]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Make eloop a tad easier to use.
authorRoy Marples <roy@marples.name>
Thu, 17 Mar 2016 14:35:13 +0000 (14:35 +0000)
committerRoy Marples <roy@marples.name>
Thu, 17 Mar 2016 14:35:13 +0000 (14:35 +0000)
arp.c
control.c
dhcp.c
dhcp6.c
dhcpcd.c
eloop.c
eloop.h
ipv6nd.c

diff --git a/arp.c b/arp.c
index d2825d7c3aefcc1cb8a7be8336b0a59f99324710..a17b5f1aaee65b31ac63c5bee257da0b09f349e3 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -201,8 +201,7 @@ arp_open(struct interface *ifp)
                            __func__, ifp->name);
                        return;
                }
-               eloop_event_add(ifp->ctx->eloop, state->fd,
-                   arp_packet, ifp, NULL, NULL);
+               eloop_event_add(ifp->ctx->eloop, state->fd, arp_packet, ifp);
        }
 }
 
index 273cc14211cf5cecdedee33d7718e4a295649e78..e46ef06deabc93180f94d60c49ea1298daf83417 100644 (file)
--- a/control.c
+++ b/control.c
@@ -181,8 +181,7 @@ control_handle1(struct dhcpcd_ctx *ctx, int lfd, unsigned int fd_flags)
                TAILQ_INIT(&l->queue);
                TAILQ_INIT(&l->free_queue);
                TAILQ_INSERT_TAIL(&ctx->control_fds, l, next);
-               eloop_event_add(ctx->eloop, l->fd,
-                   control_handle_data, l, NULL, NULL);
+               eloop_event_add(ctx->eloop, l->fd, control_handle_data, l);
        } else
                close(fd);
 }
@@ -263,14 +262,13 @@ control_start(struct dhcpcd_ctx *ctx, const char *ifname)
                return -1;
 
        ctx->control_fd = fd;
-       eloop_event_add(ctx->eloop, fd, control_handle, ctx, NULL, NULL);
+       eloop_event_add(ctx->eloop, fd, control_handle, ctx);
 
        if (ifname == NULL && (fd = control_start1(ctx, NULL, S_UNPRIV)) != -1){
                /* We must be in master mode, so create an unpriviledged socket
                 * to allow normal users to learn the status of dhcpcd. */
                ctx->control_unpriv_fd = fd;
-               eloop_event_add(ctx->eloop, fd, control_handle_unpriv,
-                   ctx, NULL, NULL);
+               eloop_event_add(ctx->eloop, fd, control_handle_unpriv, ctx);
        }
        return ctx->control_fd;
 }
@@ -410,8 +408,7 @@ control_queue(struct fd_list *fd, char *data, size_t data_len, uint8_t fit)
        d->data_len = data_len;
        d->freeit = fit;
        TAILQ_INSERT_TAIL(&fd->queue, d, next);
-       eloop_event_add(fd->ctx->eloop, fd->fd,
-           NULL, NULL, control_writeone, fd);
+       eloop_event_add_w(fd->ctx->eloop, fd->fd, control_writeone, fd);
        return 0;
 }
 
diff --git a/dhcp.c b/dhcp.c
index 3893675cfbf9225f30c838175b4c82f465b08940..ca882d1477d3d7076cab38d1c39055a5dcc6516d 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -3089,7 +3089,7 @@ dhcp_open(struct interface *ifp)
                        return -1;
                }
                eloop_event_add(ifp->ctx->eloop,
-                   state->raw_fd, dhcp_handlepacket, ifp, NULL, NULL);
+                   state->raw_fd, dhcp_handlepacket, ifp);
        }
        return 0;
 }
@@ -3267,8 +3267,7 @@ dhcp_start1(void *arg)
                                    "%s: dhcp_openudp: %m", __func__);
                } else
                        eloop_event_add(ifp->ctx->eloop,
-                           ifp->ctx->udp_fd, dhcp_handleudp,
-                           ifp->ctx, NULL, NULL);
+                           ifp->ctx->udp_fd, dhcp_handleudp, ifp->ctx);
        }
 
        if (dhcp_init(ifp) == -1) {
diff --git a/dhcp6.c b/dhcp6.c
index 057654a5f4e5f4ad97dfde5818fabcd26bee6ff2..b38e9e7266b0db3c10a5b790349df795f9bd4ce8 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -3166,8 +3166,7 @@ dhcp6_open(struct dhcpcd_ctx *dctx)
            &n, sizeof(n)) == -1)
                goto errexit;
 
-       eloop_event_add(dctx->eloop, ctx->dhcp_fd,
-           dhcp6_handledata, dctx, NULL, NULL);
+       eloop_event_add(dctx->eloop, ctx->dhcp_fd, dhcp6_handledata, dctx);
        return 0;
 
 errexit:
index 079e0b14c7c8b5cdd123ea36933fe6545a22b45e..494c85e66405a6ec7811947f6949fb8efaf89caf 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1369,7 +1369,7 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd,
                return control_queue(fd, UNCONST(fd->ctx->cffile),
                    strlen(fd->ctx->cffile) + 1, 0);
        } else if (strcmp(*argv, "--getinterfaces") == 0) {
-               eloop_event_add(fd->ctx->eloop, fd->fd, NULL, NULL,
+               eloop_event_add_w(fd->ctx->eloop, fd->fd,
                    dhcpcd_getinterfaces, fd);
                return 0;
        } else if (strcmp(*argv, "--listen") == 0) {
@@ -1910,7 +1910,7 @@ printpidfile:
 
        /* Start handling kernel messages for interfaces, addreses and
         * routes. */
-       eloop_event_add(ctx.eloop, ctx.link_fd, handle_link, &ctx, NULL, NULL);
+       eloop_event_add(ctx.eloop, ctx.link_fd, handle_link, &ctx);
 
        /* Start any dev listening plugin which may want to
         * change the interface name provided by the kernel */
diff --git a/eloop.c b/eloop.c
index 44448ff641c2597757c50a50b9526a6e000b1677..e3a748d79994dd9d1c950c9ffd875e38c7371327 100644 (file)
--- a/eloop.c
+++ b/eloop.c
@@ -261,7 +261,7 @@ eloop_pollts(struct pollfd * fds, nfds_t nfds,
 #endif /* HAVE_POLL */
 
 int
-eloop_event_add(struct eloop *eloop, int fd,
+eloop_event_add_rw(struct eloop *eloop, int fd,
     void (*read_cb)(void *), void *read_cb_arg,
     void (*write_cb)(void *), void *write_cb_arg)
 {
@@ -399,6 +399,22 @@ err:
        return -1;
 }
 
+int
+eloop_event_add(struct eloop *eloop, int fd,
+    void (*read_cb)(void *), void *read_cb_arg)
+{
+
+       return eloop_event_add_rw(eloop, fd, read_cb, read_cb_arg, NULL, NULL);
+}
+
+int
+eloop_event_add_w(struct eloop *eloop, int fd,
+    void (*write_cb)(void *), void *write_cb_arg)
+{
+
+       return eloop_event_add_rw(eloop, fd, NULL,NULL, write_cb, write_cb_arg);
+}
+
 void
 eloop_event_delete_write(struct eloop *eloop, int fd, int write_only)
 {
diff --git a/eloop.h b/eloop.h
index 9d9685cbd1102751b4427437c784996a694fd288..0119a80fd7ca8c11762ac8a497bdbd05fa721284 100644 (file)
--- a/eloop.h
+++ b/eloop.h
 /* Forward declare eloop - the content should be invisible to the outside */
 struct eloop;
 
-int eloop_event_add(struct eloop *, int,
+int eloop_event_add_rw(struct eloop *, int,
     void (*)(void *), void *,
     void (*)(void *), void *);
+int eloop_event_add(struct eloop *, int,
+    void (*)(void *), void *);
+int eloop_event_add_w(struct eloop *, int,
+    void (*)(void *), void *);
 #define eloop_event_delete(eloop, fd) \
     eloop_event_delete_write((eloop), (fd), 0)
 #define eloop_event_remove_writecb(eloop, fd) \
index 84af56ac9066b0d0c620972a8de2cfb8b3236742..482899bd9fa9e49bba7553a63053377a397c05a4 100644 (file)
--- a/ipv6nd.c
+++ b/ipv6nd.c
@@ -218,8 +218,7 @@ ipv6nd_open(struct dhcpcd_ctx *dctx)
            &filt, sizeof(filt)) == -1)
                goto eexit;
 
-       eloop_event_add(dctx->eloop, ctx->nd_fd,
-           ipv6nd_handledata, dctx, NULL, NULL);
+       eloop_event_add(dctx->eloop, ctx->nd_fd,  ipv6nd_handledata, dctx);
        return ctx->nd_fd;
 
 eexit: