fix bug 4239, 'Preferences: Text Options Header Display modal is not modal' (sic)
[claws.git] / src / crash.c
index 401d859bc3373036dede79008e4b62b702ba94f8..52dc9f93810012417a5b0eaa848e6407ee92d63f 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2002 by the Claws Mail Team and Hiroyuki Yamamoto
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2002-2015 by the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifdef HAVE_CONFIG_H
 #      include <sys/utsname.h>
 #endif
 
-#if defined(__GNU_LIBRARY__)
+#if defined(__GNU_LIBRARY__) && !defined(__UCLIBC__)
 #      include <gnu/libc-version.h>
 #endif
 
-#ifdef SIGTERM
 #include "main.h"
-#endif
-#include "sylpheed.h"
+#include "claws.h"
 #include "crash.h"
-#include "utils.h"
+#include "file-utils.h"
 #include "filesel.h"
 #include "version.h"
 #include "prefs_common.h"
+#include "manage_window.h"
 
 /*
- * NOTE: the crash dialog is called when sylpheed is not 
+ * NOTE: the crash dialog is called when claws is not 
  * initialized, so do not assume settings are available.
  * for example, loading / creating pixmaps seems not 
  * to be possible.
@@ -82,7 +80,7 @@ static void            crash_cleanup_exit             (void);
 
 /***/
 
-static const gchar *DEBUG_SCRIPT = "bt\nkill\nq";
+static const gchar *DEBUG_SCRIPT = "thread all apply\nbt full\nkill\nq";
 
 /***/
 
@@ -183,10 +181,11 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
        GtkTextBuffer *buffer;
        GtkTextIter iter;
 
-       window1 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       window1 = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "crash");
        gtk_container_set_border_width(GTK_CONTAINER(window1), 5);
        gtk_window_set_title(GTK_WINDOW(window1), _("Claws Mail has crashed"));
        gtk_window_set_position(GTK_WINDOW(window1), GTK_WIN_POS_CENTER);
+       gtk_window_set_type_hint(GTK_WINDOW(window1), GDK_WINDOW_TYPE_HINT_DIALOG);
        gtk_window_set_modal(GTK_WINDOW(window1), TRUE);
        gtk_window_set_default_size(GTK_WINDOW(window1), 460, 272);
 
@@ -253,17 +252,17 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
        button3 = gtk_button_new_with_label(_("Close"));
        gtk_widget_show(button3);
        gtk_container_add(GTK_CONTAINER(hbuttonbox4), button3);
-       GTK_WIDGET_SET_FLAGS(button3, GTK_CAN_DEFAULT);
+       gtk_widget_set_can_default(button3, TRUE);
 
        button4 = gtk_button_new_with_label(_("Save..."));
        gtk_widget_show(button4);
        gtk_container_add(GTK_CONTAINER(hbuttonbox4), button4);
-       GTK_WIDGET_SET_FLAGS(button4, GTK_CAN_DEFAULT);
+       gtk_widget_set_can_default(button4, TRUE);
 
        button5 = gtk_button_new_with_label(_("Create bug report"));
        gtk_widget_show(button5);
        gtk_container_add(GTK_CONTAINER(hbuttonbox4), button5);
-       GTK_WIDGET_SET_FLAGS(button5, GTK_CAN_DEFAULT);
+       gtk_widget_set_can_default(button5, TRUE);
        
        g_signal_connect(G_OBJECT(window1), "delete_event",
                         G_CALLBACK(gtk_main_quit), NULL);
@@ -274,6 +273,8 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
        g_signal_connect(G_OBJECT(button5), "clicked",
                         G_CALLBACK(crash_create_bug_report), NULL);
 
+       MANAGE_WINDOW_SIGNALS_CONNECT(window1);
+
        gtk_widget_show(window1);
 
        gtk_main();
@@ -282,7 +283,7 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
 
 
 /*!
- *\brief       create debugger script file in sylpheed directory.
+ *\brief       create debugger script file in claws directory.
  *             all the other options (creating temp files) looked too 
  *             convoluted.
  */
@@ -290,7 +291,7 @@ static void crash_create_debugger_file(void)
 {
        gchar *filespec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, DEBUGGERRC, NULL);
        
-       str_write_to_file(DEBUG_SCRIPT, filespec);
+       str_write_to_file(DEBUG_SCRIPT, filespec, TRUE);
        g_free(filespec);
 }
 
@@ -302,14 +303,15 @@ static void crash_save_crash_log(GtkButton *button, const gchar *text)
        time_t timer;
        struct tm *lt;
        char buf[100];
+       struct tm buft;
        gchar *filename;
 
        timer = time(NULL);
-       lt = localtime(&timer);
+       lt = localtime_r(&timer, &buft);
        strftime(buf, sizeof buf, "claws-crash-log-%Y-%m-%d-%H-%M-%S.txt", lt);
        if (NULL != (filename = filesel_select_file_save(_("Save crash information"), buf))
        &&  *filename)
-               str_write_to_file(text, filename);
+               str_write_to_file(text, filename, TRUE);
        g_free(filename);       
 }
 
@@ -318,11 +320,11 @@ static void crash_save_crash_log(GtkButton *button, const gchar *text)
  */
 static void crash_create_bug_report(GtkButton *button, const gchar *data)
 {
-       open_uri(BUGZILLA_URI, prefs_common.uri_cmd);
+       open_uri(BUGZILLA_URI, prefs_common_get_uri_cmd());
 }
 
 /*!
- *\brief       launches debugger and attaches it to crashed sylpheed
+ *\brief       launches debugger and attaches it to crashed claws
  */
 static void crash_debug(unsigned long crash_pid, 
                        gchar *exe_image,
@@ -331,18 +333,23 @@ static void crash_debug(unsigned long crash_pid,
        int choutput[2];
        pid_t pid;
 
-       pipe(choutput);
+       if (pipe(choutput) == -1) {
+               g_print("can't pipe - error %s", g_strerror(errno));
+               return;
+       }
 
        if (0 == (pid = fork())) {
                char *argp[10];
                char **argptr = argp;
                gchar *filespec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, DEBUGGERRC, NULL);
 
-               setgid(getgid());
-               setuid(getuid());
+               if (setgid(getgid()) != 0)
+                       perror("setgid");
+               if (setuid(getuid()) != 0)
+                       perror("setuid");
 
                /*
-                * setup debugger to attach to crashed sylpheed
+                * setup debugger to attach to crashed claws
                 */
                *argptr++ = "gdb"; 
                *argptr++ = "--nw";
@@ -359,10 +366,11 @@ static void crash_debug(unsigned long crash_pid,
                 * redirect output to write end of pipe
                 */
                close(1);
-               dup(choutput[1]);
+               if (dup(choutput[1]) < 0)
+                       perror("dup");
                close(choutput[0]);
                if (-1 == execvp("gdb", argp)) 
-                       puts("error execvp\n");
+                       perror("execvp");
        } else {
                char buf[100];
                int r;
@@ -373,7 +381,7 @@ static void crash_debug(unsigned long crash_pid,
                 * make it non blocking
                 */
                if (-1 == fcntl(choutput[0], F_SETFL, O_NONBLOCK))
-                       puts("set to non blocking failed\n");
+                       g_print("set to non blocking failed\n");
 
                /*
                 * get the output
@@ -404,9 +412,6 @@ static void crash_debug(unsigned long crash_pid,
 static const gchar *get_compiled_in_features(void)
 {
        return g_strdup_printf("%s",
-#if USE_THREADS
-                  " gthread"
-#endif
 #if INET6
                   " IPv6"
 #endif
@@ -416,8 +421,8 @@ static const gchar *get_compiled_in_features(void)
 #if HAVE_LIBCOMPFACE
                   " compface"
 #endif
-#if USE_OPENSSL
-                  " OpenSSL"
+#if USE_GNUTLS
+                  " GnuTLS"
 #endif
 #if USE_LDAP
                   " LDAP"
@@ -425,15 +430,12 @@ static const gchar *get_compiled_in_features(void)
 #if USE_JPILOT
                   " JPilot"
 #endif
-#if USE_ASPELL
+#if USE_ENCHANT
                   " GNU/aspell"
 #endif
 #if HAVE_LIBETPAN
                   " libetpan"
 #endif
-#if USE_GNOMEPRINT
-                  " libgnomeprint"
-#endif
 #if HAVE_LIBSM
                   " libSM"
 #endif
@@ -447,7 +449,9 @@ static const gchar *get_compiled_in_features(void)
  */
 static const gchar *get_lib_version(void)
 {
-#if defined(__GNU_LIBRARY__)
+#if defined(__UCLIBC__)
+       return g_strdup_printf("uClibc %i.%i.%i", __UCLIBC_MAJOR__, __UCLIBC_MINOR__, __UCLIBC_SUBLEVEL__);
+#elif defined(__GNU_LIBRARY__)
        return g_strdup_printf("GNU libc %s", gnu_get_libc_version());
 #else
        return g_strdup(_("Unknown"));
@@ -478,11 +482,11 @@ static const gchar *get_operating_system(void)
 
 /*!
  *\brief       see if the crash dialog is allowed (because some
- *             developers may prefer to run claws-mail under gdb...)
+ *             developers may prefer to run Claws Mail under gdb...)
  */
 static gboolean is_crash_dialog_allowed(void)
 {
-       return !getenv("CLAWS_NO_CRASH");
+       return !g_getenv("CLAWS_NO_CRASH");
 }
 
 /*!
@@ -537,10 +541,14 @@ static void crash_handler(int sig)
                args[3] = buf;
                args[4] = NULL;
 
-               chdir(sylpheed_get_startup_dir());
-               setgid(getgid());
-               setuid(getuid());
+               if (chdir(claws_get_startup_dir()) != 0)
+                       FILE_OP_ERROR(claws_get_startup_dir(), "chdir");
+               if (setgid(getgid()) != 0)
+                       perror("setgid");
+               if (setuid(getuid()) != 0 )
+                       perror("setuid");
                execvp(argv0, args);
+               perror("execvp");
        } else {
                waitpid(pid, NULL, 0);
                crash_cleanup_exit();
@@ -556,9 +564,8 @@ static void crash_handler(int sig)
  */
 static void crash_cleanup_exit(void)
 {
-       extern gchar *get_socket_name(void);
-       const char *filename = get_socket_name();
-       g_unlink(filename);
+       const char *filename = claws_get_socket_name();
+       claws_unlink(filename);
 }
 
 #endif