linux_netlink: Retry poll() on EINTR
authorChris Dickens <christopher.a.dickens@gmail.com>
Mon, 20 Feb 2017 08:51:14 +0000 (00:51 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Mon, 20 Feb 2017 08:51:14 +0000 (00:51 -0800)
This commit applies the same fix as commit 0a02d121 did for udev.
I've also removed usbi_ from the read()/write() function calls as
it is pointless.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/linux_netlink.c
libusb/os/linux_udev.c
libusb/version_nano.h

index 60cf3ad..2aadfa9 100644 (file)
@@ -162,7 +162,7 @@ int linux_netlink_stop_event_monitor(void)
 
        /* Write some dummy data to the control pipe and
         * wait for the thread to exit */
-       r = usbi_write(netlink_control_pipe[1], &dummy, sizeof(dummy));
+       r = write(netlink_control_pipe[1], &dummy, sizeof(dummy));
        if (r <= 0)
                usbi_warn(NULL, "netlink control pipe signal failed");
 
@@ -356,7 +356,8 @@ static int linux_netlink_read_message(void)
 static void *linux_netlink_event_thread_main(void *arg)
 {
        char dummy;
-       ssize_t r;
+       int r;
+       ssize_t nb;
        struct pollfd fds[] = {
                { .fd = netlink_control_pipe[0],
                  .events = POLLIN },
@@ -368,11 +369,15 @@ static void *linux_netlink_event_thread_main(void *arg)
 
        usbi_dbg("netlink event thread entering");
 
-       while (poll(fds, 2, -1) >= 0) {
+       while ((r = poll(fds, 2, -1)) >= 0 || errno == EINTR) {
+               if (r < 0) {
+                       /* temporary failure */
+                       continue;
+               }
                if (fds[0].revents & POLLIN) {
                        /* activity on control pipe, read the byte and exit */
-                       r = usbi_read(netlink_control_pipe[0], &dummy, sizeof(dummy));
-                       if (r <= 0)
+                       nb = read(netlink_control_pipe[0], &dummy, sizeof(dummy));
+                       if (nb <= 0)
                                usbi_warn(NULL, "netlink control pipe read failed");
                        break;
                }
index 61d953d..3ba352d 100644 (file)
@@ -134,7 +134,7 @@ int linux_udev_stop_event_monitor(void)
 
        /* Write some dummy data to the control pipe and
         * wait for the thread to exit */
-       r = usbi_write(udev_control_pipe[1], &dummy, sizeof(dummy));
+       r = write(udev_control_pipe[1], &dummy, sizeof(dummy));
        if (r <= 0) {
                usbi_warn(NULL, "udev control pipe signal failed");
        }
@@ -162,6 +162,7 @@ static void *linux_udev_event_thread_main(void *arg)
 {
        char dummy;
        int r;
+       ssize_t nb;
        struct udev_device* udev_dev;
        struct pollfd fds[] = {
                {.fd = udev_control_pipe[0],
@@ -179,8 +180,8 @@ static void *linux_udev_event_thread_main(void *arg)
                }
                if (fds[0].revents & POLLIN) {
                        /* activity on control pipe, read the byte and exit */
-                       r = usbi_read(udev_control_pipe[0], &dummy, sizeof(dummy));
-                       if (r <= 0) {
+                       nb = read(udev_control_pipe[0], &dummy, sizeof(dummy));
+                       if (nb <= 0) {
                                usbi_warn(NULL, "udev control pipe read failed");
                        }
                        break;
index e76cd1b..a7b48f3 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11184
+#define LIBUSB_NANO 11185