[PATCH] bb_daemonize: double-fork to ensure child doesn't get controlling tty
Peter Korsgaard
jacmet at sunsite.dk
Mon Nov 7 21:54:22 UTC 2011
bb_daemonize should double-fork so it isn't a session leader, and hence
doesn't get a controlling tty on Linux if a tty is ever opened, similar to
how libdaemon's daemon_fork or the big start-stop-daemon does it.
For details, see http://www.win.tue.nl/~aeb/linux/lk/lk-10.html#ss10.3
Signed-off-by: Peter Korsgaard <jacmet at sunsite.dk>
---
libbb/vfork_daemon_rexec.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index a75eafb..40a82e3 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -258,6 +258,8 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv)
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
+ if (fork_or_rexec(argv))
+ exit(EXIT_SUCCESS); /* parent */
}
while (fd > 2) {
close(fd--);
--
1.7.6.3
More information about the busybox
mailing list