Mixing async and sync after a fork

Bo Lorentsen bl at lue.dk
Thu Jan 10 18:07:07 CET 2013


On 01/10/2013 05:18 PM, Brandon Black wrote:
> On Thu, Jan 10, 2013 at 10:05 AM, Bo Lorentsen <bl at lue.dk 
> <mailto:bl at lue.dk>> wrote:
>
>     The thing is ... this works amazingly, until I try to startup this
>     app as a daemon (fork). And yes, when i start it as i daemon i
>     make sure to call ev::post_fork(), and my default loop starts up
>     as it is supposed to (but later or lazy really), without any
>     problems (in its own libev thread), but it seems like any socket
>     connections made after the fork between ev::post_fork() and
>     ev::default_loop().run() are invalid after calling run.
>
>
> You shouldn't even need post_fork() just to do daemonization.  Just 
> daemonize first and then initialize libev stuff afterwards.  My first 
> random guess at your problem would be that you're using some 
> daemonization library/code written by someone else, and that it closes 
> all open file descriptors during the process (a common programming 
> error in daemonization code).  I've use libev in a ton of daemonized C 
> code without issue, as I'm sure many others have, so it's unlikely to 
> be a bug in libev.
Ok, I had some old code closing the first 4096 handlers after fork (I 
have no idea as to why), after not doing this anymore, the original code 
worked without the post_fork() call.

Thanks for your valuable advise, it now seems to work as expected, SSE 
support here we come :-)

Regards

/BL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20130110/c15f6dcf/attachment.html>


More information about the libev mailing list