Do waitpid() for ALL children, even if there are no threads waiting
authorAlan T. DeKok <aland@freeradius.org>
Thu, 11 Feb 2010 09:24:57 +0000 (10:24 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 11 Feb 2010 09:27:31 +0000 (10:27 +0100)
i.e. call radius_exec_program() 4 times for each packet, each
with "nowait".  The "reap_children" function is called ONCE per packet,
and was calling waitpid() ONCE if there were no threads waiting
for a child.

This change makes it KEEP waiting until there are no more children
to wait for.

src/main/threads.c

index 3f70c69..130fe9e 100644 (file)
@@ -255,12 +255,13 @@ static void reap_children(void)
        pthread_mutex_lock(&thread_pool.wait_mutex);
 
        do {
+       retry:
                pid = waitpid(0, &status, WNOHANG);
                if (pid <= 0) break;
 
                mytf.pid = pid;
                tf = fr_hash_table_finddata(thread_pool.waiters, &mytf);
-               if (!tf) continue;
+               if (!tf) goto retry;
 
                tf->status = status;
                tf->exited = 1;
@@ -1047,6 +1048,7 @@ pid_t rad_fork(void)
                if (!rcode) {
                        radlog(L_ERR, "Failed to store PID, creating what will be a zombie process %d",
                               (int) child_pid);
+                       free(tf);
                }
        }