$NetBSD: patch-fcgiwrap.c,v 1.1 2018/11/28 16:06:36 jperkin Exp $ 1. Appease -Werror=implicit-fallthrough. 2/3/4/5. New `-l ' option sets maximum number of CGI script invocations per preforked fcgiwrap process. Maximum total number of CGI script invocations at any time is -c argument times -l argument. --- fcgiwrap.c.orig 2013-02-03 13:25:17.000000000 +0000 +++ fcgiwrap.c @@ -499,7 +499,7 @@ static void cgi_error(const char *messag _exit(99); } -static void handle_fcgi_request(void) +static int handle_fcgi_request(void) { int pipe_in[2]; int pipe_out[2]; @@ -553,7 +553,7 @@ static void handle_fcgi_request(void) execl(filename, filename, (void *)NULL); cgi_error("502 Bad Gateway", "Cannot execute script", filename); - + break; default: /* parent */ close(pipe_in[0]); close(pipe_out[1]); @@ -567,7 +567,7 @@ static void handle_fcgi_request(void) fcgi_pass(&fc); } - return; + return 0; err_fork: close(pipe_err[0]); @@ -585,17 +585,24 @@ err_pipein: FCGI_puts("Status: 502 Bad Gateway\nContent-type: text/plain\n"); FCGI_puts("System error"); + return -1; } -static void fcgiwrap_main(void) +static void fcgiwrap_main(unsigned nscriptmax) { - signal(SIGCHLD, SIG_IGN); + unsigned nscripts = 0; + + signal(SIGCHLD, SIG_DFL); signal(SIGPIPE, SIG_IGN); inherited_environ = environ; while (FCGI_Accept() >= 0) { - handle_fcgi_request(); + if (handle_fcgi_request() == 0) + nscripts++; + while (waitpid(-1, NULL, + nscripts < nscriptmax ? WNOHANG : 0) != 0) + nscripts--; } } @@ -757,6 +764,7 @@ invalid_url: int main(int argc, char **argv) { int nchildren = 1; + unsigned nscriptmax = INT_MAX; char *socket_url = NULL; int c; @@ -781,6 +789,9 @@ int main(int argc, char **argv) case 'c': nchildren = atoi(optarg); break; + case 'l': + nscriptmax = atoi(optarg); + break; case 's': socket_url = strdup(optarg); break; @@ -815,6 +826,6 @@ int main(int argc, char **argv) } prefork(nchildren); - fcgiwrap_main(); + fcgiwrap_main(nscriptmax); return 0; }