daemon : not atomic, depends on scheduling options

Stern, Eli eli.stern at intel.com
Wed Nov 16 08:38:39 UTC 2011


The waitpid() method does not work.
Instead, I created a pipe. The child writes to the pipe after setsid(). The parent reads, then exits.
This synchronizes everything.

Is such a solution acceptable? 

Eli Stern

-----Original Message-----
From: uclibc-bounces at uclibc.org [mailto:uclibc-bounces at uclibc.org] On Behalf Of Stern, Eli
Sent: Tuesday, November 15, 2011 6:21 PM
To: 'uclibc at uclibc.org'
Subject: daemon : not atomic, depends on scheduling options

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.

Can someone who understands uClibc please confirm or reject?

Thanx

Eli Stern 
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

_______________________________________________
uClibc mailing list
uClibc at uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.



More information about the uClibc mailing list