diff options
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 2d497d754..26e1776a4 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -268,12 +268,6 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv) | |||
268 | if (flags & DAEMON_CHDIR_ROOT) | 268 | if (flags & DAEMON_CHDIR_ROOT) |
269 | xchdir("/"); | 269 | xchdir("/"); |
270 | 270 | ||
271 | if (flags & DAEMON_DEVNULL_STDIO) { | ||
272 | close(0); | ||
273 | close(1); | ||
274 | close(2); | ||
275 | } | ||
276 | |||
277 | fd = open(bb_dev_null, O_RDWR); | 271 | fd = open(bb_dev_null, O_RDWR); |
278 | if (fd < 0) { | 272 | if (fd < 0) { |
279 | /* NB: we can be called as bb_sanitize_stdio() from init | 273 | /* NB: we can be called as bb_sanitize_stdio() from init |
@@ -283,8 +277,15 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv) | |||
283 | fd = xopen("/", O_RDONLY); /* don't believe this can fail */ | 277 | fd = xopen("/", O_RDONLY); /* don't believe this can fail */ |
284 | } | 278 | } |
285 | 279 | ||
286 | while ((unsigned)fd < 2) | 280 | if (flags & DAEMON_DEVNULL_STDIO) { |
287 | fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ | 281 | xdup2(fd, 0); |
282 | xdup2(fd, 1); | ||
283 | xdup2(fd, 2); | ||
284 | } else { | ||
285 | /* have 0,1,2 open at least to /dev/null */ | ||
286 | while ((unsigned)fd < 2) | ||
287 | fd = dup(fd); | ||
288 | } | ||
288 | 289 | ||
289 | if (!(flags & DAEMON_ONLY_SANITIZE)) { | 290 | if (!(flags & DAEMON_ONLY_SANITIZE)) { |
290 | 291 | ||