]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mworker: detach from tty when received READY from worker
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 9 Dec 2024 19:20:40 +0000 (20:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2024 20:32:54 +0000 (21:32 +0100)
Some master process' initialization steps are conditioned by receiving the
READY message from worker (pidfile creation, forwarding READY message to the
launching parent). So, master process can not do these initialization routines
before.

If the master process fails, while creating pid or forwarding the READY to the
parent in daemon mode, he exits with a proper alert message. In daemon mode we
no longer see such message, as process is already detached from the tty.

To fix this, as these alerts could be very useful, let's detach the master
process from the tty after his last initialization steps in _send_status.

include/haproxy/global.h
src/cli.c
src/haproxy.c

index a5730bc4b6ba207275ccec09db811d9183673c9b..ba0523cbf911d2ba7d54b7f3d689d411164a64df 100644 (file)
@@ -70,6 +70,7 @@ int split_version(const char *version, unsigned int *value);
 int compare_current_version(const char *version);
 void display_version();
 int handle_pidfile(void);
+void stdio_quiet(int fd);
 
 void mworker_accept_wrapper(int fd);
 
index 506e5e45c4d9ed2b76d9198125b3d06cea840be4..429a277dc2aa0e51b600bdad60100e1b6a84a7be 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2553,6 +2553,18 @@ static int _send_status(char **args, char *payload, struct appctx *appctx, void
        if (global.tune.options & GTUNE_USE_SYSTEMD)
                sd_notifyf(0, "READY=1\nMAINPID=%lu\nSTATUS=Ready.\n", (unsigned long)getpid());
 
+       /* master and worker have successfully started, now we can set quiet mode
+        * if MODE_DAEMON
+        */
+       if ((!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) &&
+               (global.mode & MODE_DAEMON)) {
+               /* detach from the tty, this is required to properly daemonize. */
+               if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL))
+                       stdio_quiet(-1);
+               global.mode &= ~MODE_VERBOSE;
+               global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
+       }
+
        return 1;
 }
 
index 7b03e9ed89928916ad1ac3bc9a1ce86ef81508fd..0d7f784d27543d819d821248893c579e484b1f33 100644 (file)
@@ -814,7 +814,7 @@ static void dump(struct sig_handler *sh)
  *  In the case of chrooting, you have to open /dev/null before the chroot, and
  *  pass the <fd> to this function
  */
-static void stdio_quiet(int fd)
+void stdio_quiet(int fd)
 {
        if (fd < 0)
                fd = open("/dev/null", O_RDWR, 0);
@@ -3533,15 +3533,6 @@ int main(int argc, char **argv)
 
        /* Master enters in its polling loop */
        if (master) {
-               /* set quiet mode if MODE_DAEMON */
-               if ((!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) &&
-                       (global.mode & MODE_DAEMON)) {
-                       /* detach from the tty, this is required to properly daemonize. */
-                       if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL))
-                               stdio_quiet(-1);
-                       global.mode &= ~MODE_VERBOSE;
-                       global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
-               }
                mworker_run_master();
                /* never get there in master context */
        }