]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - src/login1.c
Just create proxy and ask for owner rather than manually calling StartServiceByName...
[sojka/lightdm.git] / src / login1.c
index 60eec45781f41bba46a25f7d4f4a4a0fb18df532..cd780c58999a691994a1d2b72d2d453470320513 100644 (file)
 #include "login1.h"
 
 static gboolean
-start_login1 (void)
+check_login1 (void)
 {
-    GDBusConnection *bus;
-    GVariant *result;
-    guint32 success;
-
-    bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
-    if (!bus)
+    GDBusProxy *proxy;
+    gchar *owner;
+    gboolean success;
+
+    proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                           G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+                                           NULL,
+                                           "org.freedesktop.login1",
+                                           "/org/freedesktop/login1",
+                                           "org.freedesktop.login1.Manager",
+                                           NULL,
+                                           NULL);
+    if (!proxy)
         return FALSE;
 
-    result = g_dbus_connection_call_sync (bus,
-                                          "org.freedesktop.DBus",
-                                          "/org/freedesktop/DBus",
-                                          "org.freedesktop.DBus",
-                                          "StartServiceByName",
-                                          g_variant_new ("(su)",
-                                                         "org.freedesktop.login1",
-                                                         0),
-                                          G_VARIANT_TYPE ("(u)"),
-                                          G_DBUS_CALL_FLAGS_NONE,
-                                          -1,
-                                          NULL,
-                                          NULL);
-    g_object_unref (bus);
-    if (!result)
-        return FALSE;
+    owner = g_dbus_proxy_get_name_owner (proxy);
+    g_object_unref (proxy);
 
-    g_variant_get (result, "(u)", &success);
-    g_variant_unref (result);
+    success = (owner != NULL);
+    g_free (owner);
 
-    return success == 1 || success == 2; // started or already existed
+    return success;
 }
 
 gboolean
@@ -57,7 +50,7 @@ login1_is_running (void)
     if (!have_checked)
     {
         have_checked = TRUE;
-        is_running = start_login1();
+        is_running = check_login1();
     }
 
     return is_running;