[asterisk-bugs] [Asterisk 0015093]: [patch] astcanary: race when asterisk daemonizes

Asterisk Bug Tracker noreply at bugs.digium.com
Wed May 13 12:25:43 CDT 2009


A NOTE has been added to this issue. 
====================================================================== 
https://issues.asterisk.org/view.php?id=15093 
====================================================================== 
Reported By:                tzafrir
Assigned To:                tilghman
====================================================================== 
Project:                    Asterisk
Issue ID:                   15093
Category:                   General
Reproducibility:            random
Severity:                   minor
Priority:                   normal
Status:                     assigned
Asterisk Version:           1.6.1.0 
Regression:                 No 
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Request Review:              
====================================================================== 
Date Submitted:             2009-05-13 04:33 CDT
Last Modified:              2009-05-13 12:25 CDT
====================================================================== 
Summary:                    [patch] astcanary: race when asterisk daemonizes
Description: 
I normally start asterisk daemonized (without -c and such).

Sometimes (I still can't reproduce it) I immediately get the EX-CANARY
message printed to the console. E.g.:

Starting Asterisk PBX: The canary is no more.  He has ceased to be!  He's
expired and gone to meet his maker!  He's a stiff!  Bereft of life, he
rests in peace.  His metabolic processes are now history!  He's off the
twig!  He's kicked the bucket.  He's shuffled off his mortal coil, run down
the curtain, and joined the bleeding choir invisible!!  THIS is an
EX-CANARY.  (Reducing priority)

Note that this must have been printed before Asterisk has been detached
from the console. The message itself is ast_log(LOG_WARNING).

What we basically have is:

canary_thread() {
  sleep(120)
  while(1) {
    if (no signs of life from canary)
      give the EX-CANARY message and quit;
  }
}

main:

  fork() {
    /* child */
    exec(astcanary)
  } {
    /* parent */
    ast_pthread_create_detached(canary_thread);
  }
  
  if (user asked to daemonize)
    daemon()
}


When running daemon(), we also fork. This does not interact well with
sleep(2) as the attached test program demonstrates.
====================================================================== 

---------------------------------------------------------------------- 
 (0104693) tzafrir (manager) - 2009-05-13 12:25
 https://issues.asterisk.org/view.php?id=15093#c104693 
---------------------------------------------------------------------- 
Replaced with a slightly clearer one:

tzafrir at sweetmorn:~$ gcc -Wall -o /tmp/fork_sleep_test -lpthread
/tmp/fork_sleep_test.c

tzafrir at sweetmorn:~$ /tmp/fork_sleep_test
Starting, child keeps running...
Main thread starting...
Sleep thread sleeping...
In child from fork
Press Enter to continue
In parent from fork
/home/tzafrir

(exited right away. I didn't have time to press Enter. This is how
Asterisk behaves)

tzafrir at sweetmorn:~$ /tmp/fork_sleep_test yes
Starting, parent keeps running...
Sleep thread sleeping...
Main thread starting...
In child from fork
/home/tzafrir
In parent from fork
Press Enter to continue
Sleep thread done sleeping.

(I waited for 20 seconds, for the sleep to expire, and only the pressed
Enter) 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2009-05-13 12:25 tzafrir        Note Added: 0104693                          
======================================================================




More information about the asterisk-bugs mailing list