platform: wifi: use nmp_utils_open_sysctl() to check if device is wifi
Since function nmp_utils_open_sysctl() can avoid race condition, use it in wifi_utils_is_wifi() to open sysfs and correctly check if it's a wifi device. https://bugzilla.gnome.org/show_bug.cgi?id=775613 Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
This commit is contained in:

committed by
Thomas Haller

parent
713c74f6e4
commit
b95556eb78
@@ -26,6 +26,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "wifi-utils-private.h"
|
||||
#include "wifi-utils-nl80211.h"
|
||||
@@ -34,6 +35,8 @@
|
||||
#endif
|
||||
#include "nm-core-utils.h"
|
||||
|
||||
#include "platform/nm-platform-utils.h"
|
||||
|
||||
gpointer
|
||||
wifi_data_new (const char *iface, int ifindex, gsize len)
|
||||
{
|
||||
@@ -180,23 +183,35 @@ wifi_utils_deinit (WifiData *data)
|
||||
}
|
||||
|
||||
gboolean
|
||||
wifi_utils_is_wifi (const char *iface)
|
||||
wifi_utils_is_wifi (int ifindex, const char *ifname)
|
||||
{
|
||||
char phy80211_path[NM_STRLEN ("/sys/class/net/123456789012345/phy80211\0") + 100 /*safety*/];
|
||||
int fd_sysnet;
|
||||
int fd_phy80211;
|
||||
struct stat s;
|
||||
|
||||
g_return_val_if_fail (iface != NULL, FALSE);
|
||||
g_return_val_if_fail (ifname != NULL, FALSE);
|
||||
|
||||
nm_sprintf_buf (phy80211_path,
|
||||
"/sys/class/net/%s/phy80211",
|
||||
NM_ASSERT_VALID_PATH_COMPONENT (iface));
|
||||
nm_assert (strlen (phy80211_path) < sizeof (phy80211_path) - 1);
|
||||
fd_sysnet = nmp_utils_open_sysctl (ifindex, ifname);
|
||||
if (fd_sysnet < 0)
|
||||
return FALSE;
|
||||
|
||||
if ((stat (phy80211_path, &s) == 0 && (s.st_mode & S_IFDIR)))
|
||||
fd_phy80211 = openat (fd_sysnet, "phy80211", 0);
|
||||
if (fd_phy80211 < 0) {
|
||||
close (fd_sysnet);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((fstat (fd_phy80211, &s) == 0 && (s.st_mode & S_IFDIR))) {
|
||||
close (fd_sysnet);
|
||||
close (fd_phy80211);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
close (fd_sysnet);
|
||||
close (fd_phy80211);
|
||||
|
||||
#if HAVE_WEXT
|
||||
if (wifi_wext_is_wifi (iface))
|
||||
if (wifi_wext_is_wifi (ifname))
|
||||
return TRUE;
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user