#! /bin/sh /usr/share/dpatch/dpatch-run ## 370-rad_fork.dpatch by ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description. @DPATCH@ diff -urNad freeradius-2.0.0~/src/include/radiusd.h freeradius-2.0.0/src/include/radiusd.h --- freeradius-2.0.0~/src/include/radiusd.h 2007-01-19 04:47:11.000000000 -0500 +++ freeradius-2.0.0/src/include/radiusd.h 2007-01-19 05:36:01.000000000 -0500 @@ -447,7 +447,7 @@ extern int thread_pool_init(int spawn_flag); extern int thread_pool_clean(time_t now); extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP); -extern pid_t rad_fork(int exec_wait); +extern pid_t rad_fork(void); extern pid_t rad_waitpid(pid_t pid, int *status, int options); extern int total_active_threads(void); diff -urNad freeradius-2.0.0~/src/main/exec.c freeradius-2.0.0/src/main/exec.c --- freeradius-2.0.0~/src/main/exec.c 2007-01-19 04:47:11.000000000 -0500 +++ freeradius-2.0.0/src/main/exec.c 2007-01-19 05:36:01.000000000 -0500 @@ -226,7 +226,13 @@ output_pairs = NULL; } - if ((pid = rad_fork(exec_wait)) == 0) { + if (exec_wait) { + pid = rad_fork(); /* remember PID */ + } else { + pid = fork(); /* don't wait */ + } + + if (pid == 0) { #define MAX_ENVP 1024 int devnull; char *envp[MAX_ENVP]; diff -urNad freeradius-2.0.0~/src/main/session.c freeradius-2.0.0/src/main/session.c --- freeradius-2.0.0~/src/main/session.c 2007-01-19 04:47:11.000000000 -0500 +++ freeradius-2.0.0/src/main/session.c 2007-01-19 05:36:01.000000000 -0500 @@ -168,7 +168,7 @@ /* * Fork. */ - if ((pid = rad_fork(1)) < 0) { /* do wait for the fork'd result */ + if ((pid = rad_fork()) < 0) { /* do wait for the fork'd result */ radlog(L_ERR, "Accounting: Failed in fork(): Cannot run checkrad\n"); return 2; } diff -urNad freeradius-2.0.0~/src/main/threads.c freeradius-2.0.0/src/main/threads.c --- freeradius-2.0.0~/src/main/threads.c 2007-01-19 04:47:11.000000000 -0500 +++ freeradius-2.0.0/src/main/threads.c 2007-01-19 05:40:50.000000000 -0500 @@ -258,11 +258,10 @@ int status; thread_fork_t mytf, *tf; - if (lrad_hash_table_num_elements(thread_pool.waiters) == 0) return; pthread_mutex_lock(&thread_pool.wait_mutex); - while (1) { + do { pid = waitpid(0, &status, WNOHANG); if (pid <= 0) break; @@ -272,7 +271,7 @@ tf->status = status; tf->exited = 1; - } + } while (lrad_hash_table_num_elements(thread_pool.waiters)); pthread_mutex_unlock(&thread_pool.wait_mutex); } @@ -1049,11 +1048,10 @@ /* * Thread wrapper for fork(). */ -pid_t rad_fork(int exec_wait) +pid_t rad_fork(void) { pid_t child_pid; - if (exec_wait) return fork(); reap_children(); /* be nice to non-wait thingies */