fork and wait

Joe Maimon jmaimon at ttec.com
Fri Jan 19 11:44:06 CET 2007



Alan DeKok wrote:
> Joe Maimon wrote:
> 
>>That makes more sense.
> 
> 
>   Please try the attached patch.

Lots of zombies in a short time

If rad_fork() is not called frequently does reap_children() [or the 
waitpid() inside reap_children()] run in a predictable fashion?

> 
>   It turns out that the only calls to rad_fork() are in src/main, and
> everything else calls radius_exec_program().
> 
>   Alan DeKok.
> --
>   http://deployingradius.com       - The web site of the book
>   http://deployingradius.com/blog/ - The blog
> 
> 
> ------------------------------------------------------------------------
> 
> Index: src/include/radiusd.h
> ===================================================================
> RCS file: /source/radiusd/src/include/radiusd.h,v
> retrieving revision 1.156.2.4
> diff -u -r1.156.2.4 radiusd.h
> --- src/include/radiusd.h	11 Apr 2005 23:45:21 -0000	1.156.2.4
> +++ src/include/radiusd.h	18 Jan 2007 15:05:15 -0000
> @@ -405,7 +405,7 @@
>  extern		int thread_pool_init(void);
>  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);
>  
> Index: src/main/threads.c
> ===================================================================
> RCS file: /source/radiusd/src/main/threads.c,v
> retrieving revision 1.77.2.7
> diff -u -r1.77.2.7 threads.c
> --- src/main/threads.c	17 Oct 2005 18:38:07 -0000	1.77.2.7
> +++ src/main/threads.c	18 Jan 2007 15:05:15 -0000
> @@ -982,12 +982,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();
> -
>  	/*
>  	 *	Ensure that children are reaped always.
>  	 */
> Index: src/main/exec.c
> ===================================================================
> RCS file: /source/radiusd/src/main/exec.c,v
> retrieving revision 1.42.2.1.2.2
> diff -u -r1.42.2.1.2.2 exec.c
> --- src/main/exec.c	6 Oct 2006 23:39:21 -0000	1.42.2.1.2.2
> +++ src/main/exec.c	18 Jan 2007 15:05:16 -0000
> @@ -311,7 +311,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];
> Index: src/main/session.c
> ===================================================================
> RCS file: /source/radiusd/src/main/session.c,v
> retrieving revision 1.21.2.1.2.1
> diff -u -r1.21.2.1.2.1 session.c
> --- src/main/session.c	24 Mar 2006 17:54:57 -0000	1.21.2.1.2.1
> +++ src/main/session.c	18 Jan 2007 15:05:16 -0000
> @@ -155,7 +155,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 -1;
>  	}
> 
> 
> ------------------------------------------------------------------------
> 
> - 
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html



More information about the Freeradius-Devel mailing list