]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mworker: don't close stdio several time
authorPiBa-NL <pba_2k3@yahoo.com>
Mon, 25 Dec 2017 20:03:31 +0000 (21:03 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 29 Dec 2017 15:31:10 +0000 (16:31 +0100)
This patch makes sure that a frontend socket that gets created after
initialization won't be closed when the master gets re-executed.

When used in daemon mode, the master-worker is closing the FDs 0, 1, 2
after the fork of the children.

When the master was reloading, those FDs were assigned again during the
parsing of the configuration (probably for some listeners), and the
workers were closing them thinking it was the stdio.

This patch must be backported to 1.8.

src/haproxy.c

index ffd7ea05eb3bdc028028c7384eb0c23cf8c489a3..494ebed0169362b26d3d9347b981bbc438e958ae 100644 (file)
@@ -2580,9 +2580,18 @@ int main(int argc, char **argv)
 
        /* MODE_QUIET can inhibit alerts and warnings below this line */
 
-       if ((global.mode & MODE_QUIET) && !(global.mode & MODE_VERBOSE)) {
-               /* detach from the tty */
-               fclose(stdin); fclose(stdout); fclose(stderr);
+       if (getenv("HAPROXY_MWORKER_REEXEC") != NULL) {
+               /* either stdin/out/err are already closed or should stay as they are. */
+               if ((global.mode & MODE_DAEMON)) {
+                       /* daemon mode re-executing, stdin/stdout/stderr are already closed so keep quiet */
+                       global.mode &= ~MODE_VERBOSE;
+                       global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
+               }
+       } else {
+               if ((global.mode & MODE_QUIET) && !(global.mode & MODE_VERBOSE)) {
+                       /* detach from the tty */
+                       fclose(stdin); fclose(stdout); fclose(stderr);
+               }
        }
 
        /* open log & pid files before the chroot */