MINOR: init: Use devnullfd in stdio_quiet calls instead of recreating a fd everytime

Since commit "65760d MINOR: init: Make devnullfd global and create it
earlier in init" the devnullfd file descriptor pointing to /dev/null
is created regardless of the process's parameters so we can use it in
all 'stdio_quiet' calls instead or recreating an FD.
This commit is contained in:
Remi Tricot-Le Breton 2025-10-28 18:00:44 +01:00 committed by William Lallemand
parent 1ec59d3426
commit a011683622
2 changed files with 5 additions and 5 deletions

View File

@ -2659,7 +2659,7 @@ static int _send_status(char **args, char *payload, struct appctx *appctx, void
(global.mode & MODE_DAEMON)) {
/* detach from the tty, this is required to properly daemonize. */
if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL))
stdio_quiet(-1);
stdio_quiet(devnullfd);
global.mode &= ~MODE_VERBOSE;
global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
}

View File

@ -2496,7 +2496,7 @@ static void step_init_4(void)
} else {
if ((global.mode & MODE_QUIET) && !(global.mode & MODE_VERBOSE)) {
/* detach from the tty */
stdio_quiet(-1);
stdio_quiet(devnullfd);
}
}
@ -2596,7 +2596,7 @@ static void run_master_in_recovery_mode(int argc, char **argv)
(global.mode & MODE_DAEMON)) {
/* detach from the tty, this is required to properly daemonize. */
if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL))
stdio_quiet(-1);
stdio_quiet(devnullfd);
global.mode &= ~MODE_VERBOSE;
global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
}
@ -3551,9 +3551,9 @@ int main(int argc, char **argv)
stdio_quiet(devnullfd);
global.mode &= ~MODE_VERBOSE;
global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
close(devnullfd);
devnullfd = -1;
}
close(devnullfd);
devnullfd = -1;
pid = getpid(); /* update pid */
/* This call is expensive, as it creates a new poller, scans and tries