Commit 39eb5768 authored by Benoit Steiner's avatar Benoit Steiner

Fixe la gestion des signaux
parent 53c2e3ac
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <string.h> /* strerror() */ #include <string.h> /* strerror() */
#include "config.h" #include "config.h"
#include "debug.h"
#include "common.h" #include "common.h"
#include "threads.h" #include "threads.h"
#include "mtime.h" #include "mtime.h"
...@@ -159,7 +160,8 @@ static void Usage ( int i_fashion ); ...@@ -159,7 +160,8 @@ static void Usage ( int i_fashion );
static void Version ( void ); static void Version ( void );
static void InitSignalHandler ( void ); static void InitSignalHandler ( void );
static void SignalHandler ( int i_signal ); static void SimpleSignalHandler ( int i_signal );
static void FatalSignalHandler ( int i_signal );
#ifdef HAVE_MMX #ifdef HAVE_MMX
int TestMMX ( void ); int TestMMX ( void );
#endif #endif
...@@ -210,6 +212,11 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] ) ...@@ -210,6 +212,11 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
return( errno ); return( errno );
} }
/*
* Set signal handling policy up for all the threads that will be created
*/
InitSignalHandler(); /* prepare signals for interception */
/* /*
* Read configuration * Read configuration
*/ */
...@@ -278,8 +285,6 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] ) ...@@ -278,8 +285,6 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
p_main->p_intf = intf_Create(); p_main->p_intf = intf_Create();
if( p_main->p_intf != NULL ) if( p_main->p_intf != NULL )
{ {
InitSignalHandler(); /* prepare signals for interception */
/* /*
* This is the main loop * This is the main loop
*/ */
...@@ -721,18 +726,35 @@ static void Version( void ) ...@@ -721,18 +726,35 @@ static void Version( void )
static void InitSignalHandler( void ) static void InitSignalHandler( void )
{ {
/* Termination signals */ /* Termination signals */
signal( SIGHUP, SignalHandler ); signal( SIGHUP, FatalSignalHandler );
signal( SIGINT, SignalHandler ); signal( SIGINT, FatalSignalHandler );
signal( SIGQUIT, SignalHandler ); signal( SIGQUIT, FatalSignalHandler );
/* Other signals */
signal( SIGALRM, SimpleSignalHandler );
signal( SIGPIPE, SimpleSignalHandler );
}
/*****************************************************************************
* SimpleSignalHandler: system signal handler
*****************************************************************************
* This function is called when a non fatal signal is received by the program.
*****************************************************************************/
static void SimpleSignalHandler( int i_signal )
{
/* Acknowledge the signal received */
intf_WarnMsg(0, "intf: ignoring signal %d\n", i_signal );
} }
/***************************************************************************** /*****************************************************************************
* SignalHandler: system signal handler * FatalSignalHandler: system signal handler
***************************************************************************** *****************************************************************************
* This function is called when a signal is received by the program. It tries to * This function is called when a fatal signal is received by the program.
* end the program in a clean way. * It tries to end the program in a clean way.
*****************************************************************************/ *****************************************************************************/
static void SignalHandler( int i_signal ) static void FatalSignalHandler( int i_signal )
{ {
/* Once a signal has been trapped, the termination sequence will be armed and /* Once a signal has been trapped, the termination sequence will be armed and
* following signals will be ignored to avoid sending messages to an interface * following signals will be ignored to avoid sending messages to an interface
...@@ -742,7 +764,7 @@ static void SignalHandler( int i_signal ) ...@@ -742,7 +764,7 @@ static void SignalHandler( int i_signal )
signal( SIGQUIT, SIG_IGN ); signal( SIGQUIT, SIG_IGN );
/* Acknowledge the signal received */ /* Acknowledge the signal received */
intf_ErrMsgImm("intf: signal %d received\n", i_signal ); intf_ErrMsgImm("intf: signal %d received, exiting\n", i_signal );
/* Try to terminate everything - this is done by requesting the end of the /* Try to terminate everything - this is done by requesting the end of the
* interface thread */ * interface thread */
......
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