]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
If we can't setup a reaper, kill the process
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 8 Sep 2021 17:37:15 +0000 (12:37 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 8 Sep 2021 17:37:15 +0000 (12:37 -0500)
zombie children are a PITA

src/lib/server/exec.c

index 6a0afde2131932314a85e3ddb38e4d2001deb2f0..4af010611c89751ced2756da31fb1001589fe6e9 100644 (file)
@@ -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;
        }