annotate src/audacious/signals.c @ 3015:02a62ac3d9c2 trunk

Handle metadata sources where there are no mimetype support yet implemented.
author William Pitcock <nenolod@atheme-project.org>
date Mon, 09 Jul 2007 05:17:21 -0500
parents 182aa34ae6c4
children 06858ea4b9d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
1 /*
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
2 * Audacious
2638
12a8681e144a [svn] - reassign copyright to yaz.
nenolod
parents: 2630
diff changeset
3 * Copyright (c) 2005-2007 Yoshiki Yazawa
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
4 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
7 * the Free Software Foundation; under version 2 of the License.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
8 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
12 * GNU General Public License for more details.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
13 *
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
17 * 02110-1301, USA.
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
18 */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
19
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
20 //#define _XOPEN_SOURCE
2666
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
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
23 #include <glib.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
24 #include <glib/gi18n.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
25 #include <glib/gprintf.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
26 #include <config.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
27 #include <stdlib.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
28 #include <unistd.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
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
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
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
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
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
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
38 #include "main.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
39 #include "ui_main.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
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
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
43 gint linuxthread_signal_number = 0;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
44
2661
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
45 static void
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
46 signal_process_segv(void)
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
47 {
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
48 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
49 "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
50 "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
51 "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
52 "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
53 "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
54 "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
55
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
56 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
57
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
58 #ifdef HAVE_EXECINFO_H
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
59 {
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
60 void *stack[20];
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
61 size_t size;
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
62 char **strings;
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
63 size_t i;
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
64
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
65 size = backtrace(stack, 20);
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
66 strings = backtrace_symbols(stack, 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 g_printerr("Stacktrace (%zd frames):\n", size);
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
69
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
70 for (i = 0; i < size; i++)
2785
182aa34ae6c4 [svn] - implement some audacious-remote functions.
yaz
parents: 2677
diff changeset
71 g_printerr(" %ld. %s\n", (long)i + 1, strings[i]);
2661
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_free(strings);
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 #else
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
76 g_printerr("Stacktrace was unavailable.\n");
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
77 #endif
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_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
80
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
81 g_critical("Received SIGSEGV -- Audacious has crashed.");
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
82
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
83 bmp_config_save();
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
84 abort();
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
85 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
86
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
87 static void *
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
88 signal_process_signals (void *data)
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
89 {
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
90 sigset_t waitset;
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
91 int sig;
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
92
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
93 sigemptyset(&waitset);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
94 sigaddset(&waitset, SIGPIPE);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
95 sigaddset(&waitset, SIGSEGV);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
96 sigaddset(&waitset, SIGINT);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
97 sigaddset(&waitset, SIGTERM);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
98
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
99 while(1) {
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
100 sigwait(&waitset, &sig);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
101
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
102 switch(sig){
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
103 case SIGPIPE:
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
104 /*
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
105 * do something.
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
106 */
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
107 break;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
108
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
109 case SIGSEGV:
2661
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
110 signal_process_segv();
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
111 break;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
112
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
113 case SIGINT:
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
114 g_print("Audacious has received SIGINT and is shutting down.\n");
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
115 mainwin_quit_cb();
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
116 break;
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
117
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
118 case SIGTERM:
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
119 g_print("Audacious has received SIGTERM and is shutting down.\n");
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
120 mainwin_quit_cb();
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
121 break;
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
122 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
123 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
124
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
125 return NULL; //dummy
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
126 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
127
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
128 /********************************************************************************/
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
129 /* for linuxthread */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
130 /********************************************************************************/
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
131
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
132 typedef void (*SignalHandler) (gint);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
133
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
134 static void *
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
135 signal_process_signals_linuxthread (void *data)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
136 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
137 while(1) {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
138 g_usleep(1000000);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
139
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
140 switch(linuxthread_signal_number){
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
141 case SIGPIPE:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
142 /*
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
143 * do something.
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
144 */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
145 linuxthread_signal_number = 0;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
146 break;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
147
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
148 case SIGSEGV:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
149 signal_process_segv();
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
150 break;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
151
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
152 case SIGINT:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
153 g_print("Audacious has received SIGINT and is shutting down.\n");
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
154 mainwin_quit_cb();
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
155 break;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
156
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
157 case SIGTERM:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
158 g_print("Audacious has received SIGTERM and is shutting down.\n");
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
159 mainwin_quit_cb();
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
160 break;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
161 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
162 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
163
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
164 return NULL; //dummy
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
165 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
166
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
167 static void
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
168 linuxthread_handler (gint signal_number)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
169 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
170 /* note: cannot manipulate mutex from signal handler */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
171 linuxthread_signal_number = signal_number;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
172 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
173
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
174 static SignalHandler
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
175 signal_install_handler_full (gint signal_number,
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
176 SignalHandler handler,
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
177 gint *signals_to_block,
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
178 gsize n_signals)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
179 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
180 struct sigaction action, old_action;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
181 gsize i;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
182
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
183 action.sa_handler = handler;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
184 action.sa_flags = SA_RESTART;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
185
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
186 sigemptyset (&action.sa_mask);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
187
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
188 for (i = 0; i < n_signals; i++)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
189 sigaddset (&action.sa_mask, signals_to_block[i]);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
190
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
191 if (sigaction (signal_number, &action, &old_action) == -1)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
192 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
193 g_message ("Failed to install handler for signal %d", signal_number);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
194 return NULL;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
195 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
196
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
197 return old_action.sa_handler;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
198 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
199
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
200 /*
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
201 * A version of signal() that works more reliably across different
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
202 * platforms. It:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
203 * a. restarts interrupted system calls
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
204 * b. does not reset the handler
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
205 * c. blocks the same signal within the handler
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
206 *
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
207 * (adapted from Unix Network Programming Vol. 1)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
208 */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
209 static SignalHandler
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
210 signal_install_handler (gint signal_number,
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
211 SignalHandler handler)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
212 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
213 return signal_install_handler_full (signal_number, handler, NULL, 0);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
214 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
215
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
216
2664
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
217 /* sets up blocking signals for pthreads.
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
218 * linuxthreads sucks and needs this to make sigwait(2) work
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
219 * 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
220 *
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
221 * 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
222 * 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
223 */
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
224 static void
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
225 signal_initialize_blockers(void)
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
226 {
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
227 sigset_t blockset;
2486
113f75c7b0ce [svn] - make SIGTERM handler always work.
yaz
parents: 2373
diff changeset
228
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
229 sigemptyset(&blockset);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
230 sigaddset(&blockset, SIGPIPE);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
231 sigaddset(&blockset, SIGSEGV);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
232 sigaddset(&blockset, SIGINT);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
233 sigaddset(&blockset, SIGTERM);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
234
2674
f3ee0b78150a [svn] - use pthread_sigmask(SIG_BLOCK, ...) instead of of SIG_SETMASK
nenolod
parents: 2666
diff changeset
235 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL))
2664
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
236 g_print("pthread_sigmask() failed.\n");
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
237 }
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
238
2666
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
239 static gboolean
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
240 signal_check_for_broken_impl(void)
2664
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
241 {
2666
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
242 #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
243 {
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
244 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
245 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
246
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
247 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
248 return TRUE;
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
249 }
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
250 #endif
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
251
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
252 return FALSE;
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
253 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
254
2666
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
255 void
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
256 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
257 {
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
258 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
259 {
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
260 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
261 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
262 }
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
263 else
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
264 {
2666
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
265 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
266 "Expect unusable crash reports.\n"));
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
267
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
268 /* install special handler which catches signals and forwards to the signal handling thread */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
269 signal_install_handler(SIGPIPE, linuxthread_handler);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
270 signal_install_handler(SIGSEGV, linuxthread_handler);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
271 signal_install_handler(SIGINT, linuxthread_handler);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
272 signal_install_handler(SIGTERM, linuxthread_handler);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
273
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
274 /* create handler thread */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
275 g_thread_create(signal_process_signals_linuxthread, NULL, FALSE, NULL);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
276
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
277 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
278 }