|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From 70f1b2ddc6b94d3fa5539eb8503887b465f7fcc7 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Sat, 27 Sep 2014 20:00:00 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] journal-remote: fix handling of non-blocking sources
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
In the conversion to sd-event loop, handling of normal files got
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
broken. We do not want to perform non-blocking reads on them, but
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
simply do read() in a loop. Install a statically-enabled "source"
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
to do that.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/journal-remote/journal-remote.c | 16 ++++++++++++++++
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
1 file changed, 16 insertions(+)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index ad87783510..c97cfe613e 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/journal-remote/journal-remote.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/journal-remote/journal-remote.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -295,6 +295,8 @@ static int dispatch_raw_source_event(sd_event_source *event,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int fd,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
uint32_t revents,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
void *userdata);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+static int dispatch_blocking_source_event(sd_event_source *event,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ void *userdata);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
static int dispatch_raw_connection_event(sd_event_source *event,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int fd,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
uint32_t revents,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -378,6 +380,13 @@ static int add_source(RemoteServer *s, int fd, char* name, bool own_name) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = sd_event_add_io(s->events, &source->event,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
fd, EPOLLIN|EPOLLRDHUP|EPOLLPRI,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
dispatch_raw_source_event, s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r == -EPERM) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_debug("Falling back to sd_event_add_defer for fd:%d (%s)", fd, name);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = sd_event_add_defer(s->events, &source->event,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ dispatch_blocking_source_event, source);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r == 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ sd_event_source_set_enabled(source->event, SD_EVENT_ON);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_error("Failed to register event source for fd:%d: %s",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
fd, strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1029,6 +1038,13 @@ static int dispatch_raw_source_event(sd_event_source *event,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+static int dispatch_blocking_source_event(sd_event_source *event,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ void *userdata) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ RemoteSource *source = userdata;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return dispatch_raw_source_event(event, source->fd, EPOLLIN, server);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
static int accept_connection(const char* type, int fd,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
SocketAddress *addr, char **hostname) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int fd2, r;
|