From 5eb8203f8eba57aca55f67d63b309522c281e353 Mon Sep 17 00:00:00 2001 From: Arnav Singh Date: Sun, 22 Dec 2024 16:48:06 -0800 Subject: suspend: support logind not sending PrepareForSleep(true) elogind sends PrepareForSleep(false) when resuming but doesn't necessarily send PrepareForSleep(true) when sleeping. This means we didn't necessarily drop our previous inhibitor when it's time to take a new one. So instead of asserting that we dropped our previous inhibitor, just reuse it. --- src/mm-sleep-monitor-systemd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mm-sleep-monitor-systemd.c b/src/mm-sleep-monitor-systemd.c index 99814386..c432a416 100644 --- a/src/mm-sleep-monitor-systemd.c +++ b/src/mm-sleep-monitor-systemd.c @@ -114,7 +114,12 @@ inhibit_done (GObject *source, static void take_inhibitor (MMSleepMonitor *self) { - g_assert (self->inhibit_fd == -1); + if (self->inhibit_fd != -1) { + // logind didn't send us a `PrepareForSleep(true)` so we didn't drop our previous inhibitor. + // Just reuse it. + mm_obj_warn (self, "logind did not send sleep notification! Taking over existing inhibitor."); + return; + } mm_obj_dbg (self, "taking systemd sleep inhibitor"); g_dbus_proxy_call_with_unix_fd_list (self->sd_proxy, -- cgit v1.2.3-70-g09d2