summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2017-07-17 00:07:34 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2017-07-23 19:02:31 -0400
commit167cdc846c13f03c87fe6f100c110282aa3cd17a (patch)
tree69846e20490b704beb8050f43c8919926aa9ecc0
parentad7d6a6b1555f3ada1de3088c428b75ad4be6cb3 (diff)
downloadlighttpd1.4-167cdc846c13f03c87fe6f100c110282aa3cd17a.tar.gz
lighttpd1.4-167cdc846c13f03c87fe6f100c110282aa3cd17a.zip
[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)
-rw-r--r--src/server.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/server.c b/src/server.c
index a344357c..18a71e4f 100644
--- a/src/server.c
+++ b/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: