]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rfkill: fix erroneous behavior when polling the udev monitor (#6489)
authorS. Fan <sfanxiang@gmail.com>
Mon, 31 Jul 2017 10:10:10 +0000 (05:10 -0500)
committerLennart Poettering <lennart@poettering.net>
Mon, 31 Jul 2017 10:10:10 +0000 (12:10 +0200)
Comparing udev_device_get_sysname(device) and sysname will always return
true. We need to check the device received from udev monitor instead.

Also, fd_wait_for_event() sometimes never exits. Better set a timeout
here.

src/rfkill/rfkill.c

index c0f138b4f4459b590e641af64fb758dcd7d515ad..470853d1d2f5d08ec1ba58e54141de0547f63f96 100644 (file)
@@ -138,17 +138,21 @@ static int wait_for_initialized(
         for (;;) {
                 _cleanup_udev_device_unref_ struct udev_device *t = NULL;
 
-                r = fd_wait_for_event(watch_fd, POLLIN, USEC_INFINITY);
+                r = fd_wait_for_event(watch_fd, POLLIN, EXIT_USEC);
                 if (r == -EINTR)
                         continue;
                 if (r < 0)
                         return log_error_errno(r, "Failed to watch udev monitor: %m");
+                if (r == 0) {
+                        log_error("Timed out wating for udev monitor.");
+                        return -ETIMEDOUT;
+                }
 
                 t = udev_monitor_receive_device(monitor);
                 if (!t)
                         continue;
 
-                if (streq_ptr(udev_device_get_sysname(device), sysname)) {
+                if (streq_ptr(udev_device_get_sysname(t), sysname)) {
                         *ret = udev_device_ref(t);
                         return 0;
                 }