[gnome-session/wip/benzea/systemd-user-switch: 10/21] util: Add API to start a systemd unit



commit d735bac05e0bee276b389331f8bbd2faca7e99a3
Author: Benjamin Berg <bberg redhat com>
Date:   Sat Apr 20 01:09:53 2019 +0200

    util: Add API to start a systemd unit
    
    We'll need to start systemd units.

 gnome-session/gsm-util.c | 33 +++++++++++++++++++++++++++++++++
 gnome-session/gsm-util.h |  3 +++
 2 files changed, 36 insertions(+)
---
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
index acb446a3..adc62be9 100644
--- a/gnome-session/gsm-util.c
+++ b/gnome-session/gsm-util.c
@@ -681,6 +681,39 @@ gsm_util_update_user_environment (const char  *variable,
 
         return environment_updated;
 }
+
+gboolean
+gsm_util_start_systemd_unit (const char  *unit,
+                             const char  *mode,
+                             GError     **error)
+{
+        g_autoptr(GDBusConnection) connection = NULL;
+        g_autoptr(GVariant)        reply = NULL;
+        GError          *bus_error = NULL;
+
+        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+
+        if (connection == NULL)
+                return FALSE;
+
+        reply = g_dbus_connection_call_sync (connection,
+                                             "org.freedesktop.systemd1",
+                                             "/org/freedesktop/systemd1",
+                                             "org.freedesktop.systemd1.Manager",
+                                             "StartUnit",
+                                             g_variant_new ("(ss)",
+                                                            unit, mode),
+                                             NULL,
+                                             G_DBUS_CALL_FLAGS_NONE,
+                                             -1, NULL, &bus_error);
+
+        if (bus_error != NULL) {
+                g_propagate_error (error, bus_error);
+                return FALSE;
+        }
+
+        return TRUE;
+}
 #endif
 
 void
diff --git a/gnome-session/gsm-util.h b/gnome-session/gsm-util.h
index 763cae44..8bca5f4d 100644
--- a/gnome-session/gsm-util.h
+++ b/gnome-session/gsm-util.h
@@ -54,6 +54,9 @@ const char * const * gsm_util_listenv               (void);
 gboolean    gsm_util_export_activation_environment  (GError     **error);
 #ifdef HAVE_SYSTEMD
 gboolean    gsm_util_export_user_environment        (GError     **error);
+gboolean    gsm_util_start_systemd_unit             (const char  *unit,
+                                                     const char  *mode,
+                                                     GError     **error);
 #endif
 
 void        gsm_quit                                (void);


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