From 2d6a5bfb0ec8834302a8e20567e33a27f5e95e8e Mon Sep 17 00:00:00 2001
From: c4pp4
Date: Thu, 22 Oct 2026 20:44:18 +0200
Subject: [PATCH 1/1] Handle termination signals in the main loop

The signal handlers installed with signal() close the engine (SQLite,
GObject) and quit the main loop directly from the handler. These calls
are not async-signal-safe: if the signal arrives while the main thread
holds a lock (e.g. inside malloc or SQLite), the handler deadlocks and
the daemon hangs until it is killed, which delays the logout by the
systemd stop timeout (90 s).

Use g_unix_signal_add() to run the same code from the main loop.

Signed-off-by: c4pp4
---
 src/zeitgeist-daemon.vala | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/zeitgeist-daemon.vala b/src/zeitgeist-daemon.vala
index 987c07e..0d1a207 100644
--- a/src/zeitgeist-daemon.vala
+++ b/src/zeitgeist-daemon.vala
@@ -471,9 +471,10 @@ namespace Zeitgeist
             }
         }
 
-        static void safe_exit ()
+        static bool safe_exit ()
         {
             instance.do_quit ();
+            return Source.REMOVE;
         }
 
         static int vacuum ()
@@ -510,9 +511,9 @@ namespace Zeitgeist
 
         static int main (string[] args)
         {
-            Posix.signal (Posix.SIGHUP, safe_exit);
-            Posix.signal (Posix.SIGINT, safe_exit);
-            Posix.signal (Posix.SIGTERM, safe_exit);
+            Unix.signal_add (Posix.SIGHUP, safe_exit);
+            Unix.signal_add (Posix.SIGINT, safe_exit);
+            Unix.signal_add (Posix.SIGTERM, safe_exit);
 
             Intl.setlocale (LocaleCategory.ALL, "");
 
-- 
2.55.0

