]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mworker: detach from tty when in daemon mode
authorPiBa-NL <pba_2k3@yahoo.com>
Tue, 28 Nov 2017 22:26:08 +0000 (23:26 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 2 Dec 2017 13:13:40 +0000 (14:13 +0100)
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.

src/haproxy.c

index c7f21e3df6c22d59c4f2f9455e68ff6888dba118..e842673ea352be4086e9c03291cd160ea95ce2ca 100644 (file)
@@ -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);