[Xfce4-commits] <midori:master> Handle crash recognition in MidoriApp

Christian Dywan noreply at xfce.org
Sun Nov 25 16:44:02 CET 2012


Updating branch refs/heads/master
         to df5a4cf946876646095856d9d7618ce9353098b3 (commit)
       from 6d3c1106f1c3507935e2317f6eae6c891372ad49 (commit)

commit df5a4cf946876646095856d9d7618ce9353098b3
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Nov 25 16:39:00 2012 +0100

    Handle crash recognition in MidoriApp

 midori/main.c       |   48 ++----------------------------------------
 midori/midori-app.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 midori/midori-app.h |    3 ++
 3 files changed, 63 insertions(+), 45 deletions(-)

diff --git a/midori/main.c b/midori/main.c
index 8b47099..c68f18d 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -43,10 +43,6 @@
     #include <libsoup/soup-cache.h>
 #endif
 
-#ifdef HAVE_SIGNAL_H
-    #include <signal.h>
-#endif
-
 static void
 settings_notify_cb (MidoriWebSettings* settings,
                     GParamSpec*        pspec,
@@ -195,12 +191,7 @@ static void
 midori_app_quit_cb (MidoriBrowser* browser,
                     KatzeArray*    session)
 {
-    gchar* config_file = midori_paths_get_config_filename_for_writing ("running");
-    g_unlink (config_file);
-    g_free (config_file);
-
-    if (session)
-        midori_session_save_timeout_cb (session);
+    midori_session_save_timeout_cb (session);
 }
 
 static void
@@ -821,18 +812,6 @@ midori_web_app_browser_new_window_cb (MidoriBrowser* browser,
     return new_browser;
 }
 
-#ifdef HAVE_SIGNAL_H
-static void
-signal_handler (int signal_id)
-{
-    signal (signal_id, 0);
-    if (!midori_paths_is_readonly ())
-        midori_app_quit_cb (NULL, NULL);
-    if (kill (getpid (), signal_id))
-      exit (1);
-}
-#endif
-
 int
 main (int    argc,
       char** argv)
@@ -1082,21 +1061,6 @@ main (int    argc,
         return 0;
     }
 
-    #ifdef HAVE_SIGNAL_H
-    #ifdef SIGHUP
-    signal (SIGHUP, &signal_handler);
-    #endif
-    #ifdef SIGINT
-    signal (SIGINT, &signal_handler);
-    #endif
-    #ifdef SIGTERM
-    signal (SIGTERM, &signal_handler);
-    #endif
-    #ifdef SIGQUIT
-    signal (SIGQUIT, &signal_handler);
-    #endif
-    #endif
-
     midori_private_data_register_built_ins ();
 
     if (private)
@@ -1428,15 +1392,9 @@ main (int    argc,
 
     katze_item_set_parent (KATZE_ITEM (_session), app);
     g_object_set_data_full (G_OBJECT (app), "extensions", extensions, (GDestroyNotify)g_strfreev);
-    /* We test for the presence of a dummy file which is created once
-       and deleted during normal runtime, but persists in case of a crash. */
-    katze_assign (config_file, g_build_filename (config, "running", NULL));
-    if (g_access (config_file, F_OK) == 0)
-        back_from_crash = TRUE;
-    else
-        g_file_set_contents (config_file, "RUNNING", -1, NULL);
 
-    if (back_from_crash
+
+    if (midori_app_get_crashed (app)
      && katze_object_get_boolean (settings, "show-crash-dialog")
      && !katze_array_is_empty (_session))
         diagnostic_dialog = TRUE;
diff --git a/midori/midori-app.c b/midori/midori-app.c
index 326dc26..b49f43c 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -66,6 +66,10 @@
     #endif
 #endif
 
+#ifdef HAVE_SIGNAL_H
+    #include <signal.h>
+#endif
+
 struct _MidoriApp
 {
     GObject parent_instance;
@@ -264,9 +268,28 @@ _midori_app_add_browser (MidoriApp*     app,
     #endif
 }
 
+#ifdef HAVE_SIGNAL_H
+static MidoriApp* app_singleton;
+static void
+midori_app_signal_handler (int signal_id)
+{
+    signal (signal_id, 0);
+    if (!midori_paths_is_readonly ())
+        midori_app_quit (app_singleton);
+    if (kill (getpid (), signal_id))
+      exit (1);
+}
+#endif
+
 static void
 _midori_app_quit (MidoriApp* app)
 {
+    if (!midori_paths_is_readonly ())
+    {
+        gchar* config_file = midori_paths_get_config_filename_for_writing ("running");
+        g_unlink (config_file);
+        g_free (config_file);
+    }
     gtk_main_quit ();
 }
 
@@ -793,9 +816,43 @@ midori_app_get_name (MidoriApp* app)
     return app_name;
 }
 
+gboolean
+midori_app_get_crashed (MidoriApp* app)
+{
+    if (!midori_paths_is_readonly ())
+    {
+        /* We test for the presence of a dummy file which is created once
+           and deleted during normal runtime, but persists in case of a crash. */
+        gchar* config_file = midori_paths_get_config_filename_for_writing ("running");
+        gboolean crashed = (g_access (config_file, F_OK) == 0);
+        g_free (config_file);
+        if (crashed)
+            return TRUE;
+        g_file_set_contents (config_file, "RUNNING", -1, NULL);
+    }
+
+    return FALSE;
+}
+
 static void
 midori_app_init (MidoriApp* app)
 {
+    #ifdef HAVE_SIGNAL_H
+    app_singleton = app;
+    #ifdef SIGHUP
+    signal (SIGHUP, &midori_app_signal_handler);
+    #endif
+    #ifdef SIGINT
+    signal (SIGINT, &midori_app_signal_handler);
+    #endif
+    #ifdef SIGTERM
+    signal (SIGTERM, &midori_app_signal_handler);
+    #endif
+    #ifdef SIGQUIT
+    signal (SIGQUIT, &midori_app_signal_handler);
+    #endif
+    #endif
+
     app->settings = NULL;
     app->bookmarks = NULL;
     app->trash = NULL;
diff --git a/midori/midori-app.h b/midori/midori-app.h
index 7a35175..b63034d 100644
--- a/midori/midori-app.h
+++ b/midori/midori-app.h
@@ -45,6 +45,9 @@ const gchar*
 midori_app_get_name               (MidoriApp*         app);
 
 gboolean
+midori_app_get_crashed            (MidoriApp*         app);
+
+gboolean
 midori_app_instance_is_running    (MidoriApp*         app);
 
 gboolean


More information about the Xfce4-commits mailing list