aboutsummaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-14 07:53:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-14 07:53:06 +0000
commitd8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e (patch)
tree2ab2ac263ef155ec9ea142ff297f89e634297bcf /libbb/vfork_daemon_rexec.c
parent1adf681e87f5cd81841f8a3d84a8d9bdf83c7406 (diff)
downloadbusybox-w32-d8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e.tar.gz
busybox-w32-d8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e.tar.bz2
busybox-w32-d8540f71ac8d17ef461e2d52b3f63bd78b3c2c7e.zip
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 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)
202 return wait4pid(rc); 202 return wait4pid(rc);
203} 203}
204 204
205
206#if !BB_MMU 205#if !BB_MMU
207void forkexit_or_rexec(char **argv) 206void forkexit_or_rexec(char **argv)
208{ 207{
@@ -261,17 +260,18 @@ void bb_daemonize_or_rexec(int flags, char **argv)
261 260
262 if (!(flags & DAEMON_ONLY_SANITIZE)) { 261 if (!(flags & DAEMON_ONLY_SANITIZE)) {
263 forkexit_or_rexec(argv); 262 forkexit_or_rexec(argv);
264 /* if daemonizing, make sure we detach from stdio */ 263 /* if daemonizing, make sure we detach from stdio & ctty */
265 setsid(); 264 setsid();
266 dup2(fd, 0); 265 dup2(fd, 0);
267 dup2(fd, 1); 266 dup2(fd, 1);
268 dup2(fd, 2); 267 dup2(fd, 2);
269 } 268 }
270 if (fd > 2) 269 while (fd > 2) {
271 close(fd--); 270 close(fd--);
272 if (flags & DAEMON_CLOSE_EXTRA_FDS) 271 if (!(flags & DAEMON_CLOSE_EXTRA_FDS))
273 while (fd > 2) 272 return;
274 close(fd--); /* close everything after fd#2 */ 273 /* else close everything after fd#2 */
274 }
275} 275}
276 276
277void bb_sanitize_stdio(void) 277void bb_sanitize_stdio(void)