]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Set poll filters before writing eloop event.
authorRoy Marples <roy@marples.name>
Thu, 5 Mar 2015 11:34:47 +0000 (11:34 +0000)
committerRoy Marples <roy@marples.name>
Thu, 5 Mar 2015 11:34:47 +0000 (11:34 +0000)
eloop.c

diff --git a/eloop.c b/eloop.c
index e8d5495bcbda9e1c0748883bd89027853429dfac..6c9411384cfdb84e692e02228a2a047560820339 100644 (file)
--- 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;
                }
        }