--- misc/syslog.c 2003-07-17 22:14:44.000000000 +0000 +++ /skole/tjener/home0/jbailey/cvstree/libc/misc/syslog.c 2003-07-17 22:05:59.000000000 +0000 @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -75,27 +74,9 @@ static void openlog_internal(const char *, int, int) internal_function; static void closelog_internal(void); static void sigpipe_handler (int); - - -struct cleanup_arg -{ - void *buf; - struct sigaction *oldaction; -}; - -static void -cancel_handler (void *ptr) -{ - /* Restore the old signal handler. */ - struct cleanup_arg *clarg = (struct cleanup_arg *) ptr; - - if (clarg != NULL && clarg->oldaction != NULL) - __sigaction (SIGPIPE, clarg->oldaction, NULL); - - /* Free the lock. */ - __libc_lock_unlock (syslog_lock); -} - +#ifdef _LIBC_REENTRANT +static void cancel_handler (void *); +#endif /* * syslog, vsyslog -- @@ -137,6 +118,7 @@ size_t bufsize = 0; size_t prioff, msgoff; struct sigaction action, oldaction; + struct sigaction *oldaction_ptr = NULL; int sigpipe; int saved_errno = errno; char failbuf[3 * sizeof (pid_t) + sizeof "out of memory []"]; @@ -183,7 +165,6 @@ } else { - __fsetlocking (f, FSETLOCKING_BYCALLER); prioff = fprintf (f, "<%d>", pri); (void) time (&now); #ifdef USE_IN_LIBIO @@ -201,12 +182,9 @@ if (LogTag != NULL) fputs_unlocked (LogTag, f); if (LogStat & LOG_PID) - fprintf (f, "[%d]", (int) __getpid ()); + fprintf (f, "[%d]", __getpid ()); if (LogTag != NULL) - { - putc_unlocked (':', f); - putc_unlocked (' ', f); - } + putc_unlocked (':', f), putc_unlocked (' ', f); /* Restore errno for %m format. */ __set_errno (saved_errno); @@ -234,22 +212,16 @@ v->iov_base = (char *) "\n"; v->iov_len = 1; } - - __libc_cleanup_push (free, buf); - - /* writev is a cancellation point. */ (void)__writev(STDERR_FILENO, iov, v - iov + 1); - - __libc_cleanup_pop (0); } +#ifdef _LIBC_REENTRANT /* Prepare for multiple users. We have to take care: open and write are cancellation points. */ - struct cleanup_arg clarg; - clarg.buf = buf; - clarg.oldaction = NULL; - __libc_cleanup_push (cancel_handler, &clarg); + __libc_cleanup_region_start (1, (void (*) (void *)) cancel_handler, + &oldaction_ptr); __libc_lock_lock (syslog_lock); +#endif /* Prepare for a broken connection. */ memset (&action, 0, sizeof (action)); @@ -257,7 +229,7 @@ sigemptyset (&action.sa_mask); sigpipe = __sigaction (SIGPIPE, &action, &oldaction); if (sigpipe == 0) - clarg.oldaction = &oldaction; + oldaction_ptr = &oldaction; /* Get connected, output the message to the local logger. */ if (!connected) @@ -299,9 +271,11 @@ if (sigpipe == 0) __sigaction (SIGPIPE, &oldaction, (struct sigaction *) NULL); +#ifdef _LIBC_REENTRANT /* End of critical section. */ - __libc_cleanup_pop (0); + __libc_cleanup_region_end (0); __libc_lock_unlock (syslog_lock); +#endif free (buf); } @@ -309,7 +283,6 @@ static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */ - static void internal_function openlog_internal(const char *ident, int logstat, int logfac) @@ -339,9 +312,8 @@ == -1) { int saved_errno = errno; - int fd = LogFile; + (void)__close(LogFile); LogFile = -1; - (void)__close(fd); if (LogType == SOCK_DGRAM && saved_errno == EPROTOTYPE) { @@ -357,16 +329,28 @@ } } + +static void +log_cleanup (void *arg) +{ + __libc_lock_unlock (syslog_lock); +} + void openlog (const char *ident, int logstat, int logfac) { - /* Protect against multiple users and cancellation. */ - __libc_cleanup_push (cancel_handler, NULL); +#ifdef _LIBC_REENTRANT + /* Protect against multiple users. */ + __libc_cleanup_region_start (1, log_cleanup, NULL); __libc_lock_lock (syslog_lock); +#endif openlog_internal (ident, logstat, logfac); - __libc_cleanup_pop (1); +#ifdef _LIBC_REENTRANT + /* Free the lock. */ + __libc_cleanup_region_end (1); +#endif } static void @@ -389,17 +373,36 @@ void closelog () { - /* Protect against multiple users and cancellation. */ - __libc_cleanup_push (cancel_handler, NULL); +#ifdef _LIBC_REENTRANT + /* Protect against multiple users. */ + __libc_cleanup_region_start (1, log_cleanup, NULL); __libc_lock_lock (syslog_lock); +#endif closelog_internal (); LogTag = NULL; LogType = SOCK_DGRAM; /* this is the default */ +#ifdef _LIBC_REENTRANT + /* Free the lock. */ + __libc_cleanup_region_end (1); +#endif +} + +#ifdef _LIBC_REENTRANT +static void +cancel_handler (void *ptr) +{ + /* Restore the old signal handler. */ + struct sigaction *oldaction = *((struct sigaction **) ptr); + + if (oldaction != (struct sigaction *) NULL) + __sigaction (SIGPIPE, oldaction, (struct sigaction *) NULL); + /* Free the lock. */ - __libc_cleanup_pop (1); + __libc_lock_unlock (syslog_lock); } +#endif /* setlogmask -- set the log mask level */ int