From: PiBa-NL Date: Tue, 28 Nov 2017 22:26:08 +0000 (+0100) Subject: BUG/MINOR: mworker: detach from tty when in daemon mode X-Git-Tag: v1.9-dev1~633 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=baf6ea4bd5c6df7b9f91a612fb068df63b3d1eec;p=thirdparty%2Fhaproxy.git BUG/MINOR: mworker: detach from tty when in daemon mode This allows a calling script to show the first startup output and know when to stop reading from stdout so haproxy can daemonize. To be backpored to 1.8. --- diff --git a/src/haproxy.c b/src/haproxy.c index c7f21e3df6..e842673ea3 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2763,6 +2763,16 @@ int main(int argc, char **argv) if (global.mode & MODE_MWORKER) { mworker_cleanlisteners(); deinit_pollers(); + + if ((!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) && + (global.mode & MODE_DAEMON)) { + /* detach from the tty, this is required to properly daemonize. */ + fclose(stdin); fclose(stdout); fclose(stderr); + global.mode &= ~MODE_VERBOSE; + global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */ + setsid(); + } + mworker_wait(); /* should never get there */ exit(EXIT_FAILURE);