[mutter] Don't call meta_finalize from SIGTERM handler



commit 5134b05af9948b441ee1098ee05153bf268b6620
Author: Ray Strode <rstrode redhat com>
Date:   Thu Nov 5 14:47:47 2009 -0500

    Don't call meta_finalize from SIGTERM handler
    
    It's not a legal function to call from a signal handler.
    Instead defer until going back to the main loop.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=600864

 src/core/main.c |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/src/core/main.c b/src/core/main.c
index e136617..2a616be 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -68,6 +68,7 @@
 #include <fcntl.h>
 #include <locale.h>
 #include <time.h>
+#include <unistd.h>
 
 #include <clutter/clutter.h>
 #include <clutter/x11/clutter-x11.h>
@@ -445,12 +446,24 @@ meta_finalize (void)
   meta_session_shutdown ();
 }
 
+static int sigterm_pipe_fds[2] = { -1, -1 };
+
 static void
 sigterm_handler (int signum)
 {
-  meta_finalize ();
+  if (sigterm_pipe_fds[1] >= 0)
+    {
+      write (sigterm_pipe_fds[1], "", 1);
+      close (sigterm_pipe_fds[1]);
+      sigterm_pipe_fds[1] = -1;
+    }
+}
 
-  exit (meta_exit_code);
+static gboolean
+on_sigterm (void)
+{
+  meta_quit (META_EXIT_SUCCESS);
+  return FALSE;
 }
 
 /**
@@ -475,8 +488,9 @@ main (int argc, char **argv)
     "Pango", "GLib-GObject", "GThread"
   };
   guint i;
+  GIOChannel *channel;
   GOptionContext *ctx;
-  
+
   if (!g_thread_supported ())
     g_thread_init (NULL);
   
@@ -498,6 +512,16 @@ main (int argc, char **argv)
                 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",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]