From: Roy Marples Date: Thu, 5 Mar 2015 11:34:47 +0000 (+0000) Subject: Set poll filters before writing eloop event. X-Git-Tag: v6.8.0~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19ebeed7a454eb8d4e3372cdfedcaf2a43b06ae3;p=thirdparty%2Fdhcpcd.git Set poll filters before writing eloop event. --- diff --git a/eloop.c b/eloop.c index e8d5495b..6c941138 100644 --- a/eloop.c +++ b/eloop.c @@ -107,31 +107,36 @@ eloop_event_add(struct eloop_ctx *ctx, int fd, /* We should only have one callback monitoring the fd */ TAILQ_FOREACH(e, &ctx->events, next) { if (e->fd == fd) { - if (read_cb) { - e->read_cb = read_cb; - e->read_cb_arg = read_cb_arg; - } - if (write_cb) { - e->write_cb = write_cb; - e->write_cb_arg = write_cb_arg; - } + int error; + #if defined(HAVE_KQUEUE) EV_SET(&ke[0], fd, EVFILT_READ, EV_ADD, 0, 0, UPTR(e)); if (write_cb) EV_SET(&ke[1], fd, EVFILT_WRITE, EV_ADD, 0, 0, UPTR(e)); - if (kevent(ctx->poll_fd, ke, write_cb ? 2 : 1, - NULL, 0, NULL) == -1) + else if (e->write_cb) + EV_SET(&ke[1], fd, EVFILT_WRITE, EV_DELETE, + 0, 0, UPTR(e)); + error = kevent(ctx->poll_fd, ke, + e->write_cb || write_cb ? 2 : 1, NULL, 0, NULL); goto err; - return 0; #elif defined(HAVE_EPOLL) epe.data.ptr = e; - return epoll_ctl(ctx->poll_fd, EPOLL_CTL_MOD, + error = epoll_ctl(ctx->poll_fd, EPOLL_CTL_MOD, fd, &epe); #else - eloop_event_setup_fds(ctx); - return 0; + error = 0; #endif + if (read_cb) { + e->read_cb = read_cb; + e->read_cb_arg = read_cb_arg; + } + if (write_cb) { + e->write_cb = write_cb; + e->write_cb_arg = write_cb_arg; + } + eloop_event_setup_fds(ctx); + return error; } }