diff -r 538a8a22f622 -r 857e5b92828b src/server/safs/cgi.c --- a/src/server/safs/cgi.c Wed May 22 20:44:00 2024 +0200 +++ b/src/server/safs/cgi.c Thu May 23 12:31:30 2024 +0200 @@ -714,10 +714,7 @@ return REQ_PROCEED; } -int cgi_close(CGIProcess *p) { - int status = -1; - waitpid(p->pid, &status, 0); - +int cgi_close(CGIProcess *p) { if(p->in[0] != -1) { system_close(p->in[0]); } @@ -737,6 +734,20 @@ system_close(p->err[1]); } + // TODO: Because of WNOHANG, waitpid could fail and the process + // is still running. In that case, another waitpid call should + // be done later somewhere. + int status = -1; + if(waitpid(p->pid, &status, WNOHANG) == 0) { + log_ereport(LOG_DEBUG, "cgi_close: waitpid returned 0: pid: %d", (int)p->pid); + // cgi process still running + // workaround: sleep 1 sec and try again, if that fails again + sleep(1); + if(waitpid(p->pid, &status, WNOHANG) == 0) { + log_ereport(LOG_DEBUG, "cgi_close: waitpid returned 0 again: pid: %d", (int)p->pid); + } + } + return status; }