annotate audacious/signals.c @ 2161:c12319817d7e trunk

[svn] - patch to add a scrolling voiceprint to the mini visualizer. Patch by: Troels Bang Jensen ([Marvin] on #audacious).
author nenolod
date Mon, 18 Dec 2006 08:44:33 -0800
parents a792aaee8e8e
children 4de6e7d138c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2156
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
1 /*
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
2 * Audacious
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
3 * Copyright (c) 2005-2007 Audacious development team
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
4 *
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
5 * BMP - Cross-platform multimedia player
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
6 * Copyright (C) 2003-2005 BMP development team.
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
7 *
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
10 * the Free Software Foundation; under version 2 of the License.
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
11 *
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
16 *
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
20 * 02110-1301, USA.
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
21 */
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
22
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
23 #include <glib.h>
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
24 #include <glib/gi18n.h>
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
25 #include <glib/gprintf.h>
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
26 #include <config.h>
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
27 #include <stdlib.h>
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
28 #include <unistd.h>
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
29 #include <sys/types.h>
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
30 #include <signal.h>
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
31
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
32 #include "signals.h"
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
33
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
34 typedef void (*SignalHandler) (gint);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
35
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
36 static SignalHandler
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
37 signal_install_handler_full (gint signal_number,
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
38 SignalHandler handler,
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
39 gint *signals_to_block,
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
40 gsize n_signals)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
41 {
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
42 struct sigaction action, old_action;
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
43 gsize i;
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
44
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
45 action.sa_handler = handler;
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
46 action.sa_flags = SA_RESTART;
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
47
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
48 sigemptyset (&action.sa_mask);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
49
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
50 for (i = 0; i < n_signals; i++)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
51 sigaddset (&action.sa_mask, signals_to_block[i]);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
52
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
53 if (sigaction (signal_number, &action, &old_action) == -1)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
54 {
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
55 g_message ("Failed to install handler for signal %d", signal_number);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
56 return NULL;
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
57 }
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
58
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
59 return old_action.sa_handler;
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
60 }
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
61
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
62 /*
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
63 * A version of signal() that works more reliably across different
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
64 * platforms. It:
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
65 * a. restarts interrupted system calls
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
66 * b. does not reset the handler
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
67 * c. blocks the same signal within the handler
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
68 *
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
69 * (adapted from Unix Network Programming Vol. 1)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
70 */
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
71 static SignalHandler
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
72 signal_install_handler (gint signal_number,
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
73 SignalHandler handler)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
74 {
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
75 return signal_install_handler_full (signal_number, handler, NULL, 0);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
76 }
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
77
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
78 static void
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
79 signal_empty_handler (gint signal_number)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
80 {
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
81 /* empty */
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
82 }
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
83
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
84 static void
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
85 sigsegv_handler (gint signal_number)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
86 {
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
87 #ifdef HANDLE_SIGSEGV
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
88 g_printerr(_("\nReceived SIGSEGV\n\n"
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
89 "This could be a bug in Audacious. If you don't know why this happened, "
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
90 "file a bug at http://bugs-meta.atheme.org/\n\n"));
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
91
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
92 exit (EXIT_FAILURE);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
93 #else
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
94 abort ();
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
95 #endif
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
96 }
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
97
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
98 static void
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
99 sigterm_handler (gint signal_number)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
100 {
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
101 mainwin_quit_cb();
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
102 }
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
103
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
104 void
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
105 signal_handlers_init (void)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
106 {
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
107 char *magic;
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
108 magic = getenv("AUD_ENSURE_BACKTRACE");
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
109
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
110 signal_install_handler (SIGPIPE, signal_empty_handler);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
111 signal_install_handler (SIGINT, sigterm_handler);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
112 signal_install_handler (SIGTERM, sigterm_handler);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
113
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
114 /* in particular environment (maybe with glibc 2.5), core file
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
115 through signal handler doesn't contain useful back trace. --yaz */
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
116 if (magic == NULL)
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
117 signal_install_handler(SIGSEGV, sigsegv_handler);
a792aaee8e8e [svn] - new signal handling which does not block (based on concept from BMP 0.9.8 that never got released)
nenolod
parents:
diff changeset
118 }