summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2013-10-25 11:24:41 +0300
committerChengyi Zhao <chengyi1.zhao@archermind.com>2013-11-01 09:23:56 +0800
commitd66436126d39eebb730b3734f4ff160931a03316 (patch)
treec2138685118331b23901aa15431683c863f5a3cf
parent75db3d8015d3de4297f351fd182270daa59884f2 (diff)
downloadconnman-d66436126d39eebb730b3734f4ff160931a03316.tar.gz
connman-d66436126d39eebb730b3734f4ff160931a03316.tar.bz2
connman-d66436126d39eebb730b3734f4ff160931a03316.zip
Use always the interface index and only when interface name is needed, then fetch the name. This minimizes races when interface name changes because of udev rules. Upstream commit Id: bcb7f23f1e9afb2cf8f27368f9da418b49db9adc Change-Id: I5f128f2d7c118ec90381388dc313b91ff4e4c8f9 Signed-off-by: Chengyi Zhao <chengyi1.zhao@archermind.com>
-rw-r--r--src/rtnl.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/rtnl.c b/src/rtnl.c
index b259cd83..ead05b08 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -65,7 +65,6 @@ static guint update_timeout = 0;
struct interface_data {
int index;
- char *name;
char *ident;
enum connman_service_type service_type;
enum connman_device_type device_type;
@@ -81,7 +80,6 @@ static void free_interface(gpointer data)
interface->index, interface->ident);
g_free(interface->ident);
- g_free(interface->name);
g_free(interface);
}
@@ -120,11 +118,13 @@ static connman_bool_t wext_interface(char *ifname)
static void read_uevent(struct interface_data *interface)
{
- char *filename, line[128];
+ char *filename, *name, line[128];
connman_bool_t found_devtype;
FILE *f;
- if (ether_blacklisted(interface->name) == TRUE) {
+ name = connman_inet_ifname(interface->index);
+
+ if (ether_blacklisted(name) == TRUE) {
interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
} else {
@@ -132,8 +132,7 @@ static void read_uevent(struct interface_data *interface)
interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
}
- filename = g_strdup_printf("/sys/class/net/%s/uevent",
- interface->name);
+ filename = g_strdup_printf("/sys/class/net/%s/uevent", name);
f = fopen(filename, "re");
@@ -142,7 +141,7 @@ static void read_uevent(struct interface_data *interface)
if (!f) {
interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
- return;
+ goto out;
}
found_devtype = FALSE;
@@ -181,16 +180,18 @@ static void read_uevent(struct interface_data *interface)
fclose(f);
if (found_devtype)
- return;
+ goto out;
/* We haven't got a DEVTYPE, let's check if it's a wireless device */
- if (wext_interface(interface->name)) {
+ if (wext_interface(name)) {
interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;
- connman_error("%s runs an unsupported 802.11 driver",
- interface->name);
+ connman_error("%s runs an unsupported 802.11 driver", name);
}
+
+out:
+ g_free(name);
}
enum connman_device_type __connman_rtnl_get_device_type(int index)
@@ -455,7 +456,6 @@ static void process_newlink(unsigned short type, int index, unsigned flags,
if (interface == NULL) {
interface = g_new0(struct interface_data, 1);
interface->index = index;
- interface->name = g_strdup(ifname);
interface->ident = g_strdup(ident);
g_hash_table_insert(interface_list,