Commit 1d589191 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix abortion if killing signals are re-used.

Of course, VLC has no bugs, so you never need to abort it that way,
so that this fixes nothing.
parent 14c5e914
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */ #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
# define LIBVLC_USE_PTHREAD 1 # define LIBVLC_USE_PTHREAD 1
# define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */
# include <pthread.h> # include <pthread.h>
# ifdef DEBUG # ifdef DEBUG
......
...@@ -27,31 +27,32 @@ ...@@ -27,31 +27,32 @@
#include "config.h" #include "config.h"
#include <vlc/vlc.h>
#include <stdio.h> /* fprintf() */ #include <stdio.h> /* fprintf() */
#include <stdlib.h> /* putenv(), strtol(), */ #include <stdlib.h> /* putenv(), strtol(), */
#ifdef HAVE_SIGNAL_H
# include <signal.h> /* SIGHUP, SIGINT, SIGKILL */
#endif
#ifdef HAVE_TIME_H
# include <time.h> /* time() */
#endif
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
#endif
#include <vlc/vlc.h>
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
extern void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenviron, extern void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenviron,
int expand_wildcards, int *startupinfo); int expand_wildcards, int *startupinfo);
#endif #else
/***************************************************************************** # include <signal.h>
* Local prototypes. # include <time.h>
*****************************************************************************/ # include <pthread.h>
#if !defined(WIN32) && !defined(UNDER_CE) # include <stdbool.h>
static void *SigHandler ( void *set );
static struct
{
bool flag;
pthread_mutex_t lock;
} live = { true, PTHREAD_MUTEX_INITIALIZER };
static void *SigHandler (void *set);
#endif #endif
/***************************************************************************** /*****************************************************************************
...@@ -171,17 +172,17 @@ int main( int i_argc, char *ppsz_argv[] ) ...@@ -171,17 +172,17 @@ int main( int i_argc, char *ppsz_argv[] )
i_ret = VLC_AddIntf( 0, NULL, VLC_TRUE, VLC_TRUE ); i_ret = VLC_AddIntf( 0, NULL, VLC_TRUE, VLC_TRUE );
#if !defined(WIN32) && !defined(UNDER_CE)
pthread_cancel (sigth);
pthread_join (sigth, NULL);
#endif
/* Finish the threads */ /* Finish the threads */
VLC_CleanUp( 0 ); VLC_CleanUp( 0 );
/* Destroy the libvlc structure */ /* Destroy the libvlc structure */
VLC_Destroy( 0 ); VLC_Destroy( 0 );
#if !defined(WIN32) && !defined(UNDER_CE)
pthread_cancel (sigth);
pthread_join (sigth, NULL);
#endif
return i_ret; return i_ret;
} }
...@@ -192,7 +193,7 @@ int main( int i_argc, char *ppsz_argv[] ) ...@@ -192,7 +193,7 @@ int main( int i_argc, char *ppsz_argv[] )
* This thread receives all handled signals synchronously. * This thread receives all handled signals synchronously.
* It tries to end the program in a clean way. * It tries to end the program in a clean way.
*****************************************************************************/ *****************************************************************************/
static void *SigHandler( void *data ) static void *SigHandler (void *data)
{ {
const sigset_t *set = (sigset_t *)data; const sigset_t *set = (sigset_t *)data;
time_t abort_time = 0; time_t abort_time = 0;
...@@ -208,23 +209,29 @@ static void *SigHandler( void *data ) ...@@ -208,23 +209,29 @@ static void *SigHandler( void *data )
* signals to a libvlc structure having been destroyed */ * signals to a libvlc structure having been destroyed */
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state); pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state);
if( !b_die ) if (!b_die)
{ {
b_die = VLC_TRUE; b_die = VLC_TRUE;
abort_time = time( NULL ); abort_time = time (NULL);
fprintf( stderr, "signal %d received, terminating vlc - do it " fprintf (stderr, "signal %d received, terminating vlc - do it "
"again in case it gets stuck\n", i_signal ); "again in case it gets stuck\n", i_signal);
/* Acknowledge the signal received */ /* Acknowledge the signal received */
VLC_Die( 0 ); pthread_mutex_lock (&live.lock);
if (live.flag)
{
VLC_Die (0);
live.flag = false;
}
pthread_mutex_unlock (&live.lock);
} }
else if( time( NULL ) > abort_time + 2 ) else if( time( NULL ) > abort_time + 2 )
{ {
/* If user asks again 1 or 2 seconds later, die badly */ /* If user asks again 1 or 2 seconds later, die badly */
pthread_sigmask (SIG_UNBLOCK, set, NULL); pthread_sigmask (SIG_UNBLOCK, set, NULL);
fprintf( stderr, "user insisted too much, dying badly\n" ); fprintf (stderr, "user insisted too much, dying badly\n");
abort(); abort ();
} }
pthread_setcancelstate (state, NULL); pthread_setcancelstate (state, NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment