mirror of https://github.com/octoleo/lsyncd.git
structering the core some more
This commit is contained in:
parent
4af469854e
commit
c2d9fec1a7
53
core/core.c
53
core/core.c
|
@ -20,7 +20,6 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -43,6 +42,7 @@
|
|||
#include "pipe.h"
|
||||
#include "observe.h"
|
||||
#include "time.h"
|
||||
#include "signal.h"
|
||||
|
||||
#ifdef WITH_INOTIFY
|
||||
#include "inotify.h"
|
||||
|
@ -114,48 +114,12 @@ char * lsyncd_config_file = NULL;
|
|||
bool first_time = true;
|
||||
|
||||
|
||||
/*
|
||||
| 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;
|
||||
|
||||
|
||||
/*
|
||||
| The kernel's clock ticks per second.
|
||||
*/
|
||||
extern long clocks_per_sec;
|
||||
|
||||
|
||||
/*
|
||||
| signal handler
|
||||
*/
|
||||
void sig_child( int sig ) { /* nothing */ }
|
||||
|
||||
|
||||
/*
|
||||
| signal handler
|
||||
*/
|
||||
void
|
||||
sig_handler( int sig )
|
||||
{
|
||||
switch( sig )
|
||||
{
|
||||
case SIGTERM:
|
||||
case SIGINT:
|
||||
term = 1;
|
||||
sigcode = sig;
|
||||
return;
|
||||
|
||||
case SIGHUP:
|
||||
hup = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*:::::::::::::::::::.
|
||||
:: Helper Routines
|
||||
'::::::::::::::::::::*/
|
||||
|
@ -1500,20 +1464,7 @@ main1( int argc, char *argv[] )
|
|||
open_inotify( L );
|
||||
#endif
|
||||
|
||||
// adds signal handlers
|
||||
// listens to SIGCHLD, but blocks it until pselect( )
|
||||
// opens the signal handler up
|
||||
{
|
||||
sigset_t set;
|
||||
sigemptyset( &set );
|
||||
sigaddset( &set, SIGCHLD );
|
||||
signal( SIGCHLD, sig_child );
|
||||
sigprocmask( SIG_BLOCK, &set, NULL );
|
||||
|
||||
signal( SIGHUP, sig_handler );
|
||||
signal( SIGTERM, sig_handler );
|
||||
signal( SIGINT, sig_handler );
|
||||
}
|
||||
signal_init( );
|
||||
|
||||
// runs initializations from mantle
|
||||
// it will set the configuration and add watches
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <sys/inotify.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -26,6 +27,7 @@
|
|||
#include "log.h"
|
||||
#include "inotify.h"
|
||||
#include "observe.h"
|
||||
#include "signal.h"
|
||||
#include "time.h"
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
// includes needed for headerfile
|
||||
#include "config.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -61,9 +60,5 @@ extern struct settings {
|
|||
// Pushes a runner function and the runner error handler onto Lua stack
|
||||
extern void load_mci(lua_State *L, const char *name);
|
||||
|
||||
// set to 1 on hup signal or term signal
|
||||
extern volatile sig_atomic_t hup;
|
||||
extern volatile sig_atomic_t term;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "lsyncd.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LUA_USE_APICHECK 1
|
||||
|
@ -19,6 +20,7 @@
|
|||
#include <lauxlib.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "signal.h"
|
||||
#include "mem.h"
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
| 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 );
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
| signal.h from Lsyncd -- the Live (Mirror) Syncing Demon
|
||||
|
|
||||
|
|
||||
| Logging.
|
||||
|
|
||||
|
|
||||
| License: GPLv2 (see COPYING) or any later version
|
||||
| Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||
*/
|
||||
#ifndef LSYNCD_SIGNAL_H
|
||||
#define LSYNCD_SIGNAL_H
|
||||
|
||||
// set to 1 on hup signal or term signal
|
||||
extern volatile sig_atomic_t hup;
|
||||
extern volatile sig_atomic_t term;
|
||||
extern volatile sig_atomic_t sigcode;
|
||||
|
||||
|
||||
// Initializes signal handling.
|
||||
extern void signal_init( );
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue