fork() and syslog() locks each other. How to avoid?

Peter Volkov (pva) pva@gentoo.org
Sat Sep 23 15:25:00 GMT 2006


On Сбт, 2006-09-23 at 10:05 -0400, Daniel Jacobowitz wrote:
> On Sat, Sep 23, 2006 at 06:00:13PM +0400, Peter Volkov (pva) wrote:
> > I did not checked but seems that fork function takes mutex which syslog
> > will waits for it. If I'm right then the question is what is the right
> > way to avoid such situations but to keep program behavior?
> 
> Avoid calling syslog from a signal handler.  Take a look at POSIX, and
> you'll find a list of which C library functions are required to be safe
> when called from signal handlers - and syslog is not on it.

Thank you very much for your answer! It points me to the right
direction. Both syslog() and fork() is non-reentrant functions so if I
really want to use syslog from signal handler I have to wrap all
non-reentrant functions with futex's or may be use some global variable
to avoid simultaneous calls to this functions. Or better to follow your
suggestion and avoid syslog() in handler.

Thank you again,
Peter.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20060923/dbbe106e/attachment.sig>


More information about the Libc-alpha mailing list