Mercurial > audlegacy
annotate src/audacious/signals.c @ 2664:1d9c5db3341d trunk
[svn] - handle sigwait(2) brokenness on linuxthreads
author | nenolod |
---|---|
date | Tue, 10 Apr 2007 08:39:56 -0700 |
parents | f6c7271df7de |
children | 9b08d6cc7e81 |
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> | |
28 | |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
29 #ifdef HAVE_EXECINFO_H |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
30 # include <execinfo.h> |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
31 #endif |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
32 |
2313 | 33 #include "main.h" |
34 #include "ui_main.h" | |
35 #include "signals.h" | |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
36 #include "build_stamp.h" |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
37 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
38 static void |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
39 signal_process_segv(void) |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
40 { |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
41 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
|
42 "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
|
43 "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
|
44 "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
|
45 "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
|
46 "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
|
47 "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
|
48 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
49 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
|
50 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
51 #ifdef HAVE_EXECINFO_H |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
52 { |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
53 void *stack[20]; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
54 size_t size; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
55 char **strings; |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
56 size_t i; |
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 size = backtrace(stack, 20); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
59 strings = backtrace_symbols(stack, size); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
60 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
61 g_printerr("Stacktrace (%zd frames):\n", size); |
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 for (i = 0; i < size; i++) |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
64 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
|
65 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
66 g_free(strings); |
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 #else |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
69 g_printerr("Stacktrace was unavailable.\n"); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
70 #endif |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
71 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
72 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
|
73 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
74 g_critical("Received SIGSEGV -- Audacious has crashed."); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
75 |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
76 bmp_config_save(); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
77 abort(); |
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
78 } |
2313 | 79 |
2629 | 80 static void * |
81 signal_process_signals (void *data) | |
2313 | 82 { |
2629 | 83 sigset_t waitset; |
84 int sig; | |
85 | |
86 sigemptyset(&waitset); | |
87 sigaddset(&waitset, SIGPIPE); | |
88 sigaddset(&waitset, SIGSEGV); | |
89 sigaddset(&waitset, SIGINT); | |
90 sigaddset(&waitset, SIGTERM); | |
2313 | 91 |
2629 | 92 while(1) { |
93 sigwait(&waitset, &sig); | |
2313 | 94 |
2629 | 95 switch(sig){ |
96 case SIGPIPE: | |
97 /* | |
98 * do something. | |
99 */ | |
100 break; | |
2313 | 101 |
2629 | 102 case SIGSEGV: |
2661
f6c7271df7de
[svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents:
2638
diff
changeset
|
103 signal_process_segv(); |
2629 | 104 break; |
2313 | 105 |
2629 | 106 case SIGINT: |
107 g_print("Audacious has received SIGINT and is shutting down.\n"); | |
108 mainwin_quit_cb(); | |
109 break; | |
110 | |
111 case SIGTERM: | |
112 g_print("Audacious has received SIGTERM and is shutting down.\n"); | |
113 mainwin_quit_cb(); | |
114 break; | |
115 } | |
2313 | 116 } |
117 | |
2629 | 118 return NULL; //dummy |
2313 | 119 } |
120 | |
2664
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
121 /* sets up blocking signals for pthreads. |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
122 * linuxthreads sucks and needs this to make sigwait(2) work |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
123 * correctly. --nenolod |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
124 */ |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
125 static void |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
126 signal_initialize_blockers(void) |
2313 | 127 { |
2629 | 128 sigset_t blockset; |
2486 | 129 |
2629 | 130 sigemptyset(&blockset); |
131 sigaddset(&blockset, SIGPIPE); | |
132 sigaddset(&blockset, SIGSEGV); | |
133 sigaddset(&blockset, SIGINT); | |
134 sigaddset(&blockset, SIGTERM); | |
2313 | 135 |
2664
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
136 if(pthread_sigmask(SIG_SETMASK, &blockset, NULL)) |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
137 g_print("pthread_sigmask() failed.\n"); |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
138 } |
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 void |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
141 signal_handlers_init (void) |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
142 { |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
143 signal_initialize_blockers(); |
1d9c5db3341d
[svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents:
2661
diff
changeset
|
144 pthread_atfork(NULL, NULL, signal_initialize_blockers); |
2313 | 145 |
2629 | 146 g_thread_create(signal_process_signals, NULL, FALSE, NULL); |
2313 | 147 } |