diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-04 23:04:17 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-04 23:04:17 +0200 |
| commit | b182e9ad6011909fdb76358431d23d195febaf54 (patch) | |
| tree | 650b66e06387f8b0f7fe054a53150809aede7701 /debianutils | |
| parent | 692eeb81a4c54d7d8bf0d2e370c12762b2a16ff7 (diff) | |
| download | busybox-w32-b182e9ad6011909fdb76358431d23d195febaf54.tar.gz busybox-w32-b182e9ad6011909fdb76358431d23d195febaf54.tar.bz2 busybox-w32-b182e9ad6011909fdb76358431d23d195febaf54.zip | |
libbb: use _exit, not exit, in bb_daemonize_or_rexec()
By the time we reach exit in parent, child already exited or execed.
We should not re-run libc cleanup code.
While at it, introduce bb_daemon_helper() and add a few comments.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/start_stop_daemon.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 9d60b2c7f..07c104baa 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
| @@ -516,6 +516,11 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
| 516 | /* DAEMON_DEVNULL_STDIO is superfluous - | 516 | /* DAEMON_DEVNULL_STDIO is superfluous - |
| 517 | * it's always done by bb_daemonize() */ | 517 | * it's always done by bb_daemonize() */ |
| 518 | #else | 518 | #else |
| 519 | /* Daemons usually call bb_daemonize_or_rexec(), but SSD can do | ||
| 520 | * without: SSD is not itself a daemon, it _execs_ a daemon. | ||
| 521 | * The usual NOMMU problem of "child can't run indefinitely, | ||
| 522 | * it must exec" does not bite us: we exec anyway. | ||
| 523 | */ | ||
| 519 | pid_t pid = xvfork(); | 524 | pid_t pid = xvfork(); |
| 520 | if (pid != 0) { | 525 | if (pid != 0) { |
| 521 | /* parent */ | 526 | /* parent */ |
| @@ -525,12 +530,8 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) | |||
| 525 | } | 530 | } |
| 526 | /* Child */ | 531 | /* Child */ |
| 527 | setsid(); /* detach from controlling tty */ | 532 | setsid(); /* detach from controlling tty */ |
| 528 | /* Redirect stdio to /dev/null, close extra FDs. | 533 | /* Redirect stdio to /dev/null, close extra FDs */ |
| 529 | * We do not actually daemonize because of DAEMON_ONLY_SANITIZE */ | 534 | bb_daemon_helper(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS); |
| 530 | bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO | ||
| 531 | + DAEMON_CLOSE_EXTRA_FDS | ||
| 532 | + DAEMON_ONLY_SANITIZE, | ||
| 533 | NULL /* argv, unused */ ); | ||
| 534 | #endif | 535 | #endif |
| 535 | } | 536 | } |
| 536 | if (opt & OPT_MAKEPID) { | 537 | if (opt & OPT_MAKEPID) { |
