]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mworker: fix validity check for the pipe FDs
authorPiBa-NL <pba_2k3@yahoo.com>
Tue, 28 Nov 2017 22:22:14 +0000 (23:22 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 2 Dec 2017 12:24:47 +0000 (13:24 +0100)
Check if master-worker pipe getenv succeeded, also allow pipe fd 0 as
valid. On FreeBSD in quiet mode the stdin/stdout/stderr are closed
which lets the mworker_pipe to use fd 0 and fd 1. Additionally exit()
upon failure to create or get the master-worker pipe.

This needs to be backported to 1.8.

src/haproxy.c

index a1fe550e1c9e6e22b11f6e05945ba99caccbc118..c7f21e3df6c22d59c4f2f9455e68ff6888dba118 100644 (file)
@@ -2680,7 +2680,8 @@ int main(int argc, char **argv)
                                /* master pipe to ensure the master is still alive  */
                                ret = pipe(mworker_pipe);
                                if (ret < 0) {
-                                       ha_warning("[%s.main()] Cannot create master pipe.\n", argv[0]);
+                                       ha_alert("[%s.main()] Cannot create master pipe.\n", argv[0]);
+                                       exit(EXIT_FAILURE);
                                } else {
                                        memprintf(&msg, "%d", mworker_pipe[0]);
                                        setenv("HAPROXY_MWORKER_PIPE_RD", msg, 1);
@@ -2689,11 +2690,15 @@ int main(int argc, char **argv)
                                        free(msg);
                                }
                        } else {
-                               mworker_pipe[0] = atol(getenv("HAPROXY_MWORKER_PIPE_RD"));
-                               mworker_pipe[1] = atol(getenv("HAPROXY_MWORKER_PIPE_WR"));
-                               if (mworker_pipe[0] <= 0 || mworker_pipe[1] <= 0) {
-                                       ha_warning("[%s.main()] Cannot get master pipe FDs.\n", argv[0]);
+                               char* rd = getenv("HAPROXY_MWORKER_PIPE_RD");
+                               char* wr = getenv("HAPROXY_MWORKER_PIPE_WR");
+                               if (!rd || !wr) {
+                                       ha_alert("[%s.main()] Cannot get master pipe FDs.\n", argv[0]);
+                                       atexit_flag = 0;// dont reexecute master process
+                                       exit(EXIT_FAILURE);
                                }
+                               mworker_pipe[0] = atoi(rd);
+                               mworker_pipe[1] = atoi(wr);
                        }
                }