From 149a81a443a30fd8b23184447cc8a571fcbe0451 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Mon, 25 Dec 2017 21:03:31 +0100 Subject: [PATCH] BUG/MEDIUM: mworker: don't close stdio several time 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 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index ffd7ea05e..494ebed01 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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 */