| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
#ifdef HAVE_CONFIG_H |
|---|
| 22 |
# include "config.h" |
|---|
| 23 |
#endif |
|---|
| 24 |
|
|---|
| 25 |
#include <signal.h> |
|---|
| 26 |
#include <time.h> |
|---|
| 27 |
|
|---|
| 28 |
#include <vlc_common.h> |
|---|
| 29 |
#include <vlc_plugin.h> |
|---|
| 30 |
#include <vlc_interface.h> |
|---|
| 31 |
|
|---|
| 32 |
static int Open (vlc_object_t *); |
|---|
| 33 |
static void Close (vlc_object_t *); |
|---|
| 34 |
static void *SigThread (void *); |
|---|
| 35 |
|
|---|
| 36 |
vlc_module_begin (); |
|---|
| 37 |
set_shortname (N_("Signals")); |
|---|
| 38 |
set_category (CAT_INTERFACE); |
|---|
| 39 |
set_subcategory (SUBCAT_INTERFACE_CONTROL); |
|---|
| 40 |
set_description (N_("POSIX signals handling interface")); |
|---|
| 41 |
set_capability ("interface", 0); |
|---|
| 42 |
set_callbacks (Open, Close); |
|---|
| 43 |
vlc_module_end (); |
|---|
| 44 |
|
|---|
| 45 |
struct intf_sys_t |
|---|
| 46 |
{ |
|---|
| 47 |
vlc_thread_t thread; |
|---|
| 48 |
}; |
|---|
| 49 |
|
|---|
| 50 |
static int Open (vlc_object_t *obj) |
|---|
| 51 |
{ |
|---|
| 52 |
intf_thread_t *intf = (intf_thread_t *)obj; |
|---|
| 53 |
intf_sys_t *p_sys = malloc (sizeof (*p_sys)); |
|---|
| 54 |
|
|---|
| 55 |
if (p_sys == NULL) |
|---|
| 56 |
return VLC_ENOMEM; |
|---|
| 57 |
|
|---|
| 58 |
intf->p_sys = p_sys; |
|---|
| 59 |
|
|---|
| 60 |
if (vlc_clone (&p_sys->thread, SigThread, obj, VLC_THREAD_PRIORITY_LOW)) |
|---|
| 61 |
{ |
|---|
| 62 |
free (p_sys); |
|---|
| 63 |
intf->p_sys = NULL; |
|---|
| 64 |
return VLC_ENOMEM; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
intf->pf_run = NULL; |
|---|
| 68 |
return 0; |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
static void Close (vlc_object_t *obj) |
|---|
| 72 |
{ |
|---|
| 73 |
intf_thread_t *intf = (intf_thread_t *)obj; |
|---|
| 74 |
intf_sys_t *p_sys = intf->p_sys; |
|---|
| 75 |
|
|---|
| 76 |
vlc_cancel (p_sys->thread); |
|---|
| 77 |
#ifdef __APPLE__ |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
pthread_kill (p_sys->thread, SIGQUIT); |
|---|
| 82 |
# endif |
|---|
| 83 |
vlc_join (p_sys->thread, NULL); |
|---|
| 84 |
free (p_sys); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
static void *SigThread (void *data) |
|---|
| 88 |
{ |
|---|
| 89 |
intf_thread_t *obj = data; |
|---|
| 90 |
sigset_t set; |
|---|
| 91 |
|
|---|
| 92 |
sigemptyset (&set); |
|---|
| 93 |
sigaddset (&set, SIGHUP); |
|---|
| 94 |
sigaddset (&set, SIGINT); |
|---|
| 95 |
sigaddset (&set, SIGQUIT); |
|---|
| 96 |
sigaddset (&set, SIGTERM); |
|---|
| 97 |
|
|---|
| 98 |
sigaddset (&set, SIGCHLD); |
|---|
| 99 |
|
|---|
| 100 |
for (;;) |
|---|
| 101 |
{ |
|---|
| 102 |
int signum; |
|---|
| 103 |
|
|---|
| 104 |
sigwait (&set, &signum); |
|---|
| 105 |
|
|---|
| 106 |
#ifdef __APPLE__ |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
vlc_testcancel(); |
|---|
| 110 |
#endif |
|---|
| 111 |
|
|---|
| 112 |
switch (signum) |
|---|
| 113 |
{ |
|---|
| 114 |
case SIGINT: |
|---|
| 115 |
case SIGHUP: |
|---|
| 116 |
case SIGTERM: |
|---|
| 117 |
case SIGQUIT: |
|---|
| 118 |
msg_Err (obj, "Caught %s signal, exiting...", |
|---|
| 119 |
strsignal (signum)); |
|---|
| 120 |
vlc_object_kill (obj->p_libvlc); |
|---|
| 121 |
break; |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|