From: Arran Cudbard-Bell Date: Wed, 8 Sep 2021 17:37:15 +0000 (-0500) Subject: If we can't setup a reaper, kill the process X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cefe3d0f725fba05384c3b94e78ba7f7ddce05c;p=thirdparty%2Ffreeradius-server.git If we can't setup a reaper, kill the process zombie children are a PITA --- diff --git a/src/lib/server/exec.c b/src/lib/server/exec.c index 6a0afde2131..4af010611c8 100644 --- a/src/lib/server/exec.c +++ b/src/lib/server/exec.c @@ -320,7 +320,7 @@ int fr_exec_fork_nowait(request_t *request, fr_value_box_list_t *vb_list, fr_pai * The child never returns from calling exec_child(); */ if (pid == 0) { - int unused[2]; + int unused[2] = { -1, -1 }; exec_child(request, argv, envp, false, unused, unused, unused); } @@ -340,7 +340,18 @@ int fr_exec_fork_nowait(request_t *request, fr_value_box_list_t *vb_list, fr_pai * Ensure that we can clean up any child processes. We * don't want them left over as zombies. */ - if (fr_event_pid_reap(request->el, pid) < 0) return -1; + if (fr_event_pid_reap(request->el, pid, NULL, NULL) < 0) { + int status; + + /* + * Try and cleanup... really we have + * no idea what state things are in. + */ + kill(pid, SIGKILL); + waitpid(pid, &status, WNOHANG); + + return -1; + } return 0; } @@ -537,8 +548,17 @@ void fr_exec_cleanup(fr_exec_state_t *exec, int signal) if (exec->pid >= 0) { if (signal > 0) kill(exec->pid, signal); - if (fr_event_pid_reap(request->el, exec->pid) < 0) { + if (unlikely(fr_event_pid_reap(request->el, exec->pid, NULL, NULL) < 0)) { + int status; + RPERROR("Failed setting up async PID reaper, PID %u may now be a zombie", exec->pid); + + /* + * Try and cleanup... really we have + * no idea what state things are in. + */ + kill(exec->pid, SIGKILL); + waitpid(exec->pid, &status, WNOHANG); } exec->pid = -1; }