summaryrefslogtreecommitdiffstats
path: root/usr.sbin/syslogd
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2017-10-05 16:34:59 +0000
committerbluhm <bluhm@openbsd.org>2017-10-05 16:34:59 +0000
commitb51626741c49eda317b23eaa4236ec61d37a5ea7 (patch)
tree79ea47c56bca5bffec72d1c2ecfcf7ee0e3f5d12 /usr.sbin/syslogd
parentI have touched more than half the source code lines of syslogd(8). (diff)
downloadwireguard-openbsd-b51626741c49eda317b23eaa4236ec61d37a5ea7.tar.xz
wireguard-openbsd-b51626741c49eda317b23eaa4236ec61d37a5ea7.zip
When syslogd writes some startup errors to stderr or console, they
never appear in any log file. After initialization, write a summary into log files and to remote log host. So the problem shows up, when someone is looking at the persistent messages. Print the "dropped message" warning in a common function. OK sthen@ millert@
Diffstat (limited to 'usr.sbin/syslogd')
-rw-r--r--usr.sbin/syslogd/syslogd.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index dd7677feb5a..ec8640854b0 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: syslogd.c,v 1.251 2017/10/05 16:15:24 bluhm Exp $ */
+/* $OpenBSD: syslogd.c,v 1.252 2017/10/05 16:34:59 bluhm Exp $ */
/*
* Copyright (c) 2014-2017 Alexander Bluhm <bluhm@genua.de>
@@ -242,6 +242,7 @@ const char *ClientCertfile = NULL;
const char *ClientKeyfile = NULL;
const char *ServerCAfile = NULL;
int tcpbuf_dropped = 0; /* count messages dropped from TCP or TLS */
+int init_dropped = 0; /* messages dropped during initialization */
#define CTL_READING_CMD 1
#define CTL_WRITING_REPLY 2
@@ -336,6 +337,7 @@ void cvthname(struct sockaddr *, char *, size_t);
int decode(const char *, const CODE *);
void markit(void);
void fprintlog(struct filed *, int, char *);
+void dropped_warn(int *, const char *);
void init(void);
void logevent(int, const char *);
void logline(int, int, char *, char *);
@@ -1378,6 +1380,7 @@ void
tcp_writecb(struct bufferevent *bufev, void *arg)
{
struct filed *f = arg;
+ char ebuf[ERRBUFSIZE];
/*
* Successful write, connection to server is good, reset wait time.
@@ -1387,11 +1390,9 @@ tcp_writecb(struct bufferevent *bufev, void *arg)
if (f->f_un.f_forw.f_dropped > 0 &&
EVBUFFER_LENGTH(f->f_un.f_forw.f_bufev->output) < MAX_TCPBUF) {
- log_info(LOG_WARNING, "dropped %d message%s to loghost \"%s\"",
- f->f_un.f_forw.f_dropped,
- f->f_un.f_forw.f_dropped == 1 ? "" : "s",
+ snprintf(ebuf, sizeof(ebuf), "to loghost \"%s\"",
f->f_un.f_forw.f_loghost);
- f->f_un.f_forw.f_dropped = 0;
+ dropped_warn(&f->f_un.f_forw.f_dropped, ebuf);
}
}
@@ -1666,6 +1667,7 @@ vlogmsg(int pri, const char *proc, const char *fmt, va_list ap)
vsnprintf(msg + l, sizeof(msg) - l, fmt, ap);
if (!Started) {
fprintf(stderr, "%s\n", msg);
+ init_dropped++;
return;
}
logline(pri, ADDDATE, LocalHostName, msg);
@@ -1810,6 +1812,7 @@ logline(int pri, int flags, char *from, char *msg)
/* May be set to F_UNUSED, try again next time. */
f->f_type = F_CONSOLE;
}
+ init_dropped++;
return;
}
SIMPLEQ_FOREACH(f, &Files, f_next) {
@@ -2223,11 +2226,7 @@ init_signalcb(int signum, short event, void *arg)
init();
log_info(LOG_INFO, "restart");
- if (tcpbuf_dropped > 0) {
- log_info(LOG_WARNING, "dropped %d message%s to remote loghost",
- tcpbuf_dropped, tcpbuf_dropped == 1 ? "" : "s");
- tcpbuf_dropped = 0;
- }
+ dropped_warn(&tcpbuf_dropped, "to remote loghost");
log_debug("syslogd: restarted");
}
@@ -2237,6 +2236,20 @@ logevent(int severity, const char *msg)
log_debug("libevent: [%d] %s", severity, msg);
}
+void
+dropped_warn(int *count, const char *what)
+{
+ int dropped;
+
+ if (*count == 0)
+ return;
+
+ dropped = *count;
+ *count = 0;
+ log_info(LOG_WARNING, "dropped %d message%s %s",
+ dropped, dropped == 1 ? "" : "s", what);
+}
+
__dead void
die(int signo)
{
@@ -2255,12 +2268,8 @@ die(int signo)
}
}
Initialized = was_initialized;
-
- if (tcpbuf_dropped > 0) {
- log_info(LOG_WARNING, "dropped %d message%s to remote loghost",
- tcpbuf_dropped, tcpbuf_dropped == 1 ? "" : "s");
- tcpbuf_dropped = 0;
- }
+ dropped_warn(&init_dropped, "during initialization");
+ dropped_warn(&tcpbuf_dropped, "to remote loghost");
if (signo)
log_info(LOG_ERR, "exiting on signal %d", signo);
@@ -2341,6 +2350,7 @@ init(void)
SIMPLEQ_INSERT_TAIL(&Files,
cfline("*.PANIC\t*", "*", "*"), f_next);
Initialized = 1;
+ dropped_warn(&init_dropped, "during initialization");
return;
}
@@ -2441,6 +2451,7 @@ init(void)
(void)fclose(cf);
Initialized = 1;
+ dropped_warn(&init_dropped, "during initialization");
if (Debug) {
SIMPLEQ_FOREACH(f, &Files, f_next) {