#include <sys/socket.h>
#include <sys/syslog.h>
#include <sys/uio.h>
+#include <sys/un.h>
#include <netdb.h>
#include <errno.h>
#include <signal.h>
#include <locale.h>
-#if __STDC__
#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
#include <libio/iolibio.h>
-#define ftell(s) INTUSE(_IO_ftell) (s)
+#include <math_ldbl_opt.h>
+
+#include <kernel-features.h>
+
+#define ftell(s) _IO_ftell (s)
static int LogType = SOCK_DGRAM; /* type of socket connection */
static int LogFile = -1; /* fd for log */
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
{
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);
* 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;
FILE *f;
char *buf = 0;
size_t bufsize = 0;
- size_t prioff, msgoff;
+ size_t 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 []"];
else
{
__fsetlocking (f, FSETLOCKING_BYCALLER);
- prioff = fprintf (f, "<%d>", pri);
+ fprintf (f, "<%d>", pri);
(void) time (&now);
f->_IO_write_ptr += __strftime_l (f->_IO_write_ptr,
f->_IO_write_end
- 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;
/* 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. */
/* Output to stderr if requested. */
if (LogStat & LOG_PERROR) {
struct iovec iov[2];
- register struct iovec *v = iov;
+ struct iovec *v = iov;
v->iov_base = buf + msgoff;
v->iov_len = bufsize - msgoff;
__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;
sigpipe = __sigaction (SIGPIPE, &action, &oldaction);
if (sigpipe == 0)
clarg.oldaction = &oldaction;
+#endif
/* Get connected, output the message to the local logger. */
if (!connected)
if (LogType == SOCK_STREAM)
++bufsize;
- if (!connected || __send(LogFile, buf, bufsize, 0) < 0)
+ if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0)
{
if (connected)
{
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 */
/*
}
}
+#ifndef NO_SIGPIPE
if (sigpipe == 0)
__sigaction (SIGPIPE, &oldaction, (struct sigaction *) NULL);
+#endif
/* End of critical section. */
__libc_cleanup_pop (0);
if (buf != failbuf)
free (buf);
}
-libc_hidden_def (vsyslog)
+libc_hidden_def (__vsyslog_chk)
-static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */
+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_un SyslogAddr; /* AF_UNIX address of local logger */
static void
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)
+#ifdef SOCK_CLOEXEC
+# ifndef __ASSUME_SOCK_CLOEXEC
+ if (__have_sock_cloexec >= 0) {
+# endif
+ LogFile = __socket(AF_UNIX,
+ LogType
+ | SOCK_CLOEXEC, 0);
+# ifndef __ASSUME_SOCK_CLOEXEC
+ if (__have_sock_cloexec == 0)
+ __have_sock_cloexec
+ = ((LogFile != -1
+ || errno != EINVAL)
+ ? 1 : -1);
+ }
+# endif
+#endif
+#ifndef __ASSUME_SOCK_CLOEXEC
+# ifdef SOCK_CLOEXEC
+ if (__have_sock_cloexec < 0)
+# endif
+ LogFile = __socket(AF_UNIX, LogType, 0);
+#endif
+ if (LogFile == -1)
return;
- (void)__fcntl(LogFile, F_SETFD, 1);
+#ifndef __ASSUME_SOCK_CLOEXEC
+# ifdef SOCK_CLOEXEC
+ if (__have_sock_cloexec < 0)
+# endif
+ __fcntl(LogFile, F_SETFD, FD_CLOEXEC);
+#endif
}
}
if (LogFile != -1 && !connected)
__libc_cleanup_pop (1);
}
+#ifndef NO_SIGPIPE
static void
sigpipe_handler (int signo)
{
closelog_internal ();
}
+#endif
static void
-closelog_internal()
+closelog_internal (void)
{
if (!connected)
return;
}
void
-closelog ()
+closelog (void)
{
/* Protect against multiple users and cancellation. */
__libc_cleanup_push (cancel_handler, NULL);