From f91ccd984fc8fa610f5635710ac0037a8e43afbd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 3 Apr 2023 19:18:15 +0200 Subject: [PATCH] core: fix setting FD flags in _rfkill_update_system() F_SETFL will reset the flags. That is wrong, as we only want to add O_NONBLOCK flag and leaving the other flags alone. Usually, we would need to call F_GETFL first. Note that on Linux, F_SETFL can only set certain flags, so the O_RDWR|O_CLOEXEC flags were unaffected by this. That means, most likely there are no other flags that our use of F_SETFL would wrongly clear. Still, it's ugly, because it's not obvious whether there might be other flags. Avoid that altogether, by setting the flag already during open(). Fixes: 67e092abcbde ('core: better handling of rfkill for WiMAX and WiFi (bgo #629589) (rh #599002)') (cherry picked from commit 62a85fa84560dc296796c3a63f698f8c15794b99) --- src/core/nm-manager.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index 665472941f..19ca1d1e9b 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -2582,7 +2582,7 @@ _rfkill_update_system(NMManager *self, NMRfkillType rtype, gboolean enabled) nm_assert(NM_IN_SET(rtype, NM_RFKILL_TYPE_WLAN, NM_RFKILL_TYPE_WWAN)); - fd = open("/dev/rfkill", O_RDWR | O_CLOEXEC); + fd = open("/dev/rfkill", O_RDWR | O_NONBLOCK | O_CLOEXEC); if (fd < 0) { if (errno == EACCES) _LOGW(LOGD_RFKILL, @@ -2591,14 +2591,6 @@ _rfkill_update_system(NMManager *self, NMRfkillType rtype, gboolean enabled) return; } - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { - _LOGW(LOGD_RFKILL, - "rfkill: (%s): failed to set killswitch device for " - "non-blocking operation", - nm_rfkill_type_to_string(rtype)); - return; - } - memset(&event, 0, sizeof(event)); event.op = KERN_RFKILL_OP_CHANGE_ALL; switch (rtype) {