diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-14 11:53:06 +0400 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-14 11:53:06 +0400 |
commit | d8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e (patch) | |
tree | 2ab2ac263ef155ec9ea142ff297f89e634297bcf /libbb | |
parent | 1adf681e87f5cd81841f8a3d84a8d9bdf83c7406 (diff) |
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')
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index cb4dee799..ea7b475eb 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) |