1 --- misc/syslog.c 2003-07-17 22:14:44.000000000 +0000
2 +++ /skole/tjener/home0/jbailey/cvstree/libc/misc/syslog.c 2003-07-17 22:05:59.000000000 +0000
7 -#include <stdio_ext.h>
12 static void openlog_internal(const char *, int, int) internal_function;
13 static void closelog_internal(void);
14 static void sigpipe_handler (int);
20 - struct sigaction *oldaction;
24 -cancel_handler (void *ptr)
26 - /* Restore the old signal handler. */
27 - struct cleanup_arg *clarg = (struct cleanup_arg *) ptr;
29 - if (clarg != NULL && clarg->oldaction != NULL)
30 - __sigaction (SIGPIPE, clarg->oldaction, NULL);
32 - /* Free the lock. */
33 - __libc_lock_unlock (syslog_lock);
36 +#ifdef _LIBC_REENTRANT
37 +static void cancel_handler (void *);
44 size_t prioff, msgoff;
45 struct sigaction action, oldaction;
46 + struct sigaction *oldaction_ptr = NULL;
48 int saved_errno = errno;
49 char failbuf[3 * sizeof (pid_t) + sizeof "out of memory []"];
54 - __fsetlocking (f, FSETLOCKING_BYCALLER);
55 prioff = fprintf (f, "<%d>", pri);
60 fputs_unlocked (LogTag, f);
61 if (LogStat & LOG_PID)
62 - fprintf (f, "[%d]", (int) __getpid ());
63 + fprintf (f, "[%d]", __getpid ());
66 - putc_unlocked (':', f);
67 - putc_unlocked (' ', f);
69 + putc_unlocked (':', f), putc_unlocked (' ', f);
71 /* Restore errno for %m format. */
72 __set_errno (saved_errno);
74 v->iov_base = (char *) "\n";
78 - __libc_cleanup_push (free, buf);
80 - /* writev is a cancellation point. */
81 (void)__writev(STDERR_FILENO, iov, v - iov + 1);
83 - __libc_cleanup_pop (0);
86 +#ifdef _LIBC_REENTRANT
87 /* Prepare for multiple users. We have to take care: open and
88 write are cancellation points. */
89 - struct cleanup_arg clarg;
91 - clarg.oldaction = NULL;
92 - __libc_cleanup_push (cancel_handler, &clarg);
93 + __libc_cleanup_region_start (1, (void (*) (void *)) cancel_handler,
95 __libc_lock_lock (syslog_lock);
98 /* Prepare for a broken connection. */
99 memset (&action, 0, sizeof (action));
101 sigemptyset (&action.sa_mask);
102 sigpipe = __sigaction (SIGPIPE, &action, &oldaction);
104 - clarg.oldaction = &oldaction;
105 + oldaction_ptr = &oldaction;
107 /* Get connected, output the message to the local logger. */
111 __sigaction (SIGPIPE, &oldaction, (struct sigaction *) NULL);
113 +#ifdef _LIBC_REENTRANT
114 /* End of critical section. */
115 - __libc_cleanup_pop (0);
116 + __libc_cleanup_region_end (0);
117 __libc_lock_unlock (syslog_lock);
124 static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
129 openlog_internal(const char *ident, int logstat, int logfac)
133 int saved_errno = errno;
135 + (void)__close(LogFile);
138 if (LogType == SOCK_DGRAM
139 && saved_errno == EPROTOTYPE)
141 @@ -357,16 +329,28 @@
147 +log_cleanup (void *arg)
149 + __libc_lock_unlock (syslog_lock);
153 openlog (const char *ident, int logstat, int logfac)
155 - /* Protect against multiple users and cancellation. */
156 - __libc_cleanup_push (cancel_handler, NULL);
157 +#ifdef _LIBC_REENTRANT
158 + /* Protect against multiple users. */
159 + __libc_cleanup_region_start (1, log_cleanup, NULL);
160 __libc_lock_lock (syslog_lock);
163 openlog_internal (ident, logstat, logfac);
165 - __libc_cleanup_pop (1);
166 +#ifdef _LIBC_REENTRANT
167 + /* Free the lock. */
168 + __libc_cleanup_region_end (1);
173 @@ -389,17 +373,36 @@
177 - /* Protect against multiple users and cancellation. */
178 - __libc_cleanup_push (cancel_handler, NULL);
179 +#ifdef _LIBC_REENTRANT
180 + /* Protect against multiple users. */
181 + __libc_cleanup_region_start (1, log_cleanup, NULL);
182 __libc_lock_lock (syslog_lock);
185 closelog_internal ();
187 LogType = SOCK_DGRAM; /* this is the default */
189 +#ifdef _LIBC_REENTRANT
190 + /* Free the lock. */
191 + __libc_cleanup_region_end (1);
195 +#ifdef _LIBC_REENTRANT
197 +cancel_handler (void *ptr)
199 + /* Restore the old signal handler. */
200 + struct sigaction *oldaction = *((struct sigaction **) ptr);
202 + if (oldaction != (struct sigaction *) NULL)
203 + __sigaction (SIGPIPE, oldaction, (struct sigaction *) NULL);
206 - __libc_cleanup_pop (1);
207 + __libc_lock_unlock (syslog_lock);
211 /* setlogmask -- set the log mask level */