[mutter/wip/wayland-display: 13/55] Fix handling SIGTERM while DRM-locked
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/wayland-display: 13/55] Fix handling SIGTERM while DRM-locked
- Date: Tue, 30 Jul 2013 16:16:56 +0000 (UTC)
commit c7c61c7196d066213f2c70b404abd4c3b9a60686
Author: Giovanni Campagna <gcampagn redhat com>
Date: Tue Jul 16 15:41:26 2013 +0200
Fix handling SIGTERM while DRM-locked
And at the same time, clean up the signal handling in the regular
case.
src/core/main.c | 77 +++--------------------------------------------
src/wayland/meta-tty.c | 12 +++++--
2 files changed, 14 insertions(+), 75 deletions(-)
---
diff --git a/src/core/main.c b/src/core/main.c
index d0e167a..30e70fe 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -60,6 +60,7 @@
#endif
#include <glib-object.h>
+#include <glib-unix.h>
#include <gdk/gdkx.h>
#include <stdlib.h>
@@ -356,59 +357,12 @@ meta_finalize (void)
#endif
}
-static int signal_pipe_fds[2] = { -1, -1 };
-
-static void
-signal_handler (int signum)
-{
- if (signal_pipe_fds[1] >= 0)
- {
- switch (signum)
- {
- case SIGTERM:
- write (signal_pipe_fds[1], "T", 1);
- break;
- default:
- break;
- }
- }
-}
-
static gboolean
-on_signal (GIOChannel *source,
- GIOCondition condition,
- void *data)
+on_sigterm (gpointer user_data)
{
- char signal;
- int count;
+ meta_quit (EXIT_SUCCESS);
- for (;;)
- {
- count = read (signal_pipe_fds[0], &signal, 1);
- if (count == EINTR)
- continue;
- if (count < 0)
- {
- const char *msg = strerror (errno);
- g_warning ("Error handling signal: %s", msg);
- }
- if (count != 1)
- {
- g_warning ("Unexpectedly failed to read byte from signal pipe\n");
- return TRUE;
- }
- break;
- }
- switch (signal)
- {
- case 'T': /* SIGTERM */
- meta_quit (META_EXIT_SUCCESS);
- break;
- default:
- g_warning ("Spurious character '%c' read from signal pipe", signal);
- }
-
- return TRUE;
+ return G_SOURCE_REMOVE;
}
/**
@@ -422,7 +376,6 @@ meta_init (void)
{
struct sigaction act;
sigset_t empty_mask;
- GIOChannel *channel;
sigemptyset (&empty_mask);
act.sa_handler = SIG_IGN;
@@ -437,27 +390,7 @@ meta_init (void)
g_strerror (errno));
#endif
- if (pipe (signal_pipe_fds) != 0)
- g_printerr ("Failed to create signal pipe: %s\n",
- g_strerror (errno));
-
- channel = g_io_channel_unix_new (signal_pipe_fds[0]);
- g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
- g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_signal, NULL);
- g_io_channel_set_close_on_unref (channel, TRUE);
- g_io_channel_unref (channel);
-
- act.sa_handler = &signal_handler;
- if (sigaction (SIGTERM, &act, NULL) < 0)
- g_printerr ("Failed to register SIGTERM handler: %s\n",
- g_strerror (errno));
-
- if (meta_is_display_server ())
- {
- if (sigaction (SIGCHLD, &act, NULL) < 0)
- g_printerr ("Failed to register SIGCHLD handler: %s\n",
- g_strerror (errno));
- }
+ g_unix_signal_add (SIGTERM, on_sigterm, NULL);
if (g_getenv ("MUTTER_VERBOSE"))
meta_set_verbose (TRUE);
diff --git a/src/wayland/meta-tty.c b/src/wayland/meta-tty.c
index 31a6359..b0161a4 100644
--- a/src/wayland/meta-tty.c
+++ b/src/wayland/meta-tty.c
@@ -64,6 +64,7 @@ struct _MetaTTY
int input_source;
GSource *vt_enter_source, *vt_leave_source;
+ GSource *nested_term;
int vt, starting_vt;
int kb_mode;
};
@@ -83,7 +84,7 @@ G_DEFINE_TYPE_WITH_CODE (MetaTTY, meta_tty, G_TYPE_OBJECT,
meta_tty_initable_iface_init));
static gboolean
-vt_acquire_handler (gpointer user_data)
+quit_nested_loop (gpointer user_data)
{
MetaTTY *tty = user_data;
@@ -298,16 +299,20 @@ meta_tty_initable_init(GInitable *initable,
goto err_kdmode;
}
- tty->vt_enter_source = g_unix_signal_source_new (SIGUSR2);
- g_source_set_callback (tty->vt_enter_source, vt_acquire_handler, tty, NULL);
tty->vt_leave_source = g_unix_signal_source_new (SIGUSR1);
g_source_set_callback (tty->vt_leave_source, vt_release_handler, tty, NULL);
+ tty->vt_enter_source = g_unix_signal_source_new (SIGUSR2);
+ g_source_set_callback (tty->vt_enter_source, quit_nested_loop, tty, NULL);
+ tty->nested_term = g_unix_signal_source_new (SIGTERM);
+ g_source_set_callback (tty->nested_term, quit_nested_loop, tty, NULL);
+
tty->nested_context = g_main_context_new ();
tty->nested_loop = g_main_loop_new (tty->nested_context, FALSE);
g_source_attach (tty->vt_leave_source, NULL);
g_source_attach (tty->vt_enter_source, tty->nested_context);
+ g_source_attach (tty->nested_term, tty->nested_context);
return TRUE;
@@ -362,6 +367,7 @@ meta_tty_finalize (GObject *object)
g_source_destroy (tty->vt_enter_source);
g_source_destroy (tty->vt_leave_source);
+ g_source_destroy (tty->nested_term);
g_main_loop_unref (tty->nested_loop);
g_main_context_unref (tty->nested_context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]