2313
|
1 /*
|
|
2 * Audacious
|
2638
|
3 * Copyright (c) 2005-2007 Yoshiki Yazawa
|
2313
|
4 *
|
|
5 * This program is free software; you can redistribute it and/or modify
|
|
6 * it under the terms of the GNU General Public License as published by
|
|
7 * the Free Software Foundation; under version 2 of the License.
|
|
8 *
|
|
9 * This program is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License
|
|
15 * along with this program; if not, write to the Free Software
|
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
17 * 02110-1301, USA.
|
|
18 */
|
|
19
|
|
20 #include <glib.h>
|
|
21 #include <glib/gi18n.h>
|
|
22 #include <glib/gprintf.h>
|
|
23 #include <config.h>
|
|
24 #include <stdlib.h>
|
|
25 #include <unistd.h>
|
|
26 #include <sys/types.h>
|
|
27 #include <signal.h>
|
|
28
|
|
29 #include "main.h"
|
|
30 #include "ui_main.h"
|
|
31 #include "signals.h"
|
|
32
|
2629
|
33 static void *
|
|
34 signal_process_signals (void *data)
|
2313
|
35 {
|
2629
|
36 sigset_t waitset;
|
|
37 int sig;
|
|
38
|
|
39 sigemptyset(&waitset);
|
|
40 sigaddset(&waitset, SIGPIPE);
|
|
41 sigaddset(&waitset, SIGSEGV);
|
|
42 sigaddset(&waitset, SIGINT);
|
|
43 sigaddset(&waitset, SIGTERM);
|
2313
|
44
|
2629
|
45 while(1) {
|
|
46 sigwait(&waitset, &sig);
|
2313
|
47
|
2629
|
48 switch(sig){
|
|
49 case SIGPIPE:
|
|
50 /*
|
|
51 * do something.
|
|
52 */
|
|
53 break;
|
2313
|
54
|
2629
|
55 case SIGSEGV:
|
|
56 g_printerr(_("\nReceived SIGSEGV\n\n"
|
|
57 "This could be a bug in Audacious. If you don't know why this happened, "
|
|
58 "file a bug at http://bugs-meta.atheme.org/\n\n"));
|
|
59 g_critical("Received SIGSEGV");
|
2630
|
60 bmp_config_save();
|
|
61 abort();
|
2629
|
62 break;
|
2313
|
63
|
2629
|
64 case SIGINT:
|
|
65 g_print("Audacious has received SIGINT and is shutting down.\n");
|
|
66 mainwin_quit_cb();
|
|
67 break;
|
|
68
|
|
69 case SIGTERM:
|
|
70 g_print("Audacious has received SIGTERM and is shutting down.\n");
|
|
71 mainwin_quit_cb();
|
|
72 break;
|
|
73 }
|
2313
|
74 }
|
|
75
|
2629
|
76 return NULL; //dummy
|
2313
|
77 }
|
|
78
|
|
79 void
|
|
80 signal_handlers_init (void)
|
|
81 {
|
2629
|
82 sigset_t blockset;
|
2486
|
83
|
2629
|
84 sigemptyset(&blockset);
|
|
85 sigaddset(&blockset, SIGPIPE);
|
|
86 sigaddset(&blockset, SIGSEGV);
|
|
87 sigaddset(&blockset, SIGINT);
|
|
88 sigaddset(&blockset, SIGTERM);
|
2313
|
89
|
2629
|
90 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL))
|
|
91 g_print("pthread_sigmask() failed.\n");
|
2313
|
92
|
2629
|
93 g_thread_create(signal_process_signals, NULL, FALSE, NULL);
|
2313
|
94 }
|