summaryrefslogtreecommitdiff
path: root/src/journal/journald-kmsg.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-11 20:13:44 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-11 20:55:09 +0100
commitf9a810bedacf1da7c505c1786a2416d592665926 (patch)
treee4fdb88684e2bacb4567228aabd3448d75fb3ce0 /src/journal/journald-kmsg.c
parent419173e60a05424008fcd312f6df4b59b2ce8e62 (diff)
journald: port to sd-event and enable watchdog support
Diffstat (limited to 'src/journal/journald-kmsg.c')
-rw-r--r--src/journal/journald-kmsg.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c
index af49d8578a..bc42548cd1 100644
--- a/src/journal/journald-kmsg.c
+++ b/src/journal/journald-kmsg.c
@@ -320,7 +320,7 @@ finish:
free(pid);
}
-int server_read_dev_kmsg(Server *s) {
+static int server_read_dev_kmsg(Server *s) {
char buffer[8192+1]; /* the kernel-side limit per record is 8K currently */
ssize_t l;
@@ -335,7 +335,7 @@ int server_read_dev_kmsg(Server *s) {
* return EINVAL when we try. So handle this cleanly,
* but don' try to ever read from it again. */
if (errno == EINVAL) {
- epoll_ctl(s->epoll_fd, EPOLL_CTL_DEL, s->dev_kmsg_fd, NULL);
+ s->dev_kmsg_event_source = sd_event_source_unref(s->dev_kmsg_event_source);
return 0;
}
@@ -375,8 +375,24 @@ int server_flush_dev_kmsg(Server *s) {
return 0;
}
+static int dispatch_dev_kmsg(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
+ Server *s = userdata;
+
+ assert(es);
+ assert(fd == s->dev_kmsg_fd);
+ assert(s);
+
+ if (revents & EPOLLERR)
+ log_warning("/dev/kmsg buffer overrun, some messages lost.");
+
+ if (!(revents & EPOLLIN))
+ log_error("Got invalid event from epoll for /dev/kmsg: %"PRIx32, revents);
+
+ return server_read_dev_kmsg(s);
+}
+
int server_open_dev_kmsg(Server *s) {
- struct epoll_event ev;
+ int r;
assert(s);
@@ -386,17 +402,21 @@ int server_open_dev_kmsg(Server *s) {
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) {
+ r = sd_event_add_io(s->event, s->dev_kmsg_fd, EPOLLIN, dispatch_dev_kmsg, s, &s->dev_kmsg_event_source);
+ if (r < 0) {
/* This will fail with EPERM on older kernels where
* /dev/kmsg is not readable. */
- if (errno == EPERM)
+ if (r == -EPERM)
return 0;
- log_error("Failed to add /dev/kmsg fd to epoll object: %m");
+ log_error("Failed to add /dev/kmsg fd to event loop: %s", strerror(-r));
+ return -errno;
+ }
+
+ r = sd_event_source_set_priority(s->dev_kmsg_event_source, SD_EVENT_PRIORITY_IMPORTANT+10);
+ if (r < 0) {
+ log_error("Failed to adjust priority of kmsg event source: %s", strerror(-r));
return -errno;
}