Add early logging support to /dev/kmsg

Very early, before syslogd has started, we have traditionally been
forced to use stdout/stderr for debug, warning and error messages.

With this patch we can now rely on /dev/kmsg to preserve all logs
from early Finit problems.  When syslogd/klogd starts up they read
/dev/kmsg and copy logs to /var/log/* files.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-09-04 17:19:06 +02:00
parent 56a3f6882b
commit 2681e4c01a
+12 -1
View File
@@ -188,7 +188,18 @@ void logit(int prio, const char *fmt, ...)
va_start(ap, fmt);
if (!_slup && !fexist("/dev/log")) {
vfprintf(stderr, fmt, ap);
FILE *fp;
fp = fopen("/dev/kmsg", "w");
if (fp) {
fprintf(fp, "<%d>finit[1]: ", LOG_DAEMON | prio);
vfprintf(fp, fmt, ap);
fclose(fp);
} else {
fprintf(stderr, "Failed opening /dev/kmsg for appending ...\n");
}
if (prio <= LOG_ERR)
vfprintf(stderr, fmt, ap);
va_end(ap);
return;
}