From 9d6f980d19d9f59a359fe7c6eac867c10d67491e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Fri, 29 Oct 2021 13:17:54 +0200 Subject: [PATCH] Handle signal to close Gala gracefully on Mutter 3.41 Closes #1258 --- src/Main.vala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Main.vala b/src/Main.vala index 474d917c..c98d39c8 100644 --- a/src/Main.vala +++ b/src/Main.vala @@ -42,7 +42,27 @@ namespace Gala { return Posix.EXIT_FAILURE; } + /* Intercept signals */ ctx.set_plugin_gtype (typeof (WindowManagerGala)); + Posix.sigset_t empty_mask; + Posix.sigemptyset (out empty_mask); + Posix.sigaction_t act = {}; + act.sa_handler = Posix.SIG_IGN; + act.sa_mask = empty_mask; + act.sa_flags = 0; + + if (Posix.sigaction (Posix.SIGPIPE, act, null) < 0) { + warning ("Failed to register SIGPIPE handler: %s", GLib.strerror (GLib.errno)); + } + + if (Posix.sigaction (Posix.SIGXFSZ, act, null) < 0) { + warning ("Failed to register SIGXFSZ handler: %s", GLib.strerror (GLib.errno)); + } + + GLib.Unix.signal_add (Posix.SIGTERM, () => { + ctx.terminate (); + return GLib.Source.REMOVE; + }); #else unowned OptionContext ctx = Meta.get_option_context (); ctx.add_main_entries (Gala.OPTIONS, null);