syslog() reentrant when compiling with -pthread?

Dan Nelson dnelson at allantgroup.com
Wed Oct 6 22:45:23 PDT 2004


In the last episode (Oct 07), Marc Balmer said:
> 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.

4) make syslog() use strerror_r()

Actually, for known errno values, strerror() is thread-safe on FreeBSD. 
It just returns a pointer into sys_errlist[].  For invalid values it
stuffs "Unknown error: ##" into a static buffer and returns a pointer
to that. I'll update the PR to make syslog call strerror_r().

http://www.freebsd.org/cgi/query-pr.cgi?pr=standards/72394

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-hackers mailing list