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  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions, and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions, and the following disclaimer in the documentation
13  * provided with the distribution.
14  *
15  * This software is provided "as is" and without any warranty, express or
16  * implied. In no event shall the authors be liable for any damages arising from
17  * the use of this software.
18  */
19 
20 #include <pthread.h>
21 #include <signal.h>
22 
23 #include <libaudcore/hook.h>
24 
25 #include "main.h"
26 
27 #ifdef HAVE_SIGWAIT
28 static sigset_t signal_set;
29 
30 static void * signal_thread (void * data)
31 {
32  int signal;
33 
34  while (! sigwait (& signal_set, & signal))
35  event_queue ("quit", NULL);
36 
37  return NULL;
38 }
39 #endif
40 
41 /* Must be called before any threads are created. */
42 void signals_init (void)
43 {
44 #ifdef HAVE_SIGWAIT
45  sigemptyset (& signal_set);
46  sigaddset (& signal_set, SIGHUP);
47  sigaddset (& signal_set, SIGINT);
48  sigaddset (& signal_set, SIGQUIT);
49  sigaddset (& signal_set, SIGTERM);
50 
51  sigprocmask (SIG_BLOCK, & signal_set, NULL);
52 
53  pthread_t thread;
54  pthread_create (& thread, NULL, signal_thread, NULL);
55 #endif
56 }
#define NULL
Definition: core.h:27
#define event_queue(n, d)
Definition: hook.h:44
void signals_init(void)
Definition: signals.c:42