From 8ec1a07998758f6a85f3ea5bf2ed14d87609398f Mon Sep 17 00:00:00 2001 From: "S. Fan" Date: Mon, 31 Jul 2017 05:10:10 -0500 Subject: rfkill: fix erroneous behavior when polling the udev monitor (#6489) 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index c0f138b4f4..470853d1d2 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -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; } -- cgit v1.2.1