[core] reap lighttpd worker pids precisely

do not start another lighttpd worker if some other child process exits
(e.g. piped logger or dynamic backend fastcgi, scgi, proxy)
personal/stbuehler/mod-csrf
Glenn Strauss 5 years ago
parent ad7d6a6b15
commit 167cdc846c
  1. 24
      src/server.c

@ -1571,10 +1571,14 @@ static int server_main (server * const srv, int argc, char **argv) {
/* start watcher and workers */
num_childs = srv->srvconf.max_worker;
if (num_childs > 0) {
pid_t pids[num_childs];
pid_t pid;
const int npids = num_childs;
int child = 0;
for (int n = 0; n < npids; ++n) pids[n] = -1;
while (!child && !srv_shutdown && !graceful_shutdown) {
if (num_childs > 0) {
switch (fork()) {
switch ((pid = fork())) {
case -1:
return -1;
case 0:
@ -1582,16 +1586,28 @@ static int server_main (server * const srv, int argc, char **argv) {
break;
default:
num_childs--;
for (int n = 0; n < npids; ++n) {
if (-1 == pids[n]) {
pids[n] = pid;
break;
}
}
break;
}
} else {
int status;
if (-1 != wait(&status)) {
if (-1 != (pid = wait(&status))) {
/**
* one of our workers went away
* check if one of our workers went away
*/
num_childs++;
for (int n = 0; n < npids; ++n) {
if (pid == pids[n]) {
pids[n] = -1;
num_childs++;
break;
}
}
} else {
switch (errno) {
case EINTR:

Loading…
Cancel
Save