fork() after pthread_mutex_init()

Edgar Fuß ef at math.uni-bonn.de
Fri May 3 16:04:42 CEST 2013


What's the rationale behind calling read_mainconfig() before daemonizing?
There's a comment
	/*  Read the configuration files, BEFORE doing anything else.  */
suggesting this is intentional.

However, during that, mutexes are created via pthread_mutex_init().
To my understanding, fork()ing while holding mutexes (and without intervening
via a pthread_atfork() handler) calls for undefined behaviour.

Indeed, on NetBSD, I get
	radiusd: Error detected by libpthread: Invalid mutex.
	Detected by file [...], line [...], function "pthread_mutex_lock_slow".
	See pthread(3) for information.
unless I use one of the dont_fork options.

Running
	radiusd -f &
works as a workaround.

Also, moving the configuration reading block after the daemonizing block
seems to work, but I'm afraid there was a good reason for reading the
configuration before doing the fork.


More information about the Freeradius-Devel mailing list