12

Folks, I can't find the re-entrant version of syslog() for Linux...is there one? And if no, what do you? The obvious answer is to move logging facility into separate thread and serialise access to syslog...

pachanga
  • 3,003
  • 4
  • 30
  • 45
  • Is guarding syslog call with a semaphore/mutex any less obvious? People will be able to better help you if you can elaborate on what you want to do, and why the solution you yourself propose is unacceptable. – Michiel Buddingh Jul 22 '09 at 05:39

1 Answers1

19

According to the POSIX specification, the syslog function is already thread-safe, and so implemented in Linux. So syslog_r is unnecessary - use syslog if you need a reentrant logger function.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • 5
    The BSDs define a syslog_r call, however, for an entirely different reason; individual threads may want to log with different syslog options, which is not otherwise possible. – Michiel Buddingh Jul 22 '09 at 05:45
  • Right - that function is not available on Linux. – Martin v. Löwis Jul 22 '09 at 05:56
  • [this page](http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.basetechref%2Fdoc%2Fbasetrf2%2Fsyslog.htm) says it is not thread safe – BЈовић Sep 04 '13 at 08:35
  • Is this still the case with `syslog`? I can find no mention of thread safety or reentrant behaviour in the POSIX specification. – Michael Foukarakis Jun 19 '14 at 12:24
  • Glibc docs now note the "safety" properties, and say syslog is thread-safe: http://www.gnu.org/software/libc/manual/html_node/syslog_003b-vsyslog.html#syslog_003b-vsyslog – P.T. Apr 01 '15 at 06:56