]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
control: Fix working with new eloop
authorRoy Marples <roy@marples.name>
Wed, 10 Mar 2021 13:09:39 +0000 (13:09 +0000)
committerRoy Marples <roy@marples.name>
Wed, 10 Mar 2021 13:09:39 +0000 (13:09 +0000)
src/control.c

index 13602914763a4b6c0aa0ce9015e6fa4c33d3254a..e77dd176580365f27f1d03d1508d868641fdedf7 100644 (file)
@@ -100,11 +100,15 @@ control_handle_read(struct fd_list *fd)
        ssize_t bytes;
 
        bytes = read(fd->fd, buffer, sizeof(buffer) - 1);
-
-       if (bytes == -1 || bytes == 0) {
-               /* Control was closed or there was an error.
-                * Remove it from our list. */
+#ifdef PRIVSEP
+       if (bytes == 0 && IN_PRIVSEP(fd->ctx)) {
+               if (ps_ctl_sendeof(fd) == -1)
+                       logerr(__func__);
+       }
+#endif
+       if (bytes == -1)
                logerr(__func__);
+       if (bytes == -1 || bytes == 0) {
                control_free(fd);
                return;
        }
@@ -171,20 +175,17 @@ control_handle_write(struct fd_list *fd)
        if (TAILQ_FIRST(&fd->queue) != NULL)
                return;
 
-       /* Remove ELE_WRITE */
-       if (fd->flags & FD_LISTEN) {
-               if (eloop_event_add(fd->ctx->eloop, fd->fd, ELE_READ,
-                   control_handle_data, fd) == -1)
-                       logerr("%s: eloop_event_add", __func__);
-       } else
-               eloop_event_delete(fd->ctx->eloop, fd->fd);
 #ifdef PRIVSEP
        if (IN_PRIVSEP_SE(fd->ctx) && !(fd->flags & FD_LISTEN)) {
                if (ps_ctl_sendeof(fd) == -1)
                        logerr(__func__);
-               control_free(fd);
        }
 #endif
+
+       /* Done sending data, stop watching write to fd */
+       if (eloop_event_add(fd->ctx->eloop, fd->fd, ELE_READ,
+           control_handle_data, fd) == -1)
+               logerr("%s: eloop_event_add", __func__);
 }