XMMS2
signal_unix.c
Go to the documentation of this file.
1 /* XMMS2 - X Music Multiplexer System
2  * Copyright (C) 2003-2009 XMMS2 Team
3  *
4  * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  */
16 
17 
18 
19 
20 /** @file
21  * Takes care of unix-signals.
22  */
23 
24 
25 #include "xmmspriv/xmms_signal.h"
26 #include "xmms/xmms_log.h"
27 #include "xmms/xmms_object.h"
28 
29 #include <stdlib.h>
30 #include <string.h>
31 #include <signal.h>
32 #include <string.h>
33 #include <glib.h>
34 #include <unistd.h>
35 
36 static sigset_t osignals;
37 
38 static gpointer
39 sigwaiter (gpointer data)
40 {
41  xmms_object_t *obj = (xmms_object_t *) data;
43  sigset_t signals;
44  int caught;
45 
46  sigemptyset(&signals);
47  sigaddset (&signals, SIGINT);
48  sigaddset (&signals, SIGTERM);
49 
50  while (1337) {
51  sigwait (&signals, &caught);
52 
53  switch (caught){
54  case SIGINT:
55  case SIGTERM:
56  pthread_sigmask (SIG_UNBLOCK, &signals, NULL);
57 
58  xmms_log_info ("Bye!");
59 
61  memset (&arg, 0, sizeof (arg));
62  xmms_error_reset (&arg.error);
64  break;
65  }
66  }
67  return NULL;
68 }
69 
70 void
72 {
73  sigset_t signals;
74 
75  sigemptyset(&signals);
76 
77  sigaddset (&signals, SIGHUP);
78  sigaddset (&signals, SIGTERM);
79  sigaddset (&signals, SIGINT);
80  sigaddset (&signals, SIGPIPE);
81 
82  pthread_sigmask (SIG_BLOCK, &signals, &osignals);
83 }
84 
85 void
87 {
88  pthread_sigmask (SIG_SETMASK, &osignals, NULL);
89 }
90 
91 void
93 {
94  g_thread_create (sigwaiter, obj, FALSE, NULL);
95 }
void xmms_signal_block(void)
Definition: signal_dummy.c:27
void xmms_object_cmd_arg_init(xmms_object_cmd_arg_t *arg)
Initialize a command argument.
Definition: object.c:237
void xmms_signal_restore(void)
Definition: signal_dummy.c:32
void xmms_object_cmd_call(xmms_object_t *object, guint cmdid, xmms_object_cmd_arg_t *arg)
Call a command with argument.
Definition: object.c:339
#define xmms_log_info(fmt,...)
Definition: xmms_log.h:34
void xmms_signal_init(xmms_object_t *obj)
Definition: signal_dummy.c:37
xmms_error_t error
Definition: xmms_object.h:73