lsyncd/core/signal.c
2018-04-01 19:35:35 +02:00

89 lines
1.4 KiB
C

/*
| singal.c from Lsyncd -- the Live (Mirror) Syncing Demon
|
|
| Signal handling.
|
|
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "lsyncd.h"
#include <signal.h>
//#define LUA_USE_APICHECK 1
//#include <lua.h>
//#include <lualib.h>
//#include <lauxlib.h>
//#include "log.h"
//#include "mem.h"
//#include "util.h"
//#include "pipe.h"
//#include "observe.h"
//#include "time.h"
/*
| Set by TERM or HUP signal handler
| telling Lsyncd should end or reset ASAP.
*/
volatile sig_atomic_t hup = 0;
volatile sig_atomic_t term = 0;
volatile sig_atomic_t sigcode = 0;
/*
| signal handler
*/
static void signal_child( int sig )
{
// Nothing!
// This signal handler is just installed so the kernel
// keeps finished child processes as zombies waiting to be reaped.
}
/*
| signal handler
*/
static void
signal_handler( int sig )
{
switch( sig )
{
case SIGTERM:
case SIGINT:
term = 1;
sigcode = sig;
return;
case SIGHUP:
hup = 1;
return;
}
}
/*
| Initializes signal handling.
|
| Listens to SIGCHLD, but blocks it until pselect( )
| opens the signal handler up.
*/
void
signal_init( )
{
sigset_t set;
sigemptyset( &set );
sigaddset( &set, SIGCHLD );
signal( SIGCHLD, signal_child );
sigprocmask( SIG_BLOCK, &set, NULL );
signal( SIGHUP, signal_handler );
signal( SIGTERM, signal_handler );
signal( SIGINT, signal_handler );
}