wmail: added signal-handler for SIGINT and SIGTERM.
This commit is contained in:
parent
a3ef21b122
commit
86a8f6f0a1
|
@ -101,4 +101,6 @@ extern config_t config;
|
||||||
// config manipulation functions
|
// config manipulation functions
|
||||||
void ReadConfigFile( bool resetConfigStrings );
|
void ReadConfigFile( bool resetConfigStrings );
|
||||||
|
|
||||||
|
void ResetConfigStrings( void );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -102,6 +102,7 @@ typedef enum {
|
||||||
// data
|
// data
|
||||||
|
|
||||||
static unsigned long lastTimeOut;
|
static unsigned long lastTimeOut;
|
||||||
|
static sig_atomic_t caughtSig;
|
||||||
mail_state_t state = STATE_NOMAIL;
|
mail_state_t state = STATE_NOMAIL;
|
||||||
int numMails = 0;
|
int numMails = 0;
|
||||||
bool namesChanged = false;
|
bool namesChanged = false;
|
||||||
|
@ -162,6 +163,7 @@ static DAProgramOption options[] = {
|
||||||
// prototypes
|
// prototypes
|
||||||
|
|
||||||
void PreparePixmaps( bool freeThemFirst );
|
void PreparePixmaps( bool freeThemFirst );
|
||||||
|
static void ExitHandler( int sig );
|
||||||
void TimedOut( void );
|
void TimedOut( void );
|
||||||
void CheckTimeOut( bool force );
|
void CheckTimeOut( bool force );
|
||||||
void CheckMBox( void );
|
void CheckMBox( void );
|
||||||
|
@ -201,6 +203,7 @@ bool HasTickerWork( void );
|
||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
char *usersHome;
|
char *usersHome;
|
||||||
|
struct sigaction sa = { .sa_handler = ExitHandler };
|
||||||
struct stat fileStat;
|
struct stat fileStat;
|
||||||
XTextProperty windowName;
|
XTextProperty windowName;
|
||||||
char *name = argv[0];
|
char *name = argv[0];
|
||||||
|
@ -213,7 +216,7 @@ int main( int argc, char **argv )
|
||||||
if( config.checksumFileName == NULL ) {
|
if( config.checksumFileName == NULL ) {
|
||||||
if(( usersHome = getenv( "HOME" )) == NULL ) {
|
if(( usersHome = getenv( "HOME" )) == NULL ) {
|
||||||
WARNING( "HOME environment-variable is not set, placing %s in current directory!\n", WMAIL_CHECKSUM_FILE );
|
WARNING( "HOME environment-variable is not set, placing %s in current directory!\n", WMAIL_CHECKSUM_FILE );
|
||||||
config.checksumFileName = WMAIL_CHECKSUM_FILE;
|
config.checksumFileName = strdup( WMAIL_CHECKSUM_FILE );
|
||||||
} else
|
} else
|
||||||
config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE );
|
config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE );
|
||||||
}
|
}
|
||||||
|
@ -291,6 +294,16 @@ int main( int argc, char **argv )
|
||||||
outPixmap = DAMakePixmap();
|
outPixmap = DAMakePixmap();
|
||||||
PreparePixmaps( false );
|
PreparePixmaps( false );
|
||||||
|
|
||||||
|
if( sigaction( SIGINT, &sa, NULL ) == -1 ) {
|
||||||
|
perror( "wmail error: sigaction" );
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( sigaction( SIGTERM, &sa, NULL ) == -1 ) {
|
||||||
|
perror( "wmail error: sigaction" );
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
|
}
|
||||||
|
|
||||||
DASetCallbacks( &callbacks );
|
DASetCallbacks( &callbacks );
|
||||||
DASetTimeout (1000 / config.fps);
|
DASetTimeout (1000 / config.fps);
|
||||||
|
|
||||||
|
@ -520,8 +533,19 @@ void RemoveChecksumFile( void )
|
||||||
remove( config.checksumFileName );
|
remove( config.checksumFileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ExitHandler( int sig )
|
||||||
|
{
|
||||||
|
caughtSig = 1;
|
||||||
|
}
|
||||||
|
|
||||||
void TimedOut( void )
|
void TimedOut( void )
|
||||||
{
|
{
|
||||||
|
if (caughtSig) {
|
||||||
|
ClearAllNames();
|
||||||
|
ResetConfigStrings();
|
||||||
|
exit( EXIT_SUCCESS );
|
||||||
|
}
|
||||||
|
|
||||||
CheckTimeOut( true );
|
CheckTimeOut( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue