syslog() reentrant when compiling with -pthread?

Marc Balmer marc at msys.ch
Wed Oct 6 22:20:56 PDT 2004


Am 06.10.2004 um 16:48 schrieb Dan Nelson:

> The only unsafe part is openlog(), so set that up before you start any
> threads and you'll be okay.  Once the log fd is opened, the syslog()
> call looks to be thread-safe.  Everything in there is done with local
> variables and atomic writes.

At least on OpenBSD I can use "%m" in the syslog() format string.  This 
results in a call to strerror(), which is not thread safe, AFAIK.  This 
probably is true for FreeBSD as well, so we have the following three 
conditions for thread safe syslog():

1) openlog() must be called before any threads that use syslog() are 
started.
2) The first argument to openlog() must not be NULL.
3) The "%m" Format String must not be used in syslog() calls.

Any comments?

- Marc



More information about the freebsd-hackers mailing list