1 /*****************************************************************************
2 * signals.c : signals handler module for vlc
3 *****************************************************************************
4 * Copyright (C) 2008 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
30 #include <vlc_plugin.h>
31 #include <vlc_interface.h>
33 static int Open (vlc_object_t *);
34 static void Close (vlc_object_t *);
35 static void Run (intf_thread_t *);
36 static void *SigThread (void *);
39 set_shortname (N_("Signals"));
40 set_category (CAT_INTERFACE);
41 set_subcategory (SUBCAT_INTERFACE_CONTROL);
42 set_description (N_("POSIX signals handling interface"));
43 set_capability ("interface", 0);
44 set_callbacks (Open, Close);
53 static int Open (vlc_object_t *obj)
55 intf_thread_t *intf = (intf_thread_t *)obj;
56 intf_sys_t *p_sys = malloc (sizeof (*p_sys));
64 if (pthread_create (&p_sys->thread, NULL, SigThread, obj))
75 static void Close (vlc_object_t *obj)
77 intf_thread_t *intf = (intf_thread_t *)obj;
78 intf_sys_t *p_sys = intf->p_sys;
80 pthread_cancel (p_sys->thread);
81 pthread_join (p_sys->thread, NULL);
85 static void *SigThread (void *data)
87 intf_thread_t *obj = data;
88 intf_sys_t *p_sys = obj->p_sys;
92 sigaddset (&set, SIGHUP);
93 sigaddset (&set, SIGINT);
94 sigaddset (&set, SIGQUIT);
95 sigaddset (&set, SIGTERM);
97 sigaddset (&set, SIGCHLD);
103 sigwait (&set, &signum);
105 vlc_object_lock (obj);
106 p_sys->signum = signum;
107 vlc_object_signal_unlocked (obj);
108 vlc_object_unlock (obj);
112 static void Run (intf_thread_t *obj)
114 intf_sys_t *p_sys = obj->p_sys;
116 vlc_object_lock (obj);
119 switch (p_sys->signum)
125 msg_Err (obj, "Caught %s signal, exiting...",
126 strsignal (p_sys->signum));
130 while (!vlc_object_wait (obj));
133 vlc_object_unlock (obj);
134 vlc_object_kill (obj->p_libvlc);