diff options
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index a75eafbd3..ed1f86f0c 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -253,11 +253,19 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv) | |||
253 | if (!(flags & DAEMON_ONLY_SANITIZE)) { | 253 | if (!(flags & DAEMON_ONLY_SANITIZE)) { |
254 | if (fork_or_rexec(argv)) | 254 | if (fork_or_rexec(argv)) |
255 | exit(EXIT_SUCCESS); /* parent */ | 255 | exit(EXIT_SUCCESS); /* parent */ |
256 | /* if daemonizing, make sure we detach from stdio & ctty */ | 256 | /* if daemonizing, detach from stdio & ctty */ |
257 | setsid(); | 257 | setsid(); |
258 | dup2(fd, 0); | 258 | dup2(fd, 0); |
259 | dup2(fd, 1); | 259 | dup2(fd, 1); |
260 | dup2(fd, 2); | 260 | dup2(fd, 2); |
261 | if (flags & DAEMON_DOUBLE_FORK) { | ||
262 | /* On Linux, session leader can acquire ctty | ||
263 | * unknowingly, by opening a tty. | ||
264 | * Prevent this: stop being a session leader. | ||
265 | */ | ||
266 | if (fork_or_rexec(argv)) | ||
267 | exit(EXIT_SUCCESS); /* parent */ | ||
268 | } | ||
261 | } | 269 | } |
262 | while (fd > 2) { | 270 | while (fd > 2) { |
263 | close(fd--); | 271 | close(fd--); |