summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko2017-08-04 23:04:17 +0200
committerDenys Vlasenko2017-08-04 23:04:17 +0200
commitb182e9ad6011909fdb76358431d23d195febaf54 (patch)
tree650b66e06387f8b0f7fe054a53150809aede7701 /libbb
parent692eeb81a4c54d7d8bf0d2e370c12762b2a16ff7 (diff)
downloadbusybox-b182e9ad6011909fdb76358431d23d195febaf54.zip
busybox-b182e9ad6011909fdb76358431d23d195febaf54.tar.gz
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 'libbb')
-rw-r--r--libbb/vfork_daemon_rexec.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 98512bb..f84e678 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -209,6 +209,9 @@ pid_t FAST_FUNC fork_or_rexec(char **argv)
/* Maybe we are already re-execed and come here again? */
if (re_execed)
return 0;
+
+ /* fflush_all(); ? - so far all callers had no buffered output to flush */
+
pid = xvfork();
if (pid) /* parent */
return pid;
@@ -245,8 +248,11 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv)
fd = dup(fd); /* have 0,1,2 open at least to /dev/null */
if (!(flags & DAEMON_ONLY_SANITIZE)) {
+
+ /* fflush_all(); - add it in fork_or_rexec() if necessary */
+
if (fork_or_rexec(argv))
- exit(EXIT_SUCCESS); /* parent */
+ _exit(EXIT_SUCCESS); /* parent */
/* if daemonizing, detach from stdio & ctty */
setsid();
dup2(fd, 0);
@@ -258,7 +264,7 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv)
* Prevent this: stop being a session leader.
*/
if (fork_or_rexec(argv))
- exit(EXIT_SUCCESS); /* parent */
+ _exit(EXIT_SUCCESS); /* parent */
}
}
while (fd > 2) {