Blob Blame History Raw
From 70f1b2ddc6b94d3fa5539eb8503887b465f7fcc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Sat, 27 Sep 2014 20:00:00 -0400
Subject: [PATCH] journal-remote: fix handling of non-blocking sources

In the conversion to sd-event loop, handling of normal files got
broken. We do not want to perform non-blocking reads on them, but
simply do read() in a loop. Install a statically-enabled "source"
to do that.
---
 src/journal-remote/journal-remote.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index ad87783510..c97cfe613e 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -295,6 +295,8 @@ static int dispatch_raw_source_event(sd_event_source *event,
                                      int fd,
                                      uint32_t revents,
                                      void *userdata);
+static int dispatch_blocking_source_event(sd_event_source *event,
+                                          void *userdata);
 static int dispatch_raw_connection_event(sd_event_source *event,
                                          int fd,
                                          uint32_t revents,
@@ -378,6 +380,13 @@ static int add_source(RemoteServer *s, int fd, char* name, bool own_name) {
         r = sd_event_add_io(s->events, &source->event,
                             fd, EPOLLIN|EPOLLRDHUP|EPOLLPRI,
                             dispatch_raw_source_event, s);
+        if (r == -EPERM) {
+                log_debug("Falling back to sd_event_add_defer for fd:%d (%s)", fd, name);
+                r = sd_event_add_defer(s->events, &source->event,
+                                       dispatch_blocking_source_event, source);
+                if (r == 0)
+                        sd_event_source_set_enabled(source->event, SD_EVENT_ON);
+        }
         if (r < 0) {
                 log_error("Failed to register event source for fd:%d: %s",
                           fd, strerror(-r));
@@ -1029,6 +1038,13 @@ static int dispatch_raw_source_event(sd_event_source *event,
                 return 1;
 }
 
+static int dispatch_blocking_source_event(sd_event_source *event,
+                                          void *userdata) {
+        RemoteSource *source = userdata;
+
+        return dispatch_raw_source_event(event, source->fd, EPOLLIN, server);
+}
+
 static int accept_connection(const char* type, int fd,
                              SocketAddress *addr, char **hostname) {
         int fd2, r;