Hi,
My goal is to make logging via syslog reliable. At least I want
to see when a message gets lost.
So my idea is to write a kernel log message if sendsyslog(2) cannot
deliver a message. Then you see the problem on the console and in
the dmesg buffer. If syslogd comes back later, you will also get
the error into the log files via /dev/klog.
comments? ok?
bluhm
Index: kern/subr_log.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/subr_log.c,v
retrieving revision 1.25
diff -u -p -u -p -r1.25 subr_log.c
--- kern/subr_log.c 13 Dec 2014 21:05:33 -0000 1.25
+++ kern/subr_log.c 3 Jan 2015 13:48:32 -0000
@@ -347,14 +347,21 @@ sys_sendsyslog(struct proc *p, void *v,
struct iovec *ktriov = NULL;
int iovlen;
#endif
+#ifndef SMALL_KERNEL
+ const struct timeval mininterval = { 30, 0 };
+ static struct timeval lasttime;
+ static unsigned int failed;
+#endif
struct iovec aiov;
struct uio auio;
struct file *f;
size_t len;
int error;
- if (syslogf == NULL)
- return (ENOTCONN);
+ if (syslogf == NULL) {
+ error = ENOTCONN;
+ goto out;
+ }
f = syslogf;
FREF(f);
@@ -390,5 +397,19 @@ sys_sendsyslog(struct proc *p, void *v,
}
#endif
FRELE(f, p);
- return error;
+
+ out:
+#ifndef SMALL_KERNEL
+ if (error)
+ failed++;
+ if (failed && ratecheck(&lasttime, &mininterval)) {
+ if (failed == 1)
+ log(LOG_ERR, "send message to syslog failed\n");
+ else
+ log(LOG_ERR, "send message to syslog failed %u times\n",
+ failed);
+ failed = 0;
+ }
+#endif
+ return (error);
}