diff options
author | 2003-02-07 21:47:14 +0000 | |
---|---|---|
committer | 2003-02-07 21:47:14 +0000 | |
commit | a8241fb59f4a3d71a3265fe5a8eea9217598c131 (patch) | |
tree | 9e5c05c06881930799fc8f6bb566ec664ec841a7 /lib/libc/gen/syslog.c | |
parent | typos; (diff) | |
download | wireguard-openbsd-a8241fb59f4a3d71a3265fe5a8eea9217598c131.tar.xz wireguard-openbsd-a8241fb59f4a3d71a3265fe5a8eea9217598c131.zip |
Don't write log message to console unless we are unable to connect to
syslogd. Noticed by marc@; OK by marc@ and deraadt@
Diffstat (limited to 'lib/libc/gen/syslog.c')
-rw-r--r-- | lib/libc/gen/syslog.c | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 090e1f508f2..d65c34d0a4a 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: syslog.c,v 1.22 2003/01/20 20:10:26 millert Exp $"; +static char rcsid[] = "$OpenBSD: syslog.c,v 1.23 2003/02/07 21:47:14 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -55,10 +55,8 @@ static struct syslog_data sdata = SYSLOG_DATA_INIT; extern char *__progname; /* Program name, from crt0. */ -static void disconnectlog(void); /* disconnect from syslogd */ -static void connectlog(void); /* (re)connect to syslogd */ -static void disconnectlog_r(struct syslog_data *); -static void connectlog_r(struct syslog_data *); +static void disconnectlog_r(struct syslog_data *); /* disconnect from syslogd */ +static void connectlog_r(struct syslog_data *); /* (re)connect to syslogd */ /* * syslog, vsyslog -- @@ -83,18 +81,6 @@ vsyslog(pri, fmt, ap) vsyslog_r(pri, &sdata, fmt, ap); } -static void -disconnectlog() -{ - disconnectlog_r(&sdata); -} - -static void -connectlog() -{ - connectlog_r(&sdata); -} - void openlog(ident, logstat, logfac) const char *ident; @@ -139,7 +125,7 @@ vsyslog_r(pri, data, fmt, ap) int cnt; char ch, *p, *t; time_t now; - int fd, saved_errno; + int fd, saved_errno, error; #define TBUF_LEN 2048 #define FMT_LEN 1024 char *stdp, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN]; @@ -278,14 +264,14 @@ vsyslog_r(pri, data, fmt, ap) * case #1 and keep send()ing data to cover case #2 * to give syslogd a chance to empty its socket buffer. */ - if (send(data->log_file, tbuf, cnt, 0) < 0) { + if ((error = send(data->log_file, tbuf, cnt, 0)) < 0) { if (errno != ENOBUFS) { disconnectlog_r(data); connectlog_r(data); } do { usleep(1); - if (send(data->log_file, tbuf, cnt, 0) >= 0) + if ((error = send(data->log_file, tbuf, cnt, 0)) >= 0) break; } while (errno == ENOBUFS); } @@ -295,7 +281,7 @@ vsyslog_r(pri, data, fmt, ap) * as a blocking console should not stop other processes. * Make sure the error reported is the one from the syslogd failure. */ - if (data->log_stat & LOG_CONS && + if (error != 0 && (data->log_stat & LOG_CONS) && (fd = open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) { struct iovec iov[2]; |