Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
signals.c
Go to the documentation of this file.
1 /*
2  * signals.c
3  * Copyright 2009 John Lindgren
4  *
5  * This file is part of Audacious.
6  *
7  * Audacious is free software: you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License as published by the Free Software
9  * Foundation, version 2 or version 3 of the License.
10  *
11  * Audacious is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13  * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * Audacious. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * The Audacious team does not consider modular code linking to Audacious or
19  * using our public API to be a derived work.
20  */
21 
22 #include <signal.h>
23 #include <glib.h>
24 
25 #include <libaudcore/hook.h>
26 
27 #include "config.h"
28 #include "main.h"
29 
30 #ifdef HAVE_SIGWAIT
31 static sigset_t signal_set;
32 
33 static void * signal_thread (void * data)
34 {
35  int signal;
36 
37  while (! sigwait (& signal_set, & signal))
38  event_queue ("quit", NULL);
39 
40  return NULL;
41 }
42 #endif
43 
44 /* Must be called before any threads are created. */
45 void signals_init (void)
46 {
47 #ifdef HAVE_SIGWAIT
48  sigemptyset (& signal_set);
49  sigaddset (& signal_set, SIGHUP);
50  sigaddset (& signal_set, SIGINT);
51  sigaddset (& signal_set, SIGQUIT);
52  sigaddset (& signal_set, SIGTERM);
53 
54  sigprocmask (SIG_BLOCK, & signal_set, NULL);
55  g_thread_create (signal_thread, NULL, FALSE, NULL);
56 #endif
57 }