X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fmisc%2Fsyslog.c;h=a4f36dee9582111bbf3425251a554e2c4a01bf0c;hp=0f7576407e4945f9ab86dc33691661ea2e3d757a;hb=4750cf4202c29a895639b89099a7bdbe9ae422b6;hpb=19c1830eaaab05652d87b5ee9557d0d7a40c2f06 diff --git a/src/misc/syslog.c b/src/misc/syslog.c index 0f757640..a4f36dee 100644 --- a/src/misc/syslog.c +++ b/src/misc/syslog.c @@ -7,9 +7,10 @@ #include #include #include +#include #include "libc.h" -static int lock; +static int lock[2]; static const char *log_ident; static int log_opt; static int log_facility = LOG_USER; @@ -33,10 +34,13 @@ static const struct { void closelog(void) { - LOCK(&lock); + int cs; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + LOCK(lock); close(log_fd); log_fd = -1; - UNLOCK(&lock); + UNLOCK(lock); + pthread_setcancelstate(cs, 0); } static void __openlog(const char *ident, int opt, int facility) @@ -53,12 +57,15 @@ static void __openlog(const char *ident, int opt, int facility) void openlog(const char *ident, int opt, int facility) { - LOCK(&lock); + int cs; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + LOCK(lock); __openlog(ident, opt, facility); - UNLOCK(&lock); + UNLOCK(lock); + pthread_setcancelstate(cs, 0); } -void __vsyslog(int priority, const char *message, va_list ap) +static void _vsyslog(int priority, const char *message, va_list ap) { char timebuf[16]; time_t now; @@ -67,14 +74,10 @@ void __vsyslog(int priority, const char *message, va_list ap) int pid; int l, l2; - if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return; - - LOCK(&lock); - if (log_fd < 0) { __openlog(log_ident, log_opt | LOG_NDELAY, log_facility); if (log_fd < 0) { - UNLOCK(&lock); + UNLOCK(lock); return; } } @@ -95,7 +98,18 @@ void __vsyslog(int priority, const char *message, va_list ap) sendto(log_fd, buf, l, 0, (void *)&log_addr, 11); } - UNLOCK(&lock); + UNLOCK(lock); +} + +void __vsyslog(int priority, const char *message, va_list ap) +{ + int cs; + if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + LOCK(lock); + _vsyslog(priority, message, ap); + UNLOCK(lock); + pthread_setcancelstate(cs, 0); } void syslog(int priority, const char *message, ...)