summaryrefslogtreecommitdiff
path: root/src/event-loop.c
diff options
context:
space:
mode:
authorMarek Chalupa <mchqwerty@gmail.com>2014-08-12 11:35:06 +0200
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2014-08-18 13:03:00 +0300
commitf2338c8f3beb069d3fa7e4ba0d56be1cc6e065f5 (patch)
treec4b0e653dd6c93bb141853569f4adbe491788bc4 /src/event-loop.c
parent5504c9338bf89c960a9c70f1a682b619ce83f57a (diff)
downloadwayland-f2338c8f3beb069d3fa7e4ba0d56be1cc6e065f5.tar.gz
event-loop: make signalfd non-blocking
When we add more that one source to a signal, then wayland will block in wl_event_loop_dispatch. This is due to the attampt to read from signal's fd each time the source is dispatched. wl_event_loop_add_signal(loop, SIGINT, ...); wl_event_loop_add_signal(loop, SIGINT, ...); /* raise signal .. */ /* we got two fd's ready, both for the one SIGINT */ epoll_wait(...) = 2 [ for (i == 0) ] source1->dispatch() --> read(fd1); [ for (i == 1) ] source2->dispatch() --> read(fd2); /* blocking! */ Reading from fd2 will block, because we got only one signal, and it was read from fd1. Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'src/event-loop.c')
-rw-r--r--src/event-loop.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/event-loop.c b/src/event-loop.c
index 9790cde..a149db9 100644
--- a/src/event-loop.c
+++ b/src/event-loop.c
@@ -233,7 +233,7 @@ wl_event_source_signal_dispatch(struct wl_event_source *source,
int len;
len = read(source->fd, &signal_info, sizeof signal_info);
- if (len != sizeof signal_info)
+ if (!(len == -1 && errno == EAGAIN) && len != sizeof signal_info)
/* Is there anything we can do here? Will this ever happen? */
wl_log("signalfd read error: %m\n");
@@ -263,7 +263,7 @@ wl_event_loop_add_signal(struct wl_event_loop *loop,
sigemptyset(&mask);
sigaddset(&mask, signal_number);
- source->base.fd = signalfd(-1, &mask, SFD_CLOEXEC);
+ source->base.fd = signalfd(-1, &mask, SFD_CLOEXEC | SFD_NONBLOCK);
sigprocmask(SIG_BLOCK, &mask, NULL);
source->func = func;