71 lines
2.4 KiB
Diff
71 lines
2.4 KiB
Diff
|
From: Werner Fink <werner@suse.de>
|
||
|
Date: Thu, 21 Nov 2013 11:50:32 +0000
|
||
|
Subject: [PATCH] Avoid busy systemd-journald
|
||
|
|
||
|
Avoid a busy systemd-journald due polling a broken /dec/kmsg in lxc
|
||
|
environments.
|
||
|
|
||
|
---
|
||
|
journald-kmsg.c | 27 ++++++++++++++++++++++++++-
|
||
|
1 file changed, 26 insertions(+), 1 deletion(-)
|
||
|
|
||
|
Index: systemd-208/src/journal/journald-kmsg.c
|
||
|
===================================================================
|
||
|
--- systemd-208/src/journal/journald-kmsg.c
|
||
|
+++ systemd-208/src/journal/journald-kmsg.c 2013-11-21 13:30:22.930735683 +0000
|
||
|
@@ -23,7 +23,9 @@
|
||
|
#include <sys/epoll.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <sys/mman.h>
|
||
|
+#include <sys/stat.h>
|
||
|
#include <sys/socket.h>
|
||
|
+#include <sys/types.h>
|
||
|
|
||
|
#include <systemd/sd-messages.h>
|
||
|
#include <libudev.h>
|
||
|
@@ -377,20 +379,43 @@ int server_flush_dev_kmsg(Server *s) {
|
||
|
|
||
|
int server_open_dev_kmsg(Server *s) {
|
||
|
struct epoll_event ev;
|
||
|
+ struct stat st;
|
||
|
|
||
|
assert(s);
|
||
|
|
||
|
s->dev_kmsg_fd = open("/dev/kmsg", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
|
||
|
if (s->dev_kmsg_fd < 0) {
|
||
|
- log_warning("Failed to open /dev/kmsg, ignoring: %m");
|
||
|
+ /* Do not warn as it may not exists in LXC environments */
|
||
|
+ if (errno != ENOENT)
|
||
|
+ log_warning("Failed to open /dev/kmsg, ignoring: %m");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
+ if (fstat(s->dev_kmsg_fd, &st) < 0) {
|
||
|
+ log_error("Failed to stat /dev/kmsg fd, ignoring: %m");
|
||
|
+ close_nointr_nofail(s->dev_kmsg_fd);
|
||
|
+ s->dev_kmsg_fd = -1;
|
||
|
+ return 0;
|
||
|
+ }
|
||
|
+
|
||
|
+ if (!S_ISCHR(st.st_mode) || major(st.st_rdev) != 1 || minor(st.st_rdev) != 11) {
|
||
|
+ int old_errno = errno;
|
||
|
+ errno = ENODEV;
|
||
|
+ log_warning("Irregular device /dev/kmsg, ignoring: %m");
|
||
|
+ errno = old_errno;
|
||
|
+ close_nointr_nofail(s->dev_kmsg_fd);
|
||
|
+ s->dev_kmsg_fd = -1;
|
||
|
+ return 0;
|
||
|
+ }
|
||
|
+
|
||
|
zero(ev);
|
||
|
ev.events = EPOLLIN;
|
||
|
ev.data.fd = s->dev_kmsg_fd;
|
||
|
if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, s->dev_kmsg_fd, &ev) < 0) {
|
||
|
|
||
|
+ close_nointr_nofail(s->dev_kmsg_fd);
|
||
|
+ s->dev_kmsg_fd = -1;
|
||
|
+
|
||
|
/* This will fail with EPERM on older kernels where
|
||
|
* /dev/kmsg is not readable. */
|
||
|
if (errno == EPERM)
|