Document reason for stat() in opensys()

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2022-03-14 06:59:51 +01:00
parent 889dd1aed9
commit 6798fe76d5

View File

@ -668,6 +668,13 @@ static int opensys(const char *file)
struct stat st;
int fd;
/*
* 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.
*/
if (stat(file, &st) || !S_ISCHR(st.st_mode))
return 1;