[gnome-shell/benzea/systemd-scopes: 192/193] utils: Add utility function to place a PID into a systemd scope
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/benzea/systemd-scopes: 192/193] utils: Add utility function to place a PID into a systemd scope
- Date: Tue, 26 Nov 2019 19:24:10 +0000 (UTC)
commit a6d99900471aff980ad9c3b5f4b0e4d46e65b663
Author: Benjamin Berg <bberg redhat com>
Date: Tue Nov 26 19:44:43 2019 +0100
utils: Add utility function to place a PID into a systemd scope
src/shell-util.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/shell-util.h | 3 +++
2 files changed, 63 insertions(+)
---
diff --git a/src/shell-util.c b/src/shell-util.c
index f344ec50bb..f5edc6fd3c 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -632,6 +632,66 @@ shell_util_stop_systemd_unit (const char *unit,
return shell_util_systemd_call ("StopUnit", unit, mode, error);
}
+
+void
+shell_util_start_systemd_scope (GAppInfo *info,
+ gint32 pid)
+{
+ GVariantBuilder builder;
+ const gchar *app_id;
+ g_autofree gchar *unit_name = NULL;
+ g_autoptr (GDBusConnection) connection = NULL;
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+
+ if (connection == NULL)
+ return;
+
+ g_debug ("Trying to create transient scope for PID %d\n", pid);
+
+ /* Prepare some information */
+ app_id = g_app_info_get_id (info);
+ if (app_id == NULL)
+ app_id = "anonymous";
+
+ /* This needs to be unique, hopefully the pid will be enough. */
+ unit_name = g_strdup_printf ("gnome-shell-launched-%s-%d.scope", app_id, pid);
+
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ssa(sv)a(sa(sv)))"));
+ g_variant_builder_add (&builder, "s", unit_name);
+ g_variant_builder_add (&builder, "s", "fail");
+
+ g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(sv)"));
+ /* Note that futher settings are controlled using a drop-in. */
+ g_variant_builder_add (&builder,
+ "(sv)",
+ "Description",
+ g_variant_new_string ("Application launched by gnome-shell"));
+ g_variant_builder_add (&builder,
+ "(sv)",
+ "PIDs",
+ g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, &pid, 1, 4));
+
+ g_variant_builder_close (&builder);
+
+ g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(sa(sv))"));
+ g_variant_builder_close (&builder);
+
+ g_dbus_connection_call (connection,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "StartTransientUnit",
+ g_variant_builder_end (&builder),
+ G_VARIANT_TYPE ("(o)"),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ 1000,
+ NULL,
+ on_systemd_call_cb,
+ (gpointer) "StartTransientUnit");
+}
+
void
shell_util_sd_notify (void)
{
diff --git a/src/shell-util.h b/src/shell-util.h
index acd031048f..49c4cb2e16 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -64,6 +64,9 @@ gboolean shell_util_stop_systemd_unit (const char *unit,
const char *mode,
GError **error);
+void shell_util_start_systemd_scope (GAppInfo *info,
+ gint32 pid);
+
void shell_util_sd_notify (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]