diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
commit | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch) | |
tree | 2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /misc/syslog.c | |
parent | 7d58530341304d403a6626d7f7a1913165fe2f32 (diff) | |
download | glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.bz2 glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip |
2.5-18.1
Diffstat (limited to 'misc/syslog.c')
-rw-r--r-- | misc/syslog.c | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/misc/syslog.c b/misc/syslog.c index 6916356da7..5781b4a964 100644 --- a/misc/syslog.c +++ b/misc/syslog.c @@ -35,6 +35,7 @@ static char sccsid[] = "@(#)syslog.c 8.4 (Berkeley) 3/18/94"; #include <sys/socket.h> #include <sys/syslog.h> #include <sys/uio.h> +#include <sys/un.h> #include <netdb.h> #include <errno.h> @@ -57,6 +58,8 @@ static char sccsid[] = "@(#)syslog.c 8.4 (Berkeley) 3/18/94"; #endif #include <libio/iolibio.h> +#include <math_ldbl_opt.h> + #define ftell(s) INTUSE(_IO_ftell) (s) static int LogType = SOCK_DGRAM; /* type of socket connection */ @@ -73,8 +76,13 @@ __libc_lock_define_initialized (static, syslog_lock) static void openlog_internal(const char *, int, int) internal_function; static void closelog_internal(void); +#ifndef NO_SIGPIPE static void sigpipe_handler (int); +#endif +#ifndef send_flags +# define send_flags 0 +#endif struct cleanup_arg { @@ -85,11 +93,13 @@ struct cleanup_arg static void cancel_handler (void *ptr) { +#ifndef NO_SIGPIPE /* Restore the old signal handler. */ struct cleanup_arg *clarg = (struct cleanup_arg *) ptr; if (clarg != NULL && clarg->oldaction != NULL) __sigaction (SIGPIPE, clarg->oldaction, NULL); +#endif /* Free the lock. */ __libc_lock_unlock (syslog_lock); @@ -101,32 +111,29 @@ cancel_handler (void *ptr) * print message on log file; output is intended for syslogd(8). */ void -#if __STDC__ -syslog(int pri, const char *fmt, ...) -#else -syslog(pri, fmt, va_alist) - int pri; - char *fmt; - va_dcl -#endif +__syslog(int pri, const char *fmt, ...) { va_list ap; -#if __STDC__ va_start(ap, fmt); -#else - va_start(ap); -#endif - vsyslog(pri, fmt, ap); + __vsyslog_chk(pri, -1, fmt, ap); va_end(ap); } -libc_hidden_def (syslog) +ldbl_hidden_def (__syslog, syslog) +ldbl_strong_alias (__syslog, syslog) void -vsyslog(pri, fmt, ap) - int pri; - register const char *fmt; +__syslog_chk(int pri, int flag, const char *fmt, ...) +{ va_list ap; + + va_start(ap, fmt); + __vsyslog_chk(pri, flag, fmt, ap); + va_end(ap); +} + +void +__vsyslog_chk(int pri, int flag, const char *fmt, va_list ap) { struct tm now_tm; time_t now; @@ -135,8 +142,10 @@ vsyslog(pri, fmt, ap) char *buf = 0; size_t bufsize = 0; size_t prioff, msgoff; +#ifndef NO_SIGPIPE struct sigaction action, oldaction; int sigpipe; +#endif int saved_errno = errno; char failbuf[3 * sizeof (pid_t) + sizeof "out of memory []"]; @@ -190,7 +199,7 @@ vsyslog(pri, fmt, ap) - f->_IO_write_ptr, "%h %e %T ", __localtime_r (&now, &now_tm), - &_nl_C_locobj); + _nl_C_locobj_ptr); msgoff = ftell (f); if (LogTag == NULL) LogTag = __progname; @@ -209,7 +218,10 @@ vsyslog(pri, fmt, ap) /* We have the header. Print the user's format into the buffer. */ - vfprintf (f, fmt, ap); + if (flag == -1) + vfprintf (f, fmt, ap); + else + __vfprintf_chk (f, flag, fmt, ap); /* Close the memory stream; this will finalize the data into a malloc'd buffer in BUF. */ @@ -247,6 +259,7 @@ vsyslog(pri, fmt, ap) __libc_cleanup_push (cancel_handler, &clarg); __libc_lock_lock (syslog_lock); +#ifndef NO_SIGPIPE /* Prepare for a broken connection. */ memset (&action, 0, sizeof (action)); action.sa_handler = sigpipe_handler; @@ -254,6 +267,7 @@ vsyslog(pri, fmt, ap) sigpipe = __sigaction (SIGPIPE, &action, &oldaction); if (sigpipe == 0) clarg.oldaction = &oldaction; +#endif /* Get connected, output the message to the local logger. */ if (!connected) @@ -264,7 +278,7 @@ vsyslog(pri, fmt, ap) if (LogType == SOCK_STREAM) ++bufsize; - if (!connected || __send(LogFile, buf, bufsize, 0) < 0) + if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0) { if (connected) { @@ -274,7 +288,7 @@ vsyslog(pri, fmt, ap) openlog_internal(LogTag, LogStat | LOG_NDELAY, 0); } - if (!connected || __send(LogFile, buf, bufsize, 0) < 0) + if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0) { closelog_internal (); /* attempt re-open next time */ /* @@ -292,8 +306,10 @@ vsyslog(pri, fmt, ap) } } +#ifndef NO_SIGPIPE if (sigpipe == 0) __sigaction (SIGPIPE, &oldaction, (struct sigaction *) NULL); +#endif /* End of critical section. */ __libc_cleanup_pop (0); @@ -302,9 +318,17 @@ vsyslog(pri, fmt, ap) if (buf != failbuf) free (buf); } -libc_hidden_def (vsyslog) +libc_hidden_def (__vsyslog_chk) + +void +__vsyslog(int pri, const char *fmt, va_list ap) +{ + __vsyslog_chk (pri, -1, fmt, ap); +} +ldbl_hidden_def (__vsyslog, vsyslog) +ldbl_strong_alias (__vsyslog, vsyslog) -static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */ +static struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */ static void @@ -320,9 +344,9 @@ openlog_internal(const char *ident, int logstat, int logfac) int retry = 0; while (retry < 2) { if (LogFile == -1) { - SyslogAddr.sa_family = AF_UNIX; - (void)strncpy(SyslogAddr.sa_data, _PATH_LOG, - sizeof(SyslogAddr.sa_data)); + SyslogAddr.sun_family = AF_UNIX; + (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, + sizeof(SyslogAddr.sun_path)); if (LogStat & LOG_NDELAY) { if ((LogFile = __socket(AF_UNIX, LogType, 0)) == -1) @@ -368,11 +392,13 @@ openlog (const char *ident, int logstat, int logfac) __libc_cleanup_pop (1); } +#ifndef NO_SIGPIPE static void sigpipe_handler (int signo) { closelog_internal (); } +#endif static void closelog_internal() |