start-stop-daemon: do not lose error messages with -b

function                                             old     new   delta
start_stop_daemon_main                              1186    1206     +20
bb_daemonize_or_rexec                                196     212     +16
bb_banner                                             47      46      -1
packed_usage                                       34656   34645     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 36/-12)             Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2023-11-08 14:07:20 +01:00
parent 2de67a62e8
commit 58ca629fd2
3 changed files with 41 additions and 36 deletions

View file

@ -296,9 +296,12 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv)
}
if (flags & DAEMON_DEVNULL_STDIO) {
xdup2(fd, 0);
xdup2(fd, 1);
xdup2(fd, 2);
if (flags & DAEMON_DEVNULL_STDIN)
xdup2(fd, 0);
if (flags & DAEMON_DEVNULL_OUTERR) {
xdup2(fd, 1);
xdup2(fd, 2);
}
} else {
/* have 0,1,2 open at least to /dev/null */
while ((unsigned)fd < 2)