summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-05-23 14:04:21 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-05-23 14:04:21 +0200
commit734685586bfe193097defa77ca607b19b3f87f44 (patch)
treea187d8fe129f51bb33ca63442d82fad93fab1140 /main.c
parent39ce5b6e7b5829f2e3552f8a6cba49767478d2e8 (diff)
parent7149aa6e4e7cb1bd71d1a0cb41f48000d5416941 (diff)
Merge branch 'master' into i18n
Conflicts: main.c
Diffstat (limited to 'main.c')
-rw-r--r--main.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/main.c b/main.c
index 2887fc8a..0cae38ba 100644
--- a/main.c
+++ b/main.c
@@ -38,6 +38,7 @@
#include <sys/fcntl.h>
#include <sys/errno.h>
#include <signal.h>
+#include <execinfo.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
@@ -428,9 +429,40 @@ sigterm_handler (int sig) {
exit (0);
}
+void
+sigsegv_handler (int sig) {
+ fprintf (stderr, "Segmentation Fault\n");
+ int j, nptrs;
+#define SIZE 100
+ void *buffer[100];
+ char **strings;
+
+ nptrs = backtrace(buffer, SIZE);
+ printf("backtrace() returned %d addresses\n", nptrs);
+
+ /* The call
+ * backtrace_symbols_fd(buffer,
+ * nptrs,
+ * STDOUT_FILENO)
+ would produce similar output to the following: */
+
+ strings = backtrace_symbols(buffer, nptrs);
+ if (strings == NULL) {
+ perror("backtrace_symbols");
+ exit(EXIT_FAILURE);
+ }
+
+ for (j = 0; j < nptrs; j++)
+ printf("%s\n", strings[j]);
+
+ free(strings);
+ exit (0);
+}
+
int
main (int argc, char *argv[]) {
- setlocale (LC_ALL, "");
+ signal (SIGSEGV, sigsegv_handler);
+ setlocale (LC_ALL, "");
setlocale (LC_NUMERIC, "C");
#ifdef ENABLE_NLS
// fprintf (stderr, "enabling gettext support: package=" PACKAGE ", dir=" LOCALEDIR "...\n");