56c964d
From 67d764ecd52b4f7e972eb355a41cd90b8dcca10c Mon Sep 17 00:00:00 2001
56c964d
From: Benjamin Berg <bberg@redhat.com>
56c964d
Date: Thu, 17 Sep 2020 17:35:58 +0200
56c964d
Subject: [PATCH 4/4] gdesktopappinfo: Add SourcePath= to transient systemd
56c964d
 units
56c964d
56c964d
systemd allows setting a SourcePath= which shows the file that the unit
56c964d
has been generated from. KDE is starting to set this and it seems like a
56c964d
good idea, so do the same here.
56c964d
56c964d
See https://invent.kde.org/frameworks/kio/-/merge_requests/124
56c964d
---
56c964d
 gio/gdesktopappinfo.c | 13 +++++++++++++
56c964d
 1 file changed, 13 insertions(+)
56c964d
56c964d
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
56c964d
index 743027422..1b763b76c 100644
56c964d
--- a/gio/gdesktopappinfo.c
56c964d
+++ b/gio/gdesktopappinfo.c
56c964d
@@ -2777,6 +2777,7 @@ create_systemd_scope (GDBusConnection    *session_bus,
56c964d
 {
56c964d
   GVariantBuilder builder;
56c964d
   const char *app_name = g_get_application_name ();
56c964d
+  const char *source_path = NULL;
56c964d
   char *appid = NULL;
56c964d
   char *appid_escaped = NULL;
56c964d
   char *snid_escaped = NULL;
56c964d
@@ -2802,6 +2803,8 @@ create_systemd_scope (GDBusConnection    *session_bus,
56c964d
    */
56c964d
   unit_name = g_strdup_printf ("app-glib-%s-%d.scope", appid_escaped, pid);
56c964d
 
56c964d
+  source_path = g_desktop_app_info_get_filename (info);
56c964d
+
56c964d
   g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ssa(sv)a(sa(sv)))"));
56c964d
   g_variant_builder_add (&builder, "s", unit_name);
56c964d
   g_variant_builder_add (&builder, "s", "fail");
56c964d
@@ -2815,6 +2818,16 @@ create_systemd_scope (GDBusConnection    *session_bus,
56c964d
                            "Description",
56c964d
                            g_variant_new_take_string (g_strdup_printf ("Application launched by %s",
56c964d
                                                                        app_name)));
56c964d
+
56c964d
+  /* If we have a .desktop file, document that the scope has been "generated"
56c964d
+   * from it.
56c964d
+   */
56c964d
+  if (source_path && g_utf8_validate (source_path, -1, NULL))
56c964d
+    g_variant_builder_add (&builder,
56c964d
+                           "(sv)",
56c964d
+                           "SourcePath",
56c964d
+                           g_variant_new_string (source_path));
56c964d
+
56c964d
   g_variant_builder_add (&builder,
56c964d
                          "(sv)",
56c964d
                          "PIDs",
56c964d
-- 
56c964d
2.29.2
56c964d