[asterisk-dev] Forking after threading
    Simon Perreault 
    simon.perreault at viagenie.ca
       
    Thu Sep 20 10:46:23 CDT 2007
    
    
  
Hi,
Currently Asterisk's main() does something like this:
ast_event_init(...);	/* create event thread */
daemon(0,0);		/* fork */
pthread_init(...);	/* create other misc. threads */
This causes Asterisk to not work on FreeBSD. It's a well known bug [1]. 
However, it doesn't seem that it will be resolved soon since the behavior of 
that style of coding (i.e. forking after threading) is undefined in POSIX.
So I made this tiny change to Asterisk, which I humbly submit to this list for 
conideration. There are many implications to this change and it will need 
much scrutiny.
What do you think of it?
Thanks,
Simon
[1] http://www.freebsd.org/cgi/query-pr.cgi?pr=threads/101323
--- main/asterisk.c (revision 83228)
+++ main/asterisk.c (working copy)
@@ -2541,7 +2541,6 @@
    ast_alaw_init();
    callerid_init();
    ast_builtins_init();
-   ast_event_init();
    ast_utils_init();
    tdd_init();
    /* When Asterisk restarts after it has dropped the root privileges,
@@ -2841,6 +2840,9 @@
    if (test_for_thread_safety())
        ast_verbose("Warning! Asterisk is not thread safe.\n");
+   /* Start event thread after forking. */
+   ast_event_init();
+
    ast_makesocket();
    sigemptyset(&sigs);
    sigaddset(&sigs, SIGHUP);
    
    
More information about the asterisk-dev
mailing list