From f316614f59e6662fa3f0aec230092e24d0613df3 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Wed, 20 Jul 2016 02:58:41 +0200 Subject: [PATCH] rfkill: Fix wiphy ID lookup map_wiphy made the assumption that phy names follow the "phyN" pattern but phys created or renamed by the "iw" command can have arbitrary names. It seems that /sys/class/rfkill/rfkill%u/name is not updated on a phy rename, so we can't use it to subsequently read /sys/class/ieee80211//index but both /sys/class/rfkill/rfkill%u/../index and /sys/class/rfkill/rfkill%u/device/index point to that file. --- src/rfkill.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rfkill.c b/src/rfkill.c index 3cbfaeb3..d62cca1a 100644 --- a/src/rfkill.c +++ b/src/rfkill.c @@ -87,7 +87,7 @@ static struct rfkill_map_entry *map_wiphy(unsigned int rfkill_id) unsigned int wiphy_id; struct rfkill_map_entry *entry; - path = l_strdup_printf("/sys/class/rfkill/rfkill%u/name", rfkill_id); + path = l_strdup_printf("/sys/class/rfkill/rfkill%u/device/index", rfkill_id); fd = TFR(open(path, O_RDONLY)); @@ -104,7 +104,7 @@ static struct rfkill_map_entry *map_wiphy(unsigned int rfkill_id) return NULL; buf[bytes] = '\0'; - if (sscanf(buf, "phy%u %n", &wiphy_id, &consumed) != 1 || + if (sscanf(buf, "%u %n", &wiphy_id, &consumed) != 1 || consumed != bytes) return NULL;