annotate src/audacious/signals.c @ 2863:06858ea4b9d0 trunk

BSD relicensing (pass 4).
author William Pitcock <nenolod@atheme.org>
date Sat, 23 Jun 2007 22:41:35 -0500
parents 182aa34ae6c4
children 2f5e02538dfa
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 /*
2863
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
2 * audacious: Cross-platform multimedia player.
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
3 * signals.c: Signal handling.
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
4 *
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
5 * Copyright (c) 2005-2007 Audacious development team.
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
6 *
2863
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
7 * Redistribution and use in source and binary forms, with or without
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
8 * modification, are permitted provided that the following conditions are
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
9 * met:
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
10 *
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
11 * 1. Redistributions of source code must retain the above copyright notice,
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
12 * this list of conditions and the following disclaimer.
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
13 *
2863
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
14 * 2. Redistributions in binary form must reproduce the above copyright
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
15 * notice, this list of conditions and the following disclaimer in the
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
16 * documentation and/or other materials provided with the distribution.
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
17 *
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
18 * 3. The name of the author may not be used to endorse or promote products
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
19 * derived from this software without specific prior written permission.
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
20 *
2863
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
06858ea4b9d0 BSD relicensing (pass 4).
William Pitcock <nenolod@atheme.org>
parents: 2785
diff changeset
31 * POSSIBILITY OF SUCH DAMAGE.
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
32 */
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
33
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
34 //#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
35 #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
36
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
37 #include <glib.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
38 #include <glib/gi18n.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
39 #include <glib/gprintf.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
40 #include <config.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
41 #include <stdlib.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
42 #include <unistd.h>
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
43 #include <sys/types.h>
2674
f3ee0b78150a [svn] - use pthread_sigmask(SIG_BLOCK, ...) instead of of SIG_SETMASK
nenolod
parents: 2666
diff changeset
44 #include <pthread.h> /* for pthread_sigmask() */
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
45 #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
46 #include <strings.h>
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
47
2661
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
48 #ifdef HAVE_EXECINFO_H
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
49 # include <execinfo.h>
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
50 #endif
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
51
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
52 #include "main.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
53 #include "ui_main.h"
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
54 #include "signals.h"
2661
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
55 #include "build_stamp.h"
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
56
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
57 gint linuxthread_signal_number = 0;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
58
2661
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
59 static void
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
60 signal_process_segv(void)
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(_("\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
63 "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
64 "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
65 "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
66 "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
67 "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
68 "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
69
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
70 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
71
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
72 #ifdef HAVE_EXECINFO_H
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 void *stack[20];
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
75 size_t size;
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
76 char **strings;
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
77 size_t i;
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 size = backtrace(stack, 20);
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
80 strings = backtrace_symbols(stack, size);
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
81
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
82 g_printerr("Stacktrace (%zd frames):\n", size);
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
83
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
84 for (i = 0; i < size; i++)
2785
182aa34ae6c4 [svn] - implement some audacious-remote functions.
yaz
parents: 2677
diff changeset
85 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
86
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
87 g_free(strings);
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
88 }
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
89 #else
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
90 g_printerr("Stacktrace was unavailable.\n");
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
91 #endif
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
92
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
93 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
94
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
95 g_critical("Received SIGSEGV -- Audacious has crashed.");
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
96
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
97 bmp_config_save();
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
98 abort();
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
99 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
100
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
101 static void *
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
102 signal_process_signals (void *data)
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
103 {
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
104 sigset_t waitset;
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
105 int sig;
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 sigemptyset(&waitset);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
108 sigaddset(&waitset, SIGPIPE);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
109 sigaddset(&waitset, SIGSEGV);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
110 sigaddset(&waitset, SIGINT);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
111 sigaddset(&waitset, SIGTERM);
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 while(1) {
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
114 sigwait(&waitset, &sig);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
115
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
116 switch(sig){
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
117 case SIGPIPE:
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
118 /*
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
119 * do something.
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
120 */
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
121 break;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
122
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
123 case SIGSEGV:
2661
f6c7271df7de [svn] - use execinfo.h to provide more useful information about crashes
nenolod
parents: 2638
diff changeset
124 signal_process_segv();
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
125 break;
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
126
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
127 case SIGINT:
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
128 g_print("Audacious has received SIGINT and is shutting down.\n");
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
129 mainwin_quit_cb();
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
130 break;
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
131
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
132 case SIGTERM:
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
133 g_print("Audacious has received SIGTERM and is shutting down.\n");
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
134 mainwin_quit_cb();
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
135 break;
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
136 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
137 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
138
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
139 return NULL; //dummy
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
140 }
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
141
2677
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 /* for linuxthread */
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
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
146 typedef void (*SignalHandler) (gint);
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 static void *
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
149 signal_process_signals_linuxthread (void *data)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
150 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
151 while(1) {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
152 g_usleep(1000000);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
153
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
154 switch(linuxthread_signal_number){
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
155 case SIGPIPE:
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 * do something.
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
158 */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
159 linuxthread_signal_number = 0;
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 case SIGSEGV:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
163 signal_process_segv();
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
164 break;
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 case SIGINT:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
167 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
168 mainwin_quit_cb();
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
169 break;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
170
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
171 case SIGTERM:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
172 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
173 mainwin_quit_cb();
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
174 break;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
175 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
176 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
177
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
178 return NULL; //dummy
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
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
181 static void
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
182 linuxthread_handler (gint signal_number)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
183 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
184 /* note: cannot manipulate mutex from signal handler */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
185 linuxthread_signal_number = signal_number;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
186 }
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 static SignalHandler
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
189 signal_install_handler_full (gint signal_number,
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
190 SignalHandler handler,
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
191 gint *signals_to_block,
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
192 gsize n_signals)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
193 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
194 struct sigaction action, old_action;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
195 gsize i;
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 action.sa_handler = handler;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
198 action.sa_flags = SA_RESTART;
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 sigemptyset (&action.sa_mask);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
201
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
202 for (i = 0; i < n_signals; i++)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
203 sigaddset (&action.sa_mask, signals_to_block[i]);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
204
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
205 if (sigaction (signal_number, &action, &old_action) == -1)
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 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
208 return NULL;
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
209 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
210
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
211 return old_action.sa_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
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 * 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
216 * platforms. It:
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
217 * a. restarts interrupted system calls
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
218 * b. does not reset the handler
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
219 * c. blocks the same signal within the handler
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
220 *
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
221 * (adapted from Unix Network Programming Vol. 1)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
222 */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
223 static SignalHandler
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
224 signal_install_handler (gint signal_number,
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
225 SignalHandler handler)
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
226 {
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
227 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
228 }
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
229
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
230
2664
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
231 /* sets up blocking signals for pthreads.
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
232 * linuxthreads sucks and needs this to make sigwait(2) work
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
233 * 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
234 *
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
235 * 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
236 * 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
237 */
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
238 static void
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
239 signal_initialize_blockers(void)
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
240 {
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
241 sigset_t blockset;
2486
113f75c7b0ce [svn] - make SIGTERM handler always work.
yaz
parents: 2373
diff changeset
242
2629
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
243 sigemptyset(&blockset);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
244 sigaddset(&blockset, SIGPIPE);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
245 sigaddset(&blockset, SIGSEGV);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
246 sigaddset(&blockset, SIGINT);
021321cb5426 [svn] simplify and enhance signal handler:
yaz
parents: 2486
diff changeset
247 sigaddset(&blockset, SIGTERM);
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
248
2674
f3ee0b78150a [svn] - use pthread_sigmask(SIG_BLOCK, ...) instead of of SIG_SETMASK
nenolod
parents: 2666
diff changeset
249 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL))
2664
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
250 g_print("pthread_sigmask() failed.\n");
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
251 }
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
252
2666
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
253 static gboolean
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
254 signal_check_for_broken_impl(void)
2664
1d9c5db3341d [svn] - handle sigwait(2) brokenness on linuxthreads
nenolod
parents: 2661
diff changeset
255 {
2666
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
256 #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
257 {
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
258 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
259 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
260
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
261 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
262 return TRUE;
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
263 }
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
264 #endif
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
265
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
266 return FALSE;
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
267 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
268
2666
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
269 void
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
270 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
271 {
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
272 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
273 {
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
274 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
275 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
276 }
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
277 else
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
278 {
2666
78a8b3095274 [svn] - do not use the signal handler at all on linuxthreads and hope for the best
nenolod
parents: 2665
diff changeset
279 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
280 "Expect unusable crash reports.\n"));
2677
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
281
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
282 /* 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
283 signal_install_handler(SIGPIPE, linuxthread_handler);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
284 signal_install_handler(SIGSEGV, linuxthread_handler);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
285 signal_install_handler(SIGINT, linuxthread_handler);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
286 signal_install_handler(SIGTERM, linuxthread_handler);
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
287
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
288 /* create handler thread */
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
289 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
290
52785bdac597 [svn] - workaround for linuxthread's broken implementation of sigwait().
yaz
parents: 2674
diff changeset
291 }
2313
3149d4b1a9a9 [svn] - objective-make autodepend fixes
nenolod
parents:
diff changeset
292 }