[gnome-settings-daemon/benzea/spawn-in-scope-stable] media-keys: Place spawned processes into a systemd scope



commit c46fdb460717d9809808cfd944232e6367215602
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Nov 26 18:20:16 2019 +0100

    media-keys: Place spawned processes into a systemd scope
    
    This means we isolate the processes from the media-keys scope itself.
    
    For this to work, we need at least libgnome-desktop 3.34.2.1 as the API
    was added in that release.

 meson.build                                 |  4 +++
 plugins/media-keys/gsd-media-keys-manager.c | 41 ++++++++++++++++++++++++++++-
 plugins/media-keys/meson.build              |  1 +
 3 files changed, 45 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index 848106fd..ff1771cf 100644
--- a/meson.build
+++ b/meson.build
@@ -219,6 +219,10 @@ if enable_network_manager
 endif
 config_h.set10('HAVE_NETWORK_MANAGER', enable_network_manager)
 
+# GNOME Desktop systemd utilities (added in 3.34.2/3.35.2)
+has_gnome_desktop_systemd = cc.has_header('libgnome-desktop/gnome-systemd.h', dependencies: 
gnome_desktop_dep)
+config_h.set('HAVE_GNOME_SYSTEMD', has_gnome_desktop_systemd)
+
 gnome = import('gnome')
 i18n = import('i18n')
 pkg = import('pkgconfig')
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 0cb7c48c..e76c2395 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -41,6 +41,10 @@
 
 #include <libupower-glib/upower.h>
 #include <gdesktop-enums.h>
+#ifdef HAVE_GNOME_SYSTEMD
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <libgnome-desktop/gnome-systemd.h>
+#endif
 
 #if HAVE_GUDEV
 #include <gudev/gudev.h>
@@ -264,7 +268,6 @@ G_DEFINE_TYPE_WITH_PRIVATE (GsdMediaKeysManager, gsd_media_keys_manager, G_TYPE_
 
 static gpointer manager_object = NULL;
 
-
 static void
 media_key_unref (MediaKey *key)
 {
@@ -996,6 +999,34 @@ init_kbd (GsdMediaKeysManager *manager)
         gnome_settings_profile_end (NULL);
 }
 
+#ifdef HAVE_GNOME_SYSTEMD
+static void
+app_launched_cb (GAppLaunchContext *context,
+                 GAppInfo          *info,
+                 GVariant          *platform_data,
+                 gpointer           user_data)
+{
+        GsdMediaKeysManager *manager = GSD_MEDIA_KEYS_MANAGER (user_data);
+        GsdMediaKeysManagerPrivate *priv = GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager);
+        gint32 pid;
+        const gchar *app_name;
+
+        if (!g_variant_lookup (platform_data, "pid", "i", &pid))
+                return;
+
+        app_name = g_app_info_get_id (info);
+        if (app_name == NULL)
+                app_name = g_app_info_get_executable (info);
+
+        /* Start async request; we don't care about the result */
+        gnome_start_systemd_scope (app_name,
+                                   pid,
+                                   NULL,
+                                   priv->connection,
+                                   NULL, NULL, NULL);
+}
+#endif
+
 static void
 launch_app (GsdMediaKeysManager *manager,
            GAppInfo            *app_info,
@@ -1009,6 +1040,14 @@ launch_app (GsdMediaKeysManager *manager,
         gdk_app_launch_context_set_timestamp (launch_context, timestamp);
         set_launch_context_env (manager, G_APP_LAUNCH_CONTEXT (launch_context));
 
+#ifdef HAVE_GNOME_SYSTEMD
+        g_signal_connect_object (launch_context,
+                                 "launched",
+                                 G_CALLBACK (app_launched_cb),
+                                 manager,
+                                 0);
+#endif
+
        if (!g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error)) {
                g_warning ("Could not launch '%s': %s",
                           g_app_info_get_commandline (app_info),
diff --git a/plugins/media-keys/meson.build b/plugins/media-keys/meson.build
index e6c1d2ac..cbda8eec 100644
--- a/plugins/media-keys/meson.build
+++ b/plugins/media-keys/meson.build
@@ -27,6 +27,7 @@ deps = plugins_deps + [
   gsettings_desktop_dep,
   libcanberra_gtk_dep,
   libcommon_dep,
+  gnome_desktop_dep,
   libgvc_dep,
   libpulse_mainloop_glib_dep,
   m_dep,


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