summaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-06-14 07:53:06 +0000
committerDenis Vlasenko2007-06-14 07:53:06 +0000
commitd8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e (patch)
tree2ab2ac263ef155ec9ea142ff297f89e634297bcf /libbb/vfork_daemon_rexec.c
parent1adf681e87f5cd81841f8a3d84a8d9bdf83c7406 (diff)
downloadbusybox-d8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e.zip
busybox-d8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e.tar.gz
init: make sure fd 0,1,2 are not closed, + related optimizations.
init_main 929 920 -9 bb_daemonize_or_rexec 145 127 -18
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r--libbb/vfork_daemon_rexec.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index cb4dee7..ea7b475 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -202,7 +202,6 @@ int spawn_and_wait(char **argv)
return wait4pid(rc);
}
-
#if !BB_MMU
void forkexit_or_rexec(char **argv)
{
@@ -261,17 +260,18 @@ void bb_daemonize_or_rexec(int flags, char **argv)
if (!(flags & DAEMON_ONLY_SANITIZE)) {
forkexit_or_rexec(argv);
- /* if daemonizing, make sure we detach from stdio */
+ /* if daemonizing, make sure we detach from stdio & ctty */
setsid();
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
}
- if (fd > 2)
+ while (fd > 2) {
close(fd--);
- if (flags & DAEMON_CLOSE_EXTRA_FDS)
- while (fd > 2)
- close(fd--); /* close everything after fd#2 */
+ if (!(flags & DAEMON_CLOSE_EXTRA_FDS))
+ return;
+ /* else close everything after fd#2 */
+ }
}
void bb_sanitize_stdio(void)