Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Oct 2004 10:07:18 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Marc Balmer <marc@msys.ch>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: syslog() reentrant when compiling with -pthread?
Message-ID:  <20041006150718.GC87201@dan.emsphone.com>
In-Reply-To: <20041006144800.GB87201@dan.emsphone.com>
References:  <FFEC3743-17A3-11D9-BB63-0003938168B2@msys.ch> <20041006144800.GB87201@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Oct 06), Dan Nelson said:
> > My question regarding thread-safeness of syslog():  On OpenBSD I
> > used syslog_r() to do thread safe logging (the software in question
> > is a sendmail milter, which runs multithreaded).  FreeBSD does not
> > have these functions, but the cc man page states that compiling
> > with "-pthread" links in the thread safe libc_r library instead of
> > libc.  As syslog() seems to part of libc on FreeBSD, is it safe to
> > assume that syslog() is indeed thread safe on FreeBSD when
> > compiling with the -pthread switch?
> 
> 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.

I just noticed your email address :)   smtp-vilter 1.1.5 works just
fine on FreeBSD with plain syslog with this port Makefile addition:

# Use regular syslog instead of openbsd's syslog_r interface.
post-patch:
	@${FIND} ${WRKSRC} -name '*.[ch]' | ${XARGS} ${REINPLACE_CMD} \
		-e 's/syslog_r(\(.*\), &sdata,/syslog(\1,/' \
		-e '/SYSLOG_DATA_INIT/d' \
		-e 's/openlog_r(\(.*\),\(.*\),\(.*\),.*)/openlog(\1,\2,\3)/' \
		-e 's/closelog_r(.*)/closelog()/'

FreeBSD should probably make syslog completely thread-safe, though.
Just adding a mutex around the open/close operations would be enough. 
It looks like that's what Solaris does.  The only place you really need
syslog_r afaik is if you want to open multiple log handles at different
facilities or levels at the same time.

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041006150718.GC87201>