Mercurial > audlegacy
annotate src/audacious/signals.c @ 2665:9b08d6cc7e81 trunk
[svn] - include missing header
author | nenolod |
---|---|
date | Tue, 10 Apr 2007 08:42:11 -0700 |
parents | 1d9c5db3341d |
children | 78a8b3095274 |
rev | line source |
---|---|
2313 | 1 /* |
2 * Audacious | |
2638 | 3 * Copyright (c) 2005-2007 Yoshiki Yazawa |
2313 | 4 * |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; under version 2 of the License. | |
8 * | |
9 * This program is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program; if not, write to the Free Software | |
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
17 * 02110-1301, USA. | |
18 */ | |
19 | |
20 #include <glib.h> | |
21 #include <glib/gi18n.h> | |
22 #include <glib/gprintf.h> | |
23 #include <config.h> | |
24 #include <stdlib.h> | |
25 #include <unistd.h> | |
26 #include <sys/types.h> | |
27 #include <signal.h> | |
2665 | 28 #include <pthread.h> |
2313 | 29 |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
30 #ifdef HAVE_EXECINFO_H |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
31 # include <execinfo.h> |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
32 #endif |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
33 |
2313 | 34 #include "main.h" |
35 #include "ui_main.h" | |
36 #include "signals.h" | |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
37 #include "build_stamp.h" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
38 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
39 static void |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
40 signal_process_segv(void) |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
41 { |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
42 g_printerr(_("\nAudacious has caught signal 11 (SIGSEGV).\n\n" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
43 "We apologize for the inconvenience, but Audacious has crashed.\n" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
44 "This is a bug in the program, and should never happen under normal circumstances.\n" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
45 "Your current configuration has been saved and should not be damaged.\n\n" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
46 "You can help improve the quality of Audacious by filing a bug at http://bugs-meta.atheme.org\n" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
47 "Please include the entire text of this message and a description of what you were doing when\n" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
48 "this crash occured in order to quickly expedite the handling of your bug report:\n\n")); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
49 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
50 g_printerr("Program version: Audacious %s (buildid: %s)\n\n", VERSION, svn_stamp); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
51 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
52 #ifdef HAVE_EXECINFO_H |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
53 { |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
54 void *stack[20]; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
55 size_t size; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
56 char **strings; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
57 size_t i; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
58 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
59 size = backtrace(stack, 20); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
60 strings = backtrace_symbols(stack, size); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
61 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
62 g_printerr("Stacktrace (%zd frames):\n", size); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
63 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
64 for (i = 0; i < size; i++) |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
65 g_printerr(" %d. %s\n", i + 1, strings[i]); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
66 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
67 g_free(strings); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
68 } |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
69 #else |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
70 g_printerr("Stacktrace was unavailable.\n"); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
71 #endif |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
72 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
73 g_printerr(_("\nBugs can be reported at http://bugs-meta.atheme.org against the Audacious product.\n")); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
74 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
75 g_critical("Received SIGSEGV -- Audacious has crashed."); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
76 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
77 bmp_config_save(); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
78 abort(); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
79 } |
2313 | 80 |
2629 | 81 static void * |
82 signal_process_signals (void *data) | |
2313 | 83 { |
2629 | 84 sigset_t waitset; |
85 int sig; | |
86 | |
87 sigemptyset(&waitset); | |
88 sigaddset(&waitset, SIGPIPE); | |
89 sigaddset(&waitset, SIGSEGV); | |
90 sigaddset(&waitset, SIGINT); | |
91 sigaddset(&waitset, SIGTERM); | |
2313 | 92 |
2629 | 93 while(1) { |
94 sigwait(&waitset, &sig); | |
2313 | 95 |
2629 | 96 switch(sig){ |
97 case SIGPIPE: | |
98 /* | |
99 * do something. | |
100 */ | |
101 break; | |
2313 | 102 |
2629 | 103 case SIGSEGV: |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
104 signal_process_segv(); |
2629 | 105 break; |
2313 | 106 |
2629 | 107 case SIGINT: |
108 g_print("Audacious has received SIGINT and is shutting down.\n"); | |
109 mainwin_quit_cb(); | |
110 break; | |
111 | |
112 case SIGTERM: | |
113 g_print("Audacious has received SIGTERM and is shutting down.\n"); | |
114 mainwin_quit_cb(); | |
115 break; | |
116 } | |
2313 | 117 } |
118 | |
2629 | 119 return NULL; //dummy |
2313 | 120 } |
121 | |
2664
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
122 /* sets up blocking signals for pthreads. |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
123 * linuxthreads sucks and needs this to make sigwait(2) work |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
124 * correctly. --nenolod |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
125 */ |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
126 static void |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
127 signal_initialize_blockers(void) |
2313 | 128 { |
2629 | 129 sigset_t blockset; |
2486 | 130 |
2629 | 131 sigemptyset(&blockset); |
132 sigaddset(&blockset, SIGPIPE); | |
133 sigaddset(&blockset, SIGSEGV); | |
134 sigaddset(&blockset, SIGINT); | |
135 sigaddset(&blockset, SIGTERM); | |
2313 | 136 |
2664
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
137 if(pthread_sigmask(SIG_SETMASK, &blockset, NULL)) |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
138 g_print("pthread_sigmask() failed.\n"); |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
139 } |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
140 |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
141 void |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
142 signal_handlers_init (void) |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
143 { |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
144 signal_initialize_blockers(); |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
145 pthread_atfork(NULL, NULL, signal_initialize_blockers); |
2313 | 146 |
2629 | 147 g_thread_create(signal_process_signals, NULL, FALSE, NULL); |
2313 | 148 } |