Audacious
$Id:Doxyfile42802007-03-2104:39:00Znenolod$
|
00001 /* 00002 * signals.c 00003 * Copyright 2009 John Lindgren 00004 * 00005 * This file is part of Audacious. 00006 * 00007 * Audacious is free software: you can redistribute it and/or modify it under 00008 * the terms of the GNU General Public License as published by the Free Software 00009 * Foundation, version 2 or version 3 of the License. 00010 * 00011 * Audacious is distributed in the hope that it will be useful, but WITHOUT ANY 00012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00013 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along with 00016 * Audacious. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 * The Audacious team does not consider modular code linking to Audacious or 00019 * using our public API to be a derived work. 00020 */ 00021 00022 #include <signal.h> 00023 #include <glib.h> 00024 #include <libaudcore/eventqueue.h> 00025 00026 #include "config.h" 00027 00028 #ifdef HAVE_SIGWAIT 00029 static sigset_t signal_set; 00030 00031 static void * signal_thread (void * data) 00032 { 00033 gint signal; 00034 00035 while (! sigwait (& signal_set, & signal)) 00036 event_queue ("quit", NULL); 00037 00038 return NULL; 00039 } 00040 #endif 00041 00042 /* Must be called before any threads are created. */ 00043 void signals_init (void) 00044 { 00045 #ifdef HAVE_SIGWAIT 00046 sigemptyset (& signal_set); 00047 sigaddset (& signal_set, SIGHUP); 00048 sigaddset (& signal_set, SIGINT); 00049 sigaddset (& signal_set, SIGQUIT); 00050 sigaddset (& signal_set, SIGTERM); 00051 00052 sigprocmask (SIG_BLOCK, & signal_set, NULL); 00053 g_thread_create (signal_thread, NULL, FALSE, NULL); 00054 #endif 00055 }