diff options
-rw-r--r-- | rvnit.c | 26 |
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; |