diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-29 14:24:07 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-29 14:24:07 +0200 |
commit | fa8878bf1fe331df752395cce90da212e25e07b7 (patch) | |
tree | e2312f8e46bfcb96ef1d1bd758216fe8afcbd98b /libbb | |
parent | 13f42045616320119bb47cf8df302cfcc76ade9a (diff) | |
download | busybox-w32-fa8878bf1fe331df752395cce90da212e25e07b7.tar.gz busybox-w32-fa8878bf1fe331df752395cce90da212e25e07b7.tar.bz2 busybox-w32-fa8878bf1fe331df752395cce90da212e25e07b7.zip |
start-stop-daemon: do try to close fds > 2
sh -c 'exec 3>&1; exec start-stop-daemon -S -b -x /bin/sleep -- 123'
now closes fd 3.
function old new delta
bb_daemonize_or_rexec 183 192 +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 9/0) Total: 9 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-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 1aac27b36..65271e84f 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -263,12 +263,6 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv) | |||
263 | if (flags & DAEMON_CHDIR_ROOT) | 263 | if (flags & DAEMON_CHDIR_ROOT) |
264 | xchdir("/"); | 264 | xchdir("/"); |
265 | 265 | ||
266 | if (flags & DAEMON_DEVNULL_STDIO) { | ||
267 | close(0); | ||
268 | close(1); | ||
269 | close(2); | ||
270 | } | ||
271 | |||
272 | fd = open(bb_dev_null, O_RDWR); | 266 | fd = open(bb_dev_null, O_RDWR); |
273 | if (fd < 0) { | 267 | if (fd < 0) { |
274 | /* NB: we can be called as bb_sanitize_stdio() from init | 268 | /* NB: we can be called as bb_sanitize_stdio() from init |
@@ -278,8 +272,15 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv) | |||
278 | fd = xopen("/", O_RDONLY); /* don't believe this can fail */ | 272 | fd = xopen("/", O_RDONLY); /* don't believe this can fail */ |
279 | } | 273 | } |
280 | 274 | ||
281 | while ((unsigned)fd < 2) | 275 | if (flags & DAEMON_DEVNULL_STDIO) { |
282 | fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ | 276 | xdup2(fd, 0); |
277 | xdup2(fd, 1); | ||
278 | xdup2(fd, 2); | ||
279 | } else { | ||
280 | /* have 0,1,2 open at least to /dev/null */ | ||
281 | while ((unsigned)fd < 2) | ||
282 | fd = dup(fd); | ||
283 | } | ||
283 | 284 | ||
284 | if (!(flags & DAEMON_ONLY_SANITIZE)) { | 285 | if (!(flags & DAEMON_ONLY_SANITIZE)) { |
285 | 286 | ||