[network-manager-applet/dcbw/fixes: 2/2] applet: don't block on ModemManager initialization



commit 8a8c384fd1c6019fefe372069b67f42b7090f587
Author: Dan Williams <dcbw redhat com>
Date:   Thu May 1 09:51:45 2014 -0500

    applet: don't block on ModemManager initialization
    
    First, don't autostart ModemManager since the applet is only using
    ModemManager for information and not for controlling modems.  Leave
    that to system services (like systemd or upstart).  Requesting
    autostart can block for long periods of time in some situations,
    like if the process hangs during startup or isn't actually present
    on the disk.
    
    Second, make ModemManager initialization asynchronous to avoid any
    other initialization blockage.  The applet only uses MM for info
    about devices NM already knows about, so it's not critical to
    applet startup.

 src/applet.c |   53 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 30 insertions(+), 23 deletions(-)
---
diff --git a/src/applet.c b/src/applet.c
index 59691f6..a8e2dc9 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -2703,37 +2703,44 @@ mm1_name_owner_changed_cb (GDBusObjectManagerClient *mm1,
 }
 
 static void
+mm_new_ready (GDBusConnection *connection,
+              GAsyncResult *res,
+              NMApplet *applet)
+{
+    GError *error = NULL;
+
+    applet->mm1 = mm_manager_new_finish (res, &error);
+       if (applet->mm1) {
+               /* Check whether the ModemManager is really running */
+               g_signal_connect (applet->mm1,
+                                 "notify::name-owner",
+                                 G_CALLBACK (mm1_name_owner_changed_cb),
+                                 applet);
+               mm1_name_owner_changed_cb (G_DBUS_OBJECT_MANAGER_CLIENT (applet->mm1), NULL, applet);
+       } else {
+               g_warning ("Error connecting to ModemManager: %s", error->message);
+               g_clear_error (&error);
+       }
+}
+
+static void
 mm1_client_setup (NMApplet *applet)
 {
        GDBusConnection *system_bus;
        GError *error = NULL;
 
        system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
-       if (!system_bus) {
-               g_warning ("Error connecting to system D-Bus: %s",
-                          error->message);
-               g_clear_error (&error);
-               return;
-       }
-
-       applet->mm1 = (mm_manager_new_sync (
-                              system_bus,
-                              G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
-                              NULL,
-                              &error));
-       if (!applet->mm1) {
-               g_warning ("Error connecting to ModemManager: %s",
-                          error->message);
+       if (system_bus) {
+               mm_manager_new (system_bus,
+                               G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START,
+                               NULL,
+                               (GAsyncReadyCallback) mm_new_ready,
+                               applet);
+               g_object_unref (system_bus);
+       } else {
+               g_warning ("Error connecting to system D-Bus: %s", error->message);
                g_clear_error (&error);
-               return;
        }
-
-       /* Check whether the ModemManager is really running */
-       g_signal_connect (applet->mm1,
-                         "notify::name-owner",
-                         G_CALLBACK (mm1_name_owner_changed_cb),
-                         applet);
-       mm1_name_owner_changed_cb (G_DBUS_OBJECT_MANAGER_CLIENT (applet->mm1), NULL, applet);
 }
 
 #endif /* WITH_MODEM_MANAGER_1 */


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