From 55ced93fd4fef1e275929a15de58e385d57a49a2 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 21 Aug 2023 17:14:45 +0200 Subject: [PATCH] Fix #67: make exception for old Linux /proc/kmsg pseudo-fifo Signed-off-by: Joachim Wiberg --- src/syslogd.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/syslogd.c b/src/syslogd.c index 0d8a3d7..c02d064 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -703,12 +703,14 @@ static int opensys(const char *file) /* * In some (container) use-cases /dev/kmsg might not be a proper - * FIFO, which may lead to CPU overload and possible loss of - * function. This check, along with the in_container() function - * is an attempt to remedy such scenarios. It's merely a sanity - * check, so ignore any TOCTOU warnings this might cause. + * device node, which may lead to CPU overload and possible loss + * of function. This check, and the in_container() function is + * an attempt to remedy such scenarios. The newer /dev/kmsg is + * a (should be a) character device and the older /proc/kmsg a + * pseudo-fifo device. However, /proc on Linux does not give us + * any information other than a read-only (root only) file. */ - if (stat(file, &st) || !S_ISCHR(st.st_mode)) + if (stat(file, &st) || (!S_ISCHR(st.st_mode) && strcmp(file, "/proc/kmsg"))) return 1; fd = open(file, O_RDONLY | O_NONBLOCK | O_CLOEXEC, 0);