|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
From cb81159ce49380d39c80f803353784633b8f306c Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
From: "S. Fan" <sfanxiang@gmail.com>
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
Date: Mon, 31 Jul 2017 05:10:10 -0500
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
Subject: [PATCH] rfkill: fix erroneous behavior when polling the udev monitor
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
(#6489)
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
Comparing udev_device_get_sysname(device) and sysname will always return
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
true. We need to check the device received from udev monitor instead.
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
Also, fd_wait_for_event() sometimes never exits. Better set a timeout
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
here.
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
(cherry picked from commit 8ec1a07998758f6a85f3ea5bf2ed14d87609398f)
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
---
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
src/rfkill/rfkill.c | 8 ++++++--
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
index c0f138b4f4..470853d1d2 100644
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
--- a/src/rfkill/rfkill.c
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
+++ b/src/rfkill/rfkill.c
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
@@ -138,17 +138,21 @@ static int wait_for_initialized(
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
for (;;) {
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
_cleanup_udev_device_unref_ struct udev_device *t = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
- r = fd_wait_for_event(watch_fd, POLLIN, USEC_INFINITY);
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
+ r = fd_wait_for_event(watch_fd, POLLIN, EXIT_USEC);
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
if (r == -EINTR)
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
continue;
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
return log_error_errno(r, "Failed to watch udev monitor: %m");
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
+ if (r == 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
+ log_error("Timed out wating for udev monitor.");
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
+ return -ETIMEDOUT;
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
t = udev_monitor_receive_device(monitor);
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
if (!t)
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
continue;
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
- if (streq_ptr(udev_device_get_sysname(device), sysname)) {
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
+ if (streq_ptr(udev_device_get_sysname(t), sysname)) {
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
*ret = udev_device_ref(t);
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
27bd1b |
}
|