[PATCH] core: don't activate uninitialized devices from udev



When enumerating devices, libgudev's matching by default will return
devices which udev has not yet finished initializing.

This was frequently causing boot-time races on the OLPC XO, where
NetworkManager would bring a device up before udev had renamed it,
causing the later rename to fail.

To solve this, filter the enumeration matches to only include
initialized devices. The devices that are present but uninitialized
at this time will arrive a short time later, via a uevent.

https://bugs.freedesktop.org/show_bug.cgi?id=56929
---
 src/nm-udev-manager.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/nm-udev-manager.c b/src/nm-udev-manager.c
index 792e53b..60f41aa 100644
--- a/src/nm-udev-manager.c
+++ b/src/nm-udev-manager.c
@@ -515,25 +515,35 @@ void
 nm_udev_manager_query_devices (NMUdevManager *self)
 {
 	NMUdevManagerPrivate *priv = NM_UDEV_MANAGER_GET_PRIVATE (self);
+	GUdevEnumerator *enumerator;
 	GList *devices, *iter;
 
 	g_return_if_fail (self != NULL);
 	g_return_if_fail (NM_IS_UDEV_MANAGER (self));
 
-	devices = g_udev_client_query_by_subsystem (priv->client, "net");
+	enumerator = g_udev_enumerator_new (priv->client);
+	g_udev_enumerator_add_match_subsystem (enumerator, "net");
+	g_udev_enumerator_add_match_is_initialized (enumerator);
+
+	devices = g_udev_enumerator_execute (enumerator);
 	for (iter = devices; iter; iter = g_list_next (iter)) {
 		net_add (self, G_UDEV_DEVICE (iter->data));
 		g_object_unref (G_UDEV_DEVICE (iter->data));
 	}
 	g_list_free (devices);
+	g_object_unref (enumerator);
 
 
-	devices = g_udev_client_query_by_subsystem (priv->client, "atm");
+	enumerator = g_udev_enumerator_new (priv->client);
+	g_udev_enumerator_add_match_subsystem (enumerator, "atm");
+	g_udev_enumerator_add_match_is_initialized (enumerator);
+	devices = g_udev_enumerator_execute (enumerator);
 	for (iter = devices; iter; iter = g_list_next (iter)) {
 		adsl_add (self, G_UDEV_DEVICE (iter->data));
 		g_object_unref (G_UDEV_DEVICE (iter->data));
 	}
 	g_list_free (devices);
+	g_object_unref (enumerator);
 }
 
 static void
-- 
1.7.11.7



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]