]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: init: Use devnullfd in stdio_quiet calls instead of recreating a fd everytime
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Tue, 28 Oct 2025 17:00:44 +0000 (18:00 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Wed, 29 Oct 2025 09:54:17 +0000 (10:54 +0100)
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
src/haproxy.c

index dea6c36f16023285e91029a7c25a3bedeee17fb5..5a19be559b7cd60c99c8958f3741cc7504d42277 100644 (file)
--- 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 */
        }
index 28e9c1dea43a3ec1a0140bc0ea9cb79f59dbae6f..09fe465e61bc471a4abe02f51a4fc63484c087da 100644 (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