summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-01-30 00:07:15 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-01-30 00:07:15 +0100
commitba70db3738ecb70e595992c2c977f70b9bdc9ebc (patch)
tree417dfc84c0c99ccae96fa91b3c7c6e69dbc72ae3
parent6a6748c9c70bc585611f74811bd2bf71f9a14814 (diff)
downloadrvnit-ba70db3738ecb70e595992c2c977f70b9bdc9ebc.tar.gz
rvnit-ba70db3738ecb70e595992c2c977f70b9bdc9ebc.tar.xz
rvnit-ba70db3738ecb70e595992c2c977f70b9bdc9ebc.zip
default global log to /dev/kmsg kmsg
-rw-r--r--rvnit.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/rvnit.c b/rvnit.c
index 794d43c..d138ab9 100644
--- a/rvnit.c
+++ b/rvnit.c
@@ -62,6 +62,7 @@ int selflogfd[2];
 int newlogfd[2];
 int globallogfd[2];
 int nullfd;
+int kmsgfd;
 
 int pid1;
 int real_pid1;
@@ -483,9 +484,21 @@ logger_loop(void* ignored)
 					   to logger failed (potentially because
 					   the pipe is full, we don't want to
 					   stall here) */
-					dprintf(2, "%s %s[%ld]: %.*s\n",
-					    timestamp,
-					    sv, pid, (int)(eol - s), s);
+					if (kmsgfd == 2)
+						dprintf(2, "%s %s[%ld]: %.*s\n",
+						    timestamp,
+						    sv, pid, (int)(eol - s), s);
+					else { // LOG_DAEMON|LOG_INFO
+						// can't dprintf to /dev/kmsg
+						// https://sourceware.org/bugzilla/show_bug.cgi?id=17830
+						static char buf[4096 + 128];
+						int l = snprintf(buf, sizeof buf,
+						    "<30>%s[%ld]: %.*s\n",
+						    sv, pid, (int)(eol - s), s);
+						if (l > (int)sizeof buf)
+							l = sizeof buf;
+						write(kmsgfd, buf, l);
+					}
 				}
 
 				s = eol + 1;
@@ -743,6 +756,13 @@ main(int argc, char *argv[])
 		close(fd[1]);
 	}
 
+	kmsgfd = 2;
+	if (pid1) {
+		kmsgfd = open("/dev/kmsg", O_WRONLY | O_APPEND | O_CLOEXEC);
+		if (kmsgfd < 0)
+			kmsgfd = 2;
+	}
+
 	if (pthread_mutex_init(&services_lock, 0) != 0) {
 		perror("rvnit: pthread_mutex_init");
 		return 111;