Anyone?
On Mon, Sep 18, 2017 at 04:36:08PM +0200, Alexander Bluhm wrote:
> Hi,
>
> 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.
>
> syslogd[91295]: dropped 3 messages during initialization
>
> While there, print the "dropped message" warning in a common function.
>
> ok?
>
> bluhm
>
> Index: usr.sbin/syslogd/syslogd.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.248
> diff -u -p -r1.248 syslogd.c
> --- usr.sbin/syslogd/syslogd.c 17 Sep 2017 23:49:14 -0000 1.248
> +++ usr.sbin/syslogd/syslogd.c 18 Sep 2017 14:30:33 -0000
> @@ -226,6 +226,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
> @@ -320,6 +321,7 @@ void cvthname(struct sockaddr *, char *,
> 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 *);
> @@ -1361,6 +1363,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.
> @@ -1370,11 +1373,9 @@ tcp_writecb(struct bufferevent *bufev, v
>
> 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);
> }
> }
>
> @@ -1649,6 +1650,7 @@ vlogmsg(int pri, const char *proc, const
> vsnprintf(msg + l, sizeof(msg) - l, fmt, ap);
> if (!Started) {
> fprintf(stderr, "%s\n", msg);
> + init_dropped++;
> return;
> }
> logline(pri, ADDDATE, LocalHostName, msg);
> @@ -1793,6 +1795,7 @@ logline(int pri, int flags, char *from,
> /* May be set to F_UNUSED, try again next time. */
> f->f_type = F_CONSOLE;
> }
> + init_dropped++;
> return;
> }
> SIMPLEQ_FOREACH(f, &Files, f_next) {
> @@ -2205,11 +2208,7 @@ init_signalcb(int signum, short event, v
> 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");
> }
>
> @@ -2219,6 +2218,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)
> {
> @@ -2237,12 +2250,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);
> @@ -2323,6 +2332,7 @@ init(void)
> SIMPLEQ_INSERT_TAIL(&Files,
> cfline("*.PANIC\t*", "*", "*"), f_next);
> Initialized = 1;
> + dropped_warn(&init_dropped, "during initialization");
> return;
> }
>
> @@ -2423,6 +2433,7 @@ init(void)
> (void)fclose(cf);
>
> Initialized = 1;
> + dropped_warn(&init_dropped, "during initialization");
>
> if (Debug) {
> SIMPLEQ_FOREACH(f, &Files, f_next) {