From: Roy Marples Date: Thu, 17 Mar 2016 14:35:13 +0000 (+0000) Subject: Make eloop a tad easier to use. X-Git-Tag: v6.10.2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eeda296867934185dc105385d0ae4636179c3e10;p=thirdparty%2Fdhcpcd.git Make eloop a tad easier to use. --- diff --git a/arp.c b/arp.c index d2825d7c..a17b5f1a 100644 --- 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); } } diff --git a/control.c b/control.c index 273cc142..e46ef06d 100644 --- 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 3893675c..ca882d14 100644 --- 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 057654a5..b38e9e72 100644 --- 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: diff --git a/dhcpcd.c b/dhcpcd.c index 079e0b14..494c85e6 100644 --- 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 44448ff6..e3a748d7 100644 --- 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 9d9685cb..0119a80f 100644 --- a/eloop.h +++ b/eloop.h @@ -69,9 +69,13 @@ /* 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) \ diff --git a/ipv6nd.c b/ipv6nd.c index 84af56ac..482899bd 100644 --- 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: