]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: init: Do not close previously created fd in stdio_quiet
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Tue, 28 Oct 2025 17:00:42 +0000 (18:00 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Wed, 29 Oct 2025 09:54:17 +0000 (10:54 +0100)
During init we were calling 'stdio_quiet' and passing the previously
created 'devnullfd' file descriptor. But the 'stdio_quiet' was also
closed afterwards which raised an error (EBADF).
If we keep from closing FDs that were opened outside of the
'stdio_quiet' function we will let the caller manage its FD and avoid
double close calls.

This patch can be backported to all stable branches.

src/haproxy.c

index 8127f0e044b6d6bbfecc39d57eaf83d1daf22db2..1a43ae6e0fb76e38a065b43023a6f7046310cbe7 100644 (file)
@@ -893,8 +893,11 @@ static void dump(struct sig_handler *sh)
  */
 void stdio_quiet(int fd)
 {
-       if (fd < 0)
+       int close_fd = 0;
+       if (fd < 0) {
                fd = open("/dev/null", O_RDWR, 0);
+               close_fd = 1;
+       }
 
        if (fd > -1) {
                fclose(stdin);
@@ -904,7 +907,7 @@ void stdio_quiet(int fd)
                dup2(fd, 0);
                dup2(fd, 1);
                dup2(fd, 2);
-               if (fd > 2)
+               if (fd > 2 && close_fd)
                        close(fd);
                return;
        }