From 3595de50cc3011bd606dfc69f28837a49ca55bbe Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Fri, 18 Dec 2020 23:00:52 +0100 Subject: [PATCH] Small fix in epoll plugin: actually check that EPOLLERR is not set in recved events mask. --- Lib/modules.c | 12 ++++-------- Lib/poll_plugins/epoll_priv.c | 3 +++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Lib/modules.c b/Lib/modules.c index f9c746b..9a47f61 100644 --- a/Lib/modules.c +++ b/Lib/modules.c @@ -133,6 +133,7 @@ static inline module_ret_code loop_quit(ctx_t *c, const uint8_t quit_code) { } static int recv_events(ctx_t *c, int timeout) { + int real_recv = 0; int nfds = poll_wait(c->fd, c->max_events, c->pevents, timeout); for (int i = 0; i < nfds; i++) { fd_priv_t *p = poll_recv(i, c->pevents); @@ -166,25 +167,20 @@ static int recv_events(ctx_t *c, int timeout) { MODULE_DEBUG("PoisonPilling '%s'.\n", mod->name); stop(mod, true); } - } else { - /* Forward error to below handling code */ - errno = ENXIO; - nfds = -1; + real_recv++; } } - if (nfds > 0) { + if (real_recv > 0) { evaluate_new_state(c); } else if (nfds < 0) { /* Quit and return < 0 only for real errors */ if (errno != EINTR && errno != EAGAIN) { fprintf(stderr, "Ctx '%s' loop error: %s.\n", c->name, strerror(errno)); loop_quit(c, errno); - } else { - nfds = 0; } } - return nfds; + return real_recv; } /** Public API **/ diff --git a/Lib/poll_plugins/epoll_priv.c b/Lib/poll_plugins/epoll_priv.c index f26e007..c66832a 100644 --- a/Lib/poll_plugins/epoll_priv.c +++ b/Lib/poll_plugins/epoll_priv.c @@ -36,6 +36,9 @@ int poll_wait(const int fd, const int max_events, void *pevents, const int timeo fd_priv_t *poll_recv(const int idx, void *pevents) { struct epoll_event *pev = (struct epoll_event *) pevents; + if (pev[idx].events & EPOLLERR) { + return NULL; + } return (fd_priv_t *)pev[idx].data.ptr; }