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: 67e092abcb ('core: better handling of rfkill for WiMAX and WiFi (bgo #629589) (rh #599002)')
(cherry picked from commit 62a85fa845)
This commit is contained in:
Thomas Haller 2023-04-03 19:18:15 +02:00 committed by Lubomir Rintel
parent 2df22bac90
commit f91ccd984f

View file

@ -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) {