This is to allow the pidfile to be more easily rewritten
if the pid a worker changes
---
src/haproxy.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/haproxy.c b/src/haproxy.c
index 35ee06e..c33c072 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1358,13 +1358,6 @@ static void create_processes(int argc, char **argv, FILE
*pidfile)
send_log(NULL, LOG_INFO, "Master started\n");
}
- rewind(pidfile);
- ftruncate(fileno(pidfile), 0);
- if (global.mode & MODE_MASTER_WORKER) {
- fprintf(pidfile, "%d\n", pid);
- fflush(pidfile);
- }
-
/* Store PIDs of worker processes in oldpid so
* they can be signaled later */
nb_oldpids = global.nbproc;
@@ -1396,8 +1389,6 @@ static void create_processes(int argc, char **argv, FILE
*pidfile)
"Worker #%d started\n", proc);
break;
}
- fprintf(pidfile, "%d\n", ret);
- fflush(pidfile);
oldpids[proc] = ret;
relative_pid++; /* each child will get a different one */
}
@@ -1432,6 +1423,16 @@ static void create_processes(int argc, char **argv, FILE
*pidfile)
global.mode |= MODE_QUIET; /* ensure that we won't say anything
from now */
}
+ if (pidfile && (is_master || !(global.mode & MODE_MASTER_WORKER))) {
+ rewind(pidfile);
+ ftruncate(fileno(pidfile), 0);
+ if (is_master)
+ fprintf(pidfile, "%d\n", pid);
+ for (proc = 0; proc < nb_oldpids; proc++)
+ fprintf(pidfile, "%d\n", oldpids[proc]);
+ fflush(pidfile);
+ }
+
fork_poller();
}
--
1.7.2.3