rewriting signal system

This commit is contained in:
Axel Kittenberger 2018-04-21 14:23:21 +02:00
parent 9b9ac5d675
commit e2be36a831
8 changed files with 135 additions and 26 deletions

3
.gitignore vendored
View File

@ -4,7 +4,6 @@
*.out
lsyncd
# cmake
AdditionalInfo.txt
@ -16,8 +15,8 @@ CMakeFiles/
cmake_install.cmake
install_manifest.txt
# generated C code
default.c
mantle.c
signames.c

View File

@ -108,7 +108,8 @@ check_logcat( const char *name )
|
| Returns true if OK.
*/
bool add_logcat( const char *name, int priority )
bool
add_logcat( const char *name, int priority )
{
struct logcat *lc;

View File

@ -371,8 +371,8 @@ main1( int argc, char *argv[] )
while( argp < argc )
{
lua_pushnumber( L, idx++ );
lua_pushstring( L, argv[ argp++ ] );
lua_pushnumber( L, idx++ );
lua_settable( L, -3 );
}
@ -400,6 +400,12 @@ main1( int argc, char *argv[] )
lua_pop( L, 2 );
}
signal_init( );
#ifdef WITH_INOTIFY
open_inotify( L );
#endif
// checks existence of the config file
if( lsyncd_config_file )
{
@ -437,7 +443,6 @@ main1( int argc, char *argv[] )
exit( -1 );
}
// loads the user enivornment
lua_getglobal( L, "userENV" );
lua_setupvalue( L, -2, 1 );
@ -453,12 +458,6 @@ main1( int argc, char *argv[] )
}
}
#ifdef WITH_INOTIFY
open_inotify( L );
#endif
signal_init( );
// runs initializations from mantle
// it will set the configuration and add watches
{

View File

@ -111,10 +111,10 @@ int callError;
| Returns (Lua stack) the pid on success, 0 on failure.
*/
static int
l_exec( lua_State *L )
l_exec( lua_State * L )
{
// the binary to call
const char *binary = luaL_checkstring(L, 1);
const char *binary = luaL_checkstring( L, 1 );
// number of arguments
int argc = lua_gettop( L ) - 1;
@ -352,7 +352,7 @@ l_realdir( lua_State *L )
{
luaL_Buffer b;
const char *rdir = luaL_checkstring(L, 1);
char *adir = get_realpath(rdir);
char *adir = get_realpath( rdir );
if( !adir )
{
@ -476,9 +476,7 @@ l_readdir( lua_State *L )
{
const char * dirname = luaL_checkstring( L, 1 );
DIR *d;
d = opendir( dirname );
DIR *d = opendir( dirname );
if( d == NULL )
{
@ -596,8 +594,7 @@ l_configure( lua_State *L )
free( settings.log_file );
}
settings.log_file =
s_strdup( file );
settings.log_file = s_strdup( file );
}
else if( !strcmp( command, "logfacility" ) )
{
@ -644,7 +641,7 @@ l_configure( lua_State *L )
/*
| The Lsnycd's core library.
*/
static const luaL_Reg corelib[] =
static const luaL_Reg corelib[ ] =
{
{ "configure", l_configure },
{ "exec", l_exec },
@ -653,8 +650,10 @@ static const luaL_Reg corelib[] =
{ "now", l_now },
{ "nonobserve_fd", l_nonobserve_fd },
{ "observe_fd", l_observe_fd },
// { "onsignal", l_onsignal },
{ "readdir", l_readdir },
{ "realdir", l_realdir },
{ "signames", l_signames },
{ "stackdump", l_stackdump },
{ "terminate", l_terminate },
{ NULL, NULL }

View File

@ -1,7 +1,9 @@
/*
| singal.c from Lsyncd -- the Live (Mirror) Syncing Demon
|
| Signal handling.
| Albeit this signal handling system at first seems to violate
| rentry rules things are evened out by sigmasks taking care
| only one signal at a time can enter the core.
|
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
@ -10,6 +12,26 @@
#include <stddef.h>
#include <signal.h>
#include <string.h>
#define LUA_USE_APICHECK 1
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "mem.h"
static volatile sig_atomic_t * queue;
static int queue_len;
static int queue_pos;
/*
| XXX
*/
static int *handlers;
static int handlers_len;
static int handlers_maxlen;
/*
@ -21,12 +43,16 @@ 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.
}
@ -53,6 +79,8 @@ signal_handler( int sig )
}
/*
| Initializes signal handling.
|
@ -62,6 +90,16 @@ signal_handler( int sig )
void
signal_init( )
{
queue_len = 5;
queue = s_malloc( queue_len * sizeof( sig_atomic_t ) );
queue_pos = 0;
handlers_maxlen = 5;
handlers_len = 0;
handlers = s_malloc( handlers_maxlen * sizeof( int * ) );
}
/*
sigset_t set;
sigemptyset( &set );
sigaddset( &set, SIGCHLD );
@ -72,4 +110,31 @@ signal_init( )
signal( SIGTERM, signal_handler );
signal( SIGINT, signal_handler );
}
*/
/*
| Forwards the result of psiginfo to mantle.
|
| Params on Lua stack:
|
| Returns on Lua stack:
| A table of all signalnames as keys and their signal number as value.
*/
int
l_signames( lua_State * L )
{
int i;
lua_newtable( L );
for( i = 0; i < NSIG; i++ )
{
lua_pushnumber( L, i );
lua_pushstring( L, strsignal( i ) );
lua_settable( L, -3 );
}
return 1;
}

View File

@ -18,4 +18,7 @@ extern volatile sig_atomic_t sigcode;
// Initializes signal handling.
extern void signal_init( );
// returns signal name/signums as table
int l_signames( lua_State * L );
#endif

View File

@ -375,11 +375,23 @@ end
--
-- Called from core on init or restart after user configuration.
--
-- firstTime:
-- true when Lsyncd startups the first time,
-- false on resets, due to HUP signal or monitor queue overflow.
--
function mci.initialize( firstTime )
function mci.initialize
(
firstTime -- true when Lsyncd startups the first time,
-- -- false on resets, due to HUP signal or monitor queue overflow.
)
do
local signames = core.signames( )
local signum = 0
signame = signames[ 0 ]
while signame ~= nil
do
print( 'SIG', signum, signame )
signum = signum + 1
signame = signames[ signum ]
end
end
-- Checks if user overwrote the settings function.
-- ( was Lsyncd <2.1 style )

31
signames.sh Executable file
View File

@ -0,0 +1,31 @@
##
# signames.sh from Lsyncd -- the Live (Mirror) Syncing Demon
#
# Creates a .c file for all signal names understood by the kill command
# on the system Lsyncd is being compiled for.
#
# License: GPLv2 (see COPYING) or any later version
# Authors: Axel Kittenberger <axkibe@gmail.com>
#
KILL=/bin/kill
if [ "$#" -ne 1 ];
then
echo >&2 "$0 needs excatly one argument -- the c file to create"
exit 1
fi
echo "/* This file is autogenerated by $0 querying `$KILL --version` */" > $1
echo "char const * const siglist[ ] =" >> $1
echo "{" >> $1
n=1
while name=`kill -l $n 2>/dev/null`;
do
echo -e "\t\"$name\"," >> $1
n=$((n+1))
done
echo -e "\tNULL," >> $1
echo "}" >> $1