Mercurial > audlegacy
annotate src/audacious/signals.c @ 2674:f3ee0b78150a trunk
[svn] - use pthread_sigmask(SIG_BLOCK, ...) instead of of SIG_SETMASK
author | nenolod |
---|---|
date | Tue, 10 Apr 2007 14:16:32 -0700 |
parents | 78a8b3095274 |
children | 52785bdac597 |
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 | |
2666
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
20 #define _XOPEN_SOURCE |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
21 #include <unistd.h> /* for signal_check_for_broken_impl() */ |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
22 |
2313 | 23 #include <glib.h> |
24 #include <glib/gi18n.h> | |
25 #include <glib/gprintf.h> | |
26 #include <config.h> | |
27 #include <stdlib.h> | |
28 #include <unistd.h> | |
29 #include <sys/types.h> | |
2674
f3ee0b78150a
[svn] - use pthread_sigmask(SIG_BLOCK, ...) instead of of SIG_SETMASK
nenolod
parents:
2666
diff
changeset
|
30 #include <pthread.h> /* for pthread_sigmask() */ |
2313 | 31 #include <signal.h> |
2666
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
32 #include <strings.h> |
2313 | 33 |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
34 #ifdef HAVE_EXECINFO_H |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
35 # include <execinfo.h> |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
36 #endif |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
37 |
2313 | 38 #include "main.h" |
39 #include "ui_main.h" | |
40 #include "signals.h" | |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
41 #include "build_stamp.h" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
42 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
43 static void |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
44 signal_process_segv(void) |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
45 { |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
46 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
|
47 "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
|
48 "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
|
49 "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
|
50 "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
|
51 "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
|
52 "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
|
53 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
54 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
|
55 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
56 #ifdef HAVE_EXECINFO_H |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
57 { |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
58 void *stack[20]; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
59 size_t size; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
60 char **strings; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
61 size_t i; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
62 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
63 size = backtrace(stack, 20); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
64 strings = backtrace_symbols(stack, size); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
65 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
66 g_printerr("Stacktrace (%zd frames):\n", size); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
67 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
68 for (i = 0; i < size; i++) |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
69 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
|
70 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
71 g_free(strings); |
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 #else |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
74 g_printerr("Stacktrace was unavailable.\n"); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
75 #endif |
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 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
|
78 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
79 g_critical("Received SIGSEGV -- Audacious has crashed."); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
80 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
81 bmp_config_save(); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
82 abort(); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
83 } |
2313 | 84 |
2629 | 85 static void * |
86 signal_process_signals (void *data) | |
2313 | 87 { |
2629 | 88 sigset_t waitset; |
89 int sig; | |
90 | |
91 sigemptyset(&waitset); | |
92 sigaddset(&waitset, SIGPIPE); | |
93 sigaddset(&waitset, SIGSEGV); | |
94 sigaddset(&waitset, SIGINT); | |
95 sigaddset(&waitset, SIGTERM); | |
2313 | 96 |
2629 | 97 while(1) { |
98 sigwait(&waitset, &sig); | |
2313 | 99 |
2629 | 100 switch(sig){ |
101 case SIGPIPE: | |
102 /* | |
103 * do something. | |
104 */ | |
105 break; | |
2313 | 106 |
2629 | 107 case SIGSEGV: |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
108 signal_process_segv(); |
2629 | 109 break; |
2313 | 110 |
2629 | 111 case SIGINT: |
112 g_print("Audacious has received SIGINT and is shutting down.\n"); | |
113 mainwin_quit_cb(); | |
114 break; | |
115 | |
116 case SIGTERM: | |
117 g_print("Audacious has received SIGTERM and is shutting down.\n"); | |
118 mainwin_quit_cb(); | |
119 break; | |
120 } | |
2313 | 121 } |
122 | |
2629 | 123 return NULL; //dummy |
2313 | 124 } |
125 | |
2664
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
126 /* sets up blocking signals for pthreads. |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
127 * linuxthreads sucks and needs this to make sigwait(2) work |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
128 * correctly. --nenolod |
2666
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
129 * |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
130 * correction -- this trick does not work on linuxthreads. |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
131 * going to keep it in it's own function though --nenolod |
2664
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
132 */ |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
133 static void |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
134 signal_initialize_blockers(void) |
2313 | 135 { |
2629 | 136 sigset_t blockset; |
2486 | 137 |
2629 | 138 sigemptyset(&blockset); |
139 sigaddset(&blockset, SIGPIPE); | |
140 sigaddset(&blockset, SIGSEGV); | |
141 sigaddset(&blockset, SIGINT); | |
142 sigaddset(&blockset, SIGTERM); | |
2313 | 143 |
2674
f3ee0b78150a
[svn] - use pthread_sigmask(SIG_BLOCK, ...) instead of of SIG_SETMASK
nenolod
parents:
2666
diff
changeset
|
144 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL)) |
2664
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
145 g_print("pthread_sigmask() failed.\n"); |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
146 } |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
147 |
2666
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
148 static gboolean |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
149 signal_check_for_broken_impl(void) |
2664
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
150 { |
2666
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
151 #ifdef _CS_GNU_LIBPTHREAD_VERSION |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
152 { |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
153 gchar str[1024]; |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
154 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, sizeof(str)); |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
155 |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
156 if (!strncasecmp("linuxthreads", str, 12)) |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
157 return TRUE; |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
158 } |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
159 #endif |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
160 |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
161 return FALSE; |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
162 } |
2313 | 163 |
2666
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
164 void |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
165 signal_handlers_init(void) |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
166 { |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
167 if (signal_check_for_broken_impl() != TRUE) |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
168 { |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
169 signal_initialize_blockers(); |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
170 g_thread_create(signal_process_signals, NULL, FALSE, NULL); |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
171 } |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
172 else |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
173 g_printerr(_("Your signaling implementation is broken.\n" |
78a8b3095274
[svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents:
2665
diff
changeset
|
174 "Expect unusable crash reports.\n")); |
2313 | 175 } |