From 4763ffdf0407e1c697da77a10599a2aecf7dcb04 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Tue, 28 Nov 2017 23:22:14 +0100 Subject: [PATCH] BUG/MINOR: mworker: fix validity check for the pipe FDs 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 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index a1fe550e1..c7f21e3df 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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); } }