Skip to content

Commit

Permalink
Small fix in epoll plugin: actually check that EPOLLERR is not set in…
Browse files Browse the repository at this point in the history
… recved events mask.
  • Loading branch information
FedeDP committed Dec 18, 2020
1 parent b7a7c58 commit 3595de5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Lib/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 **/
Expand Down
3 changes: 3 additions & 0 deletions Lib/poll_plugins/epoll_priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3595de5

Please sign in to comment.