context: Initialize signal handlers during setup

Is currently done during meta_init().

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-03-02 11:58:57 +01:00
parent 8ace1bf3ea
commit 6f4b973329

View File

@ -22,6 +22,7 @@
#include "core/meta-context-private.h"
#include <glib-unix.h>
#include <locale.h>
#include "backends/meta-backend-private.h"
@ -96,6 +97,36 @@ meta_context_configure (MetaContext *context,
return TRUE;
}
static gboolean
on_sigterm (gpointer user_data)
{
MetaContext *context = META_CONTEXT (user_data);
meta_context_terminate (context);
return G_SOURCE_REMOVE;
}
static void
init_signal_handlers (MetaContext *context)
{
struct sigaction act = { 0 };
sigset_t empty_mask;
sigemptyset (&empty_mask);
act.sa_handler = SIG_IGN;
act.sa_mask = empty_mask;
act.sa_flags = 0;
if (sigaction (SIGPIPE, &act, NULL) < 0)
g_warning ("Failed to register SIGPIPE handler: %s", g_strerror (errno));
#ifdef SIGXFSZ
if (sigaction (SIGXFSZ, &act, NULL) < 0)
g_warning ("Failed to register SIGXFSZ handler: %s", g_strerror (errno));
#endif
g_unix_signal_add (SIGTERM, on_sigterm, context);
}
static const char *
compositor_type_to_description (MetaCompositorType compositor_type)
{
@ -131,6 +162,8 @@ meta_context_setup (MetaContext *context,
return FALSE;
}
init_signal_handlers (context);
compositor_type = meta_context_get_compositor_type (context);
g_message ("Running %s (using mutter %s) as a %s",
priv->name, VERSION,