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 /libbb | |
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 'libbb')
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 98512bb00..f84e678b5 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) | |||
209 | /* Maybe we are already re-execed and come here again? */ | 209 | /* Maybe we are already re-execed and come here again? */ |
210 | if (re_execed) | 210 | if (re_execed) |
211 | return 0; | 211 | return 0; |
212 | |||
213 | /* fflush_all(); ? - so far all callers had no buffered output to flush */ | ||
214 | |||
212 | pid = xvfork(); | 215 | pid = xvfork(); |
213 | if (pid) /* parent */ | 216 | if (pid) /* parent */ |
214 | return pid; | 217 | return pid; |
@@ -245,8 +248,11 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv) | |||
245 | fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ | 248 | fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ |
246 | 249 | ||
247 | if (!(flags & DAEMON_ONLY_SANITIZE)) { | 250 | if (!(flags & DAEMON_ONLY_SANITIZE)) { |
251 | |||
252 | /* fflush_all(); - add it in fork_or_rexec() if necessary */ | ||
253 | |||
248 | if (fork_or_rexec(argv)) | 254 | if (fork_or_rexec(argv)) |
249 | exit(EXIT_SUCCESS); /* parent */ | 255 | _exit(EXIT_SUCCESS); /* parent */ |
250 | /* if daemonizing, detach from stdio & ctty */ | 256 | /* if daemonizing, detach from stdio & ctty */ |
251 | setsid(); | 257 | setsid(); |
252 | dup2(fd, 0); | 258 | dup2(fd, 0); |
@@ -258,7 +264,7 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv) | |||
258 | * Prevent this: stop being a session leader. | 264 | * Prevent this: stop being a session leader. |
259 | */ | 265 | */ |
260 | if (fork_or_rexec(argv)) | 266 | if (fork_or_rexec(argv)) |
261 | exit(EXIT_SUCCESS); /* parent */ | 267 | _exit(EXIT_SUCCESS); /* parent */ |
262 | } | 268 | } |
263 | } | 269 | } |
264 | while (fd > 2) { | 270 | while (fd > 2) { |