[mod_scgi] detect child exit, restart proactively
(instead of detecting upon a subsequent HTTP request)
(for backends spawned by mod_scgi)
@@ -2886,6 +2886,49 @@ TRIGGER_FUNC(mod_scgi_handle_trigger) {
host = ex->hosts[n];
+ for (proc = host->first; proc; proc = proc->next) {
+ int status;
+
+ if (proc->pid == 0) continue;
+
+ switch (waitpid(proc->pid, &status, WNOHANG)) {
+ case 0:
+ /* child still running after timeout, good */
+ break;
+ case -1:
+ if (errno != EINTR) {
+ /* no PID found ? should never happen */
+ log_error_write(srv, __FILE__, __LINE__, "sddss",
+ "pid ", proc->pid, proc->state,
+ "not found:", strerror(errno));
+ }
+ break;
+ default:
+ /* the child should not terminate at all */
+ if (WIFEXITED(status)) {
+ if (proc->state != PROC_STATE_KILLED) {
+ log_error_write(srv, __FILE__, __LINE__, "sdb",
+ "child exited:",
+ WEXITSTATUS(status), proc->socket);
+ }
+ } else if (WIFSIGNALED(status)) {
+ if (WTERMSIG(status) != SIGTERM) {
+ log_error_write(srv, __FILE__, __LINE__, "sd",
+ "child signaled:",
+ WTERMSIG(status));
+ }
+ } else {
+ log_error_write(srv, __FILE__, __LINE__, "sd",
+ "child died somehow:",
+ status);
+ }
+ proc->pid = 0;
+ if (proc->state == PROC_STATE_RUNNING) host->active_procs--;
+ proc->state = PROC_STATE_DIED;
+ host->max_id--;
+ }
+ }
+
scgi_restart_dead_procs(srv, p, host);
for (proc = host->first; proc; proc = proc->next) {
