From: Roy Marples Date: Tue, 2 Feb 2021 15:10:20 +0000 (+0000) Subject: Fix prior for epoll. X-Git-Tag: v10.0.0~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c26587f67aefd49ddbaa5565622be6b0d3b6ccf;p=thirdparty%2Fdhcpcd.git Fix prior for epoll. --- diff --git a/src/dev.c b/src/dev.c index d33c8faa..88dfc0de 100644 --- a/src/dev.c +++ b/src/dev.c @@ -167,10 +167,13 @@ dev_start1(struct dhcpcd_ctx *ctx, const struct dev_dhcpcd *dev_dhcpcd) } static void -dev_handle_data(void *arg) +dev_handle_data(void *arg, unsigned short events) { struct dhcpcd_ctx *ctx; + if (events != ELE_READ) + logerrx("%s: unexpected event 0x%04x", __func__, events); + ctx = arg; if (ctx->dev->handle_device(arg) == -1) { /* XXX: an error occured. should we restart dev? */ @@ -191,7 +194,7 @@ dev_start(struct dhcpcd_ctx *ctx, int (*handler)(void *, int, const char *)) ctx->dev_fd = dev_start1(ctx, &dev_dhcpcd); if (ctx->dev_fd != -1) { - if (eloop_event_add(ctx->eloop, ctx->dev_fd, + if (eloop_event_add(ctx->eloop, ctx->dev_fd, ELE_READ, dev_handle_data, ctx) == -1) { logerr(__func__); diff --git a/src/eloop.c b/src/eloop.c index ab8d289c..32042c54 100644 --- a/src/eloop.c +++ b/src/eloop.c @@ -377,13 +377,12 @@ eloop_event_add(struct eloop *eloop, int fd, unsigned short events, #elif defined(HAVE_EPOLL) memset(&epe, 0, sizeof(epe)); epe.data.ptr = e; - if (e->events & ELE_READ) + if (events & ELE_READ) epe.events |= EPOLLIN; - if (e->events & ELE_WRITE) + if (events & ELE_WRITE) epe.events |= EPOLLOUT; - op = added ? EPOLL_CTL_ADD : EPOLL_CTL_MOD; - if (epoll_ctl(eloop->fd, op, fd, &epe) == -1) { + if (epe.events != 0 && epoll_ctl(eloop->fd, op, fd, &epe) == -1) { if (added) { TAILQ_REMOVE(&eloop->events, e, next); TAILQ_INSERT_TAIL(&eloop->free_events, e, next); @@ -689,9 +688,9 @@ eloop_forked(struct eloop *eloop) #elif defined(HAVE_EPOLL) memset(&epe, 0, sizeof(epe)); epe.data.ptr = e; - if (e->read_cb != NULL) + if (e->events & ELE_READ) epe.events |= EPOLLIN; - if (e->write_cb != NULL) + if (e->events & ELE_WRITE) epe.events |= EPOLLOUT; if (epoll_ctl(eloop->fd, EPOLL_CTL_ADD, e->fd, &epe) == -1) return -1; diff --git a/src/privsep-root.c b/src/privsep-root.c index 03f68266..b09a67da 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -179,7 +179,7 @@ ps_root_mreaderror(struct dhcpcd_ctx *ctx, void **data, size_t *len) .psr_ctx = ctx, }; - if (eloop_event_add(ctx->ps_eloop, ctx->ps_root_fd, + if (eloop_event_add(ctx->ps_eloop, ctx->ps_root_fd, ELE_READ, ps_root_mreaderrorcb, &psr_ctx) == -1) return -1;