Cosmetic: use always g_getenv instead of getenv
[claws.git] / src / crash.c
index b98102eeeac01d98f55b4a76163930e0602678b4..386958127a9d257a61229ce930e0701032712dc2 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -42,7 +41,7 @@
 #      include <sys/utsname.h>
 #endif
 
-#if defined(__GNU_LIBRARY__)
+#if defined(__GNU_LIBRARY__) && !defined(__UCLIBC__)
 #      include <gnu/libc-version.h>
 #endif
 
@@ -53,6 +52,7 @@
 #include "filesel.h"
 #include "version.h"
 #include "prefs_common.h"
+#include "manage_window.h"
 
 /*
  * NOTE: the crash dialog is called when claws is not 
@@ -251,17 +251,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);
+       gtkut_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);
+       gtkut_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);
+       gtkut_widget_set_can_default(button5, TRUE);
        
        g_signal_connect(G_OBJECT(window1), "delete_event",
                         G_CALLBACK(gtk_main_quit), NULL);
@@ -272,6 +272,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();
@@ -330,15 +332,20 @@ 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 claws
@@ -358,7 +365,8 @@ 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)) 
                        g_print("error execvp\n");
@@ -403,9 +411,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
@@ -430,9 +435,6 @@ static const gchar *get_compiled_in_features(void)
 #if HAVE_LIBETPAN
                   " libetpan"
 #endif
-#if USE_GNOMEPRINT
-                  " libgnomeprint"
-#endif
 #if HAVE_LIBSM
                   " libSM"
 #endif
@@ -446,7 +448,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"));
@@ -481,7 +485,7 @@ static const gchar *get_operating_system(void)
  */
 static gboolean is_crash_dialog_allowed(void)
 {
-       return !getenv("CLAWS_NO_CRASH");
+       return !g_getenv("CLAWS_NO_CRASH");
 }
 
 /*!
@@ -536,9 +540,12 @@ static void crash_handler(int sig)
                args[3] = buf;
                args[4] = NULL;
 
-               chdir(claws_get_startup_dir());
-               setgid(getgid());
-               setuid(getuid());
+               if (chdir(claws_get_startup_dir()) != 0)
+                       perror("chdir");
+               if (setgid(getgid()) != 0)
+                       perror("setgid");
+               if (setuid(getuid()) != 0 )
+                       perror("setuid");
                execvp(argv0, args);
        } else {
                waitpid(pid, NULL, 0);