[Xfce4-commits] <xfwm4:xfce-4.8> Fix crash in signal handler

Olivier Fourdan noreply at xfce.org
Tue Oct 25 14:26:01 CEST 2011


Updating branch refs/heads/xfce-4.8
         to 109d8b2409900fef3d4b75e2441b977721b4d35e (commit)
       from 68c8ea50a16658bba84635d45b3b50e656bdd063 (commit)

commit 109d8b2409900fef3d4b75e2441b977721b4d35e
Author: Olivier Fourdan <fourdan at xfce.org>
Date:   Tue Oct 25 13:46:33 2011 +0200

    Fix crash in signal handler
    
    Conflicts:
    
    	src/main.c

 src/main.c |   83 ++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 48 insertions(+), 35 deletions(-)

diff --git a/src/main.c b/src/main.c
index 0f1cb1e..621bfa1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -95,14 +95,59 @@ static DisplayInfo *main_display_info = NULL;
 static gint compositor = COMPOSITOR_MODE_MANUAL;
 
 static void
+handleSignal (int sig)
+{
+    if (main_display_info)
+    {
+        switch (sig)
+        {
+            case SIGINT:
+                /* Walk thru */
+            case SIGTERM:
+                gtk_main_quit ();
+                main_display_info->quit = TRUE;
+                break;
+            case SIGHUP:
+                /* Walk thru */
+            case SIGUSR1:
+                main_display_info->reload = TRUE;
+                break;
+            default:
+                break;
+        }
+    }
+}
+
+static void
+setupHandler (gboolean install)
+{
+    struct sigaction act;
+
+    if (install)
+        act.sa_handler = handleSignal;
+    else
+        act.sa_handler = SIG_DFL;
+
+    sigemptyset (&act.sa_mask);
+    act.sa_flags = 0;
+    sigaction (SIGINT,  &act, NULL);
+    sigaction (SIGTERM, &act, NULL);
+    sigaction (SIGHUP,  &act, NULL);
+    sigaction (SIGUSR1, &act, NULL);
+    sigaction (SIGSEGV, &act, NULL);
+}
+
+static void
 cleanUp (void)
 {
     GSList *screens;
 
-    g_return_if_fail (main_display_info);
-
     TRACE ("entering cleanUp");
 
+    setupHandler (FALSE);
+
+    g_return_if_fail (main_display_info);
+
     eventFilterClose (main_display_info->xfilter);
     for (screens = main_display_info->screens; screens; screens = g_slist_next (screens))
     {
@@ -120,31 +165,6 @@ cleanUp (void)
 }
 
 static void
-handleSignal (int sig)
-{
-    TRACE ("entering handleSignal");
-
-    switch (sig)
-    {
-        case SIGINT:
-        case SIGTERM:
-            gtk_main_quit ();
-            main_display_info->quit = TRUE;
-            break;
-        case SIGHUP:
-        case SIGUSR1:
-            main_display_info->reload = TRUE;
-            break;
-        case SIGSEGV:
-            cleanUp ();
-            g_error (_("%s: Segmentation fault"), PACKAGE);
-            break;
-        default:
-            break;
-    }
-}
-
-static void
 ensure_basedir_spec (void)
 {
     char *new, *old, path[PATH_MAX];
@@ -389,7 +409,6 @@ compositor_callback (const gchar  *name,
 static int
 initialize (gint compositor_mode, gboolean replace_wm)
 {
-    struct sigaction act;
     long ws;
     gint i, nscreens;
 
@@ -423,13 +442,7 @@ initialize (gint compositor_mode, gboolean replace_wm)
 
     initModifiers (main_display_info->dpy);
 
-    act.sa_handler = handleSignal;
-    act.sa_flags = 0;
-    sigaction (SIGINT,  &act, NULL);
-    sigaction (SIGTERM, &act, NULL);
-    sigaction (SIGHUP,  &act, NULL);
-    sigaction (SIGUSR1, &act, NULL);
-    sigaction (SIGSEGV, &act, NULL);
+    setupHandler (TRUE);
 
     nscreens = gdk_display_get_n_screens (main_display_info->gdisplay);
     for(i = 0; i < nscreens; i++)


More information about the Xfce4-commits mailing list