From a0116836226a313e564210de4856ad663d9442f1 Mon Sep 17 00:00:00 2001 From: Remi Tricot-Le Breton Date: Tue, 28 Oct 2025 18:00:44 +0100 Subject: [PATCH] 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. --- src/cli.c | 2 +- src/haproxy.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cli.c b/src/cli.c index dea6c36f1..5a19be559 100644 --- a/src/cli.c +++ b/src/cli.c @@ -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 */ } diff --git a/src/haproxy.c b/src/haproxy.c index 28e9c1dea..09fe465e6 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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 -- 2.47.3