summaryrefslogtreecommitdiffstats
path: root/metacity-dont-do-bad-stuff-on-sigterm.patch
blob: 7402e6c97c5c39c240d34b75569527268b19d74b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
diff -up metacity-2.28.0/src/core/main.c.sigterm metacity-2.28.0/src/core/main.c
--- metacity-2.28.0/src/core/main.c.sigterm	2009-11-05 14:53:40.599237201 -0500
+++ metacity-2.28.0/src/core/main.c	2009-11-05 17:28:18.601486344 -0500
@@ -67,6 +67,7 @@
 #include <fcntl.h>
 #include <locale.h>
 #include <time.h>
+#include <unistd.h>
 
 /**
  * The exit code we'll return to our parent process when we eventually die.
@@ -368,12 +369,25 @@ 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)
+    {
+      ssize_t bytes_written;
+      bytes_written = 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;
 }
 
 static guint sigchld_signal_id = 0;
@@ -421,6 +434,7 @@ main (int argc, char **argv)
     "Pango", "GLib-GObject", "GThread"
   };
   guint i;
+  GIOChannel *channel;
 
   if (!g_thread_supported ())
     g_thread_init (NULL);
@@ -443,6 +457,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",