]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
On a read error, remove the FD from eloop.
authorRoy Marples <roy@marples.name>
Tue, 1 Apr 2014 11:48:57 +0000 (11:48 +0000)
committerRoy Marples <roy@marples.name>
Tue, 1 Apr 2014 11:48:57 +0000 (11:48 +0000)
This shouldn't happen really.

dhcp.c

diff --git a/dhcp.c b/dhcp.c
index 1beb944c3f66a6d261910d090eb987abd281a915..2480b8155460e336615da2d57427153a813ca6d6 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -2630,31 +2630,38 @@ dhcp_handlepacket(void *arg)
 }
 
 static void
-dhcp_handleudp(void *arg)
+dhcp_handleudp1(struct dhcpcd_ctx *ctx, int *fd, const char *ifname)
 {
-       struct dhcpcd_ctx *ctx;
        uint8_t buffer[sizeof(struct dhcp_message)];
 
-       ctx = arg;
-
        /* Just read what's in the UDP fd and discard it as we always read
         * from the raw fd */
-       (void)read(ctx->udp_fd, buffer, sizeof(buffer));
+       if (read(*fd, buffer, sizeof(buffer)) == -1) {
+               syslog(LOG_ERR, "%s: %s: %m", ifname, __func__);
+               eloop_event_delete(ctx->eloop, *fd);
+               close(*fd);
+               *fd = -1;
+       }
+}
+
+static void
+dhcp_handleudp(void *arg)
+{
+       struct dhcpcd_ctx *ctx;
+
+       ctx = arg;
+       dhcp_handleudp1(arg, &ctx->udp_fd, NULL);
 }
 
 static void
 dhcp_handleifudp(void *arg)
 {
        const struct interface *ifp;
-       const struct dhcp_state *state;
-       uint8_t buffer[sizeof(struct dhcp_message)];
+       struct dhcp_state *state;
 
        ifp = arg;
-       state = D_CSTATE(ifp);
-
-       /* Just read what's in the UDP fd and discard it as we always read
-        * from the raw fd */
-       (void)read(state->udp_fd, buffer, sizeof(buffer));
+       state = D_STATE(ifp);
+       dhcp_handleudp1(ifp->ctx, &state->udp_fd, ifp->name);
 }
 
 static int