aboutsummaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
authorPeter Korsgaard <jacmet@sunsite.dk>2011-11-09 19:44:37 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-11-09 19:44:37 +0100
commit743edac6c84ac207d0bb4c3124b0e8fe450a38b4 (patch)
treed74290b238665a3369e191dd85e7a4b38f74aadb /libbb/vfork_daemon_rexec.c
parent7e21f0491cf3e72835cd9b515734caec56d41e70 (diff)
downloadbusybox-743edac6c84ac207d0bb4c3124b0e8fe450a38b4.tar.gz
bb_daemonize_or_rexec(): add flag to double-fork; use it in start-stop-daemon
Add a DAEMON_DOUBLE_FORK flag to make bb_daemonize 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 - And use it in start-stop-daemon. For details, see http://www.win.tue.nl/~aeb/linux/lk/lk-10.html#ss10.3 Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r--libbb/vfork_daemon_rexec.c10
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)
if (!(flags & DAEMON_ONLY_SANITIZE)) {
if (fork_or_rexec(argv))
exit(EXIT_SUCCESS); /* parent */
- /* if daemonizing, make sure we detach from stdio & ctty */
+ /* if daemonizing, detach from stdio & ctty */
setsid();
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
+ if (flags & DAEMON_DOUBLE_FORK) {
+ /* On Linux, session leader can acquire ctty
+ * unknowingly, by opening a tty.
+ * Prevent this: stop being a session leader.
+ */
+ if (fork_or_rexec(argv))
+ exit(EXIT_SUCCESS); /* parent */
+ }
}
while (fd > 2) {
close(fd--);