From d8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Thu, 14 Jun 2007 07:53:06 +0000 Subject: init: make sure fd 0,1,2 are not closed, + related optimizations. init_main 929 920 -9 bb_daemonize_or_rexec 145 127 -18 --- libbb/vfork_daemon_rexec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libbb') 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) -- cgit v1.2.3