daemon : not atomic, depends on scheduling options

Mike Frysinger vapier at gentoo.org
Thu Nov 17 16:29:00 UTC 2011


On Tuesday 15 November 2011 11:20:44 Stern, Eli wrote:
> Following is a concern that daemon() might fail due to scheduling.
> 
> The daemon() function does not synchronize itself, and so it is prone to
> failure depending on system scheduling. Example:
> - Last line in a script is a process that uses daemon(). Within daemon:
>   * parent does fork();
>   * Parent gets CPU, child did not start.
>   * Parent does _exit();
>   * The script recognizes that the last line of the script has been
> executed, and send a SIGHUP to the pgrp. * Child receives SIGHUP and
> exits.
> 
> All this can be avoided if the parent waits on waitpid till the child
> detaches (setsid()). At this point the parent receives ECHILD on the
> waitpid, and can exit safely.

doesn't your test case fail the same way on glibc ?  i can't see the glibc 
code being any different here.  and since daemon() isn't covered under POSIX, 
i'd simply say "if glibc fails in the same way, then oh well".
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20111117/789217ab/attachment.asc>


More information about the uClibc mailing list