110 lines
4.9 KiB
Diff
110 lines
4.9 KiB
Diff
From adfe5778edea1273076ed19c51875d5d4a062693 Mon Sep 17 00:00:00 2001
|
|
From: Adrian Vovk <adrianvovk@gmail.com>
|
|
Date: Tue, 8 Apr 2025 11:13:57 -0400
|
|
Subject: [PATCH] systemd: Drop blocking inhibitors before shutdown
|
|
|
|
Starting in systemd v257, systemd simplified the logic it uses for
|
|
inhibitors. It'll now enforce blocking inhibitors, even for processes
|
|
running as the same user that took them. So, gnome-session needs to make
|
|
sure it's not holding any blocking inhibitors when it's time to shutdown,
|
|
otherwise systemd will refuse to shutdown.
|
|
|
|
Fixes: https://gitlab.gnome.org/GNOME/gnome-session/-/issues/142
|
|
---
|
|
gnome-session/gsm-systemd.c | 51 +++++++++++++++++++++++++++----------
|
|
1 file changed, 38 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/gnome-session/gsm-systemd.c b/gnome-session/gsm-systemd.c
|
|
index 9361496e..362491b4 100644
|
|
--- a/gnome-session/gsm-systemd.c
|
|
+++ b/gnome-session/gsm-systemd.c
|
|
@@ -913,6 +913,25 @@ inhibit_done (GObject *source,
|
|
}
|
|
}
|
|
|
|
+static void
|
|
+gsm_systemd_call_inhibit (GsmSystemd *manager,
|
|
+ char *what)
|
|
+{
|
|
+ g_dbus_proxy_call_with_unix_fd_list (manager->priv->sd_proxy,
|
|
+ "Inhibit",
|
|
+ g_variant_new ("(ssss)",
|
|
+ what,
|
|
+ g_get_user_name (),
|
|
+ "user session inhibited",
|
|
+ "block"),
|
|
+ 0,
|
|
+ G_MAXINT,
|
|
+ NULL,
|
|
+ NULL,
|
|
+ inhibit_done,
|
|
+ manager);
|
|
+}
|
|
+
|
|
static void
|
|
gsm_systemd_set_inhibitors (GsmSystem *system,
|
|
GsmInhibitorFlag flags)
|
|
@@ -936,19 +955,19 @@ gsm_systemd_set_inhibitors (GsmSystem *system,
|
|
|
|
if (locks != NULL) {
|
|
g_debug ("Adding system inhibitor on %s", locks);
|
|
- g_dbus_proxy_call_with_unix_fd_list (manager->priv->sd_proxy,
|
|
- "Inhibit",
|
|
- g_variant_new ("(ssss)",
|
|
- locks,
|
|
- g_get_user_name (),
|
|
- "user session inhibited",
|
|
- "block"),
|
|
- 0,
|
|
- G_MAXINT,
|
|
- NULL,
|
|
- NULL,
|
|
- inhibit_done,
|
|
- manager);
|
|
+ gsm_systemd_call_inhibit (manager, locks);
|
|
+ } else {
|
|
+ drop_system_inhibitor (manager);
|
|
+ }
|
|
+}
|
|
+
|
|
+static void
|
|
+gsm_systemd_reacquire_inhibitors (GsmSystemd *manager)
|
|
+{
|
|
+ const gchar *locks = manager->priv->inhibit_locks;
|
|
+ if (locks != NULL) {
|
|
+ g_debug ("Reacquiring system inhibitor on %s", locks);
|
|
+ gsm_systemd_call_inhibit (manager, locks);
|
|
} else {
|
|
drop_system_inhibitor (manager);
|
|
}
|
|
@@ -976,6 +995,7 @@ reboot_or_poweroff_done (GObject *source,
|
|
g_debug ("GsmSystemd: shutdown preparation failed");
|
|
systemd->priv->prepare_for_shutdown_expected = FALSE;
|
|
g_signal_emit_by_name (systemd, "shutdown-prepared", FALSE);
|
|
+ gsm_systemd_reacquire_inhibitors (systemd);
|
|
} else {
|
|
g_variant_unref (result);
|
|
}
|
|
@@ -993,6 +1013,10 @@ gsm_systemd_prepare_shutdown (GsmSystem *system,
|
|
|
|
g_debug ("GsmSystemd: prepare shutdown");
|
|
|
|
+ /* if we're holding a blocking inhibitor to inhibit shutdown, systemd
|
|
+ * will prevent us from shutting down */
|
|
+ drop_system_inhibitor (systemd);
|
|
+
|
|
res = g_dbus_proxy_call_with_unix_fd_list_sync (systemd->priv->sd_proxy,
|
|
"Inhibit",
|
|
g_variant_new ("(ssss)",
|
|
@@ -1010,6 +1034,7 @@ gsm_systemd_prepare_shutdown (GsmSystem *system,
|
|
g_warning ("Failed to get delay inhibitor: %s", error->message);
|
|
g_error_free (error);
|
|
g_signal_emit_by_name (systemd, "shutdown-prepared", FALSE);
|
|
+ gsm_systemd_reacquire_inhibitors (systemd);
|
|
return;
|
|
}
|
|
|
|
--
|
|
2.47.1
|
|
|