[gnome-shell/wip/carlosg/x11-services-on-demand: 1/4] shell: Add helpers to start/stop systemd units



commit 348cd7c9c445825047f32894f5b158b6cc83123d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 15 13:22:24 2019 +0200

    shell: Add helpers to start/stop systemd units
    
    These just send the respective DBus message to the systemd user service.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/680

 src/shell-util.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/shell-util.h |  7 +++++++
 2 files changed, 58 insertions(+)
---
diff --git a/src/shell-util.c b/src/shell-util.c
index 5838d23273..7f01fd9541 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -612,3 +612,54 @@ shell_util_check_cloexec_fds (void)
   fdwalk (check_cloexec, NULL);
   g_info ("Open fd CLOEXEC check complete");
 }
+
+static gboolean
+shell_util_systemd_call (const gchar *command,
+                         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",
+                                       command,
+                                       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;
+}
+
+gboolean
+shell_util_start_systemd_unit (const char  *unit,
+                               const char  *mode,
+                               GError     **error)
+{
+  return shell_util_systemd_call ("StartUnit", unit, mode, error);
+}
+
+gboolean
+shell_util_stop_systemd_unit (const char  *unit,
+                              const char  *mode,
+                              GError     **error)
+{
+  return shell_util_systemd_call ("StopUnit", unit, mode, error);
+}
diff --git a/src/shell-util.h b/src/shell-util.h
index 6904f43bc3..c41e02c798 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -59,6 +59,13 @@ cairo_surface_t * shell_util_composite_capture_images (ClutterCapture  *captures
 
 void shell_util_check_cloexec_fds (void);
 
+gboolean shell_util_start_systemd_unit (const char  *unit,
+                                        const char  *mode,
+                                        GError     **error);
+gboolean shell_util_stop_systemd_unit  (const char  *unit,
+                                        const char  *mode,
+                                        GError     **error);
+
 G_END_DECLS
 
 #endif /* __SHELL_UTIL_H__ */


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