From c3a08ee5899398a5704c3b990235562fbe6cbeff Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Mon, 20 May 2013 00:27:58 +0200 Subject: [PATCH] main: use glib to handle sigterm We can remove a lot of code with that --- src/core/main.c | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index a4e49bce2..6e4287615 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -56,6 +56,7 @@ #include #include +#include #include #include @@ -328,23 +329,8 @@ meta_finalize (void) CurrentTime); /* I doubt correct timestamps matter here */ } -static int sigterm_pipe_fds[2] = { -1, -1 }; - -static void -sigterm_handler (int signum) -{ - if (sigterm_pipe_fds[1] >= 0) - { - int G_GNUC_UNUSED dummy; - - dummy = write (sigterm_pipe_fds[1], "", 1); - close (sigterm_pipe_fds[1]); - sigterm_pipe_fds[1] = -1; - } -} - static gboolean -on_sigterm (void) +on_sigterm (gpointer user_data) { meta_quit (META_EXIT_SUCCESS); return FALSE; @@ -361,8 +347,7 @@ meta_init (void) { struct sigaction act; sigset_t empty_mask; - GIOChannel *channel; - + sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; act.sa_mask = empty_mask; @@ -376,20 +361,7 @@ meta_init (void) g_strerror (errno)); #endif - if (pipe (sigterm_pipe_fds) != 0) - g_printerr ("Failed to create SIGTERM pipe: %s\n", - g_strerror (errno)); - - channel = g_io_channel_unix_new (sigterm_pipe_fds[0]); - g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); - g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_sigterm, NULL); - g_io_channel_set_close_on_unref (channel, TRUE); - g_io_channel_unref (channel); - - act.sa_handler = &sigterm_handler; - if (sigaction (SIGTERM, &act, NULL) < 0) - g_printerr ("Failed to register SIGTERM handler: %s\n", - g_strerror (errno)); + g_unix_signal_add (SIGTERM, on_sigterm, NULL); meta_debug_init ();