mirror of https://github.com/octoleo/lsyncd.git
reworking signal system
This commit is contained in:
parent
60e30a379c
commit
a9e609d60c
|
@ -4,6 +4,8 @@ cmake_minimum_required( VERSION 2.8 )
|
|||
set( LSYNCD_VERSION 3.0.0-devel )
|
||||
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/" )
|
||||
|
||||
# More Warnings
|
||||
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
|
||||
# Finding Lua
|
||||
find_package( Lua REQUIRED )
|
||||
|
|
|
@ -335,6 +335,8 @@ l_mci( lua_State *L )
|
|||
l_stackdump( L );
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -773,6 +775,7 @@ mci_load_default(
|
|||
{
|
||||
printlogf( L, "Error",
|
||||
"loading default sync implementations: %s", lua_tostring( L, -1 ) );
|
||||
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
|
@ -786,6 +789,7 @@ mci_load_default(
|
|||
{
|
||||
printlogf( L, "Error",
|
||||
"preparing default sync implementations: %s", lua_tostring( L, -1 ) );
|
||||
|
||||
exit( -1 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ observe_select
|
|||
timeout, &sigset
|
||||
);
|
||||
|
||||
// FIXME handle signals
|
||||
signal_notify( L );
|
||||
|
||||
// something happened!
|
||||
if( pr >= 0 )
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <lauxlib.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "mci.h"
|
||||
#include "mem.h"
|
||||
|
||||
|
||||
|
@ -59,6 +60,7 @@ volatile sig_atomic_t sigcode = 0;
|
|||
/*
|
||||
| signal handler
|
||||
*/
|
||||
/*
|
||||
static void
|
||||
signal_child( int sig )
|
||||
{
|
||||
|
@ -67,6 +69,7 @@ signal_child( int sig )
|
|||
// This signal handler is just installed so the kernel
|
||||
// keeps finished child processes as zombies waiting to be reaped.
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
@ -121,7 +124,9 @@ signal_init( )
|
|||
| false if they denied it
|
||||
*/
|
||||
int
|
||||
l_onsignal( lua_State *L )
|
||||
l_onsignal(
|
||||
lua_State *L
|
||||
)
|
||||
{
|
||||
int sigc = 0;
|
||||
int ok;
|
||||
|
@ -178,6 +183,8 @@ l_onsignal( lua_State *L )
|
|||
sigaction( signum, &act, NULL );
|
||||
}
|
||||
|
||||
handlers_len = 0;
|
||||
|
||||
// and now the signalmask is applied
|
||||
sigprocmask( SIG_BLOCK, &blockmask, NULL );
|
||||
|
||||
|
@ -230,3 +237,30 @@ l_onsignal( lua_State *L )
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
| Notifies the mantle about queued signals.
|
||||
*/
|
||||
void
|
||||
signal_notify(
|
||||
lua_State *L
|
||||
)
|
||||
{
|
||||
if( queue_pos == 0 ) return;
|
||||
|
||||
load_mci( L, "signalEvent" );
|
||||
|
||||
lua_createtable( L, queue_pos, 0 );
|
||||
|
||||
int p = 1;
|
||||
while( queue_pos > 0 )
|
||||
{
|
||||
lua_pushinteger( L, p++ );
|
||||
lua_pushinteger( L, queue[ --queue_pos ] );
|
||||
lua_settable( L, -3 );
|
||||
}
|
||||
|
||||
if( lua_pcall( L, 1, 0, -3 ) ) exit( -1 );
|
||||
lua_pop( L, 1 );
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,13 @@ extern volatile sig_atomic_t term;
|
|||
extern volatile sig_atomic_t sigcode;
|
||||
|
||||
|
||||
// Initializes signal handling.
|
||||
// initializes signal handling.
|
||||
extern void signal_init( );
|
||||
|
||||
// FIXME
|
||||
int l_onsignal( lua_State *L );
|
||||
|
||||
// notifies the mantle about signals
|
||||
extern void signal_notify( lua_State *L );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -175,7 +175,7 @@ default.collect = function
|
|||
then
|
||||
log( 'Error', 'Failure with a list with exitcode = ', exitcode )
|
||||
else
|
||||
log( 'Error', 'Unknown exitcode "',exitcode,'" with a list' )
|
||||
log( 'Error', 'Unknown exitcode "', exitcode, '" with a list' )
|
||||
|
||||
rc = 'die'
|
||||
end
|
||||
|
|
|
@ -147,7 +147,7 @@ rsync.action = function
|
|||
end
|
||||
|
||||
--
|
||||
-- Gets the list of paths for the event list
|
||||
-- Gets the list of paths for the event list.
|
||||
--
|
||||
-- Deletes create multi match patterns
|
||||
--
|
||||
|
|
|
@ -358,7 +358,7 @@ local eventListFuncs =
|
|||
--
|
||||
getPaths = function
|
||||
(
|
||||
elist, -- handle returned by getevents( )
|
||||
elist, -- handle returned by getEvents( )
|
||||
mutator -- if not nil called with ( etype, path, path2 )
|
||||
-- returns one or two strings to add.
|
||||
)
|
||||
|
|
|
@ -437,9 +437,9 @@ function mci.initialize
|
|||
end
|
||||
|
||||
-- from now on use logging as configured instead of stdout/err.
|
||||
lsyncdStatus = 'run';
|
||||
lsyncdStatus = 'run'
|
||||
|
||||
configure( 'running' );
|
||||
configure( 'running' )
|
||||
|
||||
local ufuncs =
|
||||
{
|
||||
|
@ -609,9 +609,9 @@ function mci.term
|
|||
{
|
||||
[ 2 ] = 'INT',
|
||||
[ 15 ] = 'TERM'
|
||||
};
|
||||
}
|
||||
|
||||
local sigtext = sigtexts[ sigcode ];
|
||||
local sigtext = sigtexts[ sigcode ]
|
||||
|
||||
if not sigtext then sigtext = 'UNKNOWN' end
|
||||
|
||||
|
|
|
@ -29,9 +29,7 @@ end
|
|||
-- keys are signal numbers
|
||||
-- values are functions to be called
|
||||
-- or 'false' in case of disabled default signals
|
||||
--
|
||||
-- On signal the core will directly look up this table.
|
||||
mci.sigHandlers = { }
|
||||
local sigHandlers = { }
|
||||
|
||||
-- counter of signal handlers
|
||||
-- used to tell the core to enlarge the signal queue if needed
|
||||
|
@ -74,7 +72,7 @@ local function onsignalPrep
|
|||
error( 'signal of type ' .. type( signal ) .. ' invalid.', 2 )
|
||||
end
|
||||
|
||||
mci.sigHandlers[ signum ] = handler
|
||||
sigHandlers[ signum ] = handler
|
||||
end
|
||||
|
||||
--
|
||||
|
@ -89,7 +87,7 @@ function onsignal
|
|||
)
|
||||
onsignalPrep( signal, handler )
|
||||
|
||||
core.onsignal( mci.sigHandlers )
|
||||
core.onsignal( sigHandlers )
|
||||
end
|
||||
|
||||
|
||||
|
@ -105,24 +103,46 @@ function initSignalHandlers
|
|||
onsignalPrep(
|
||||
'HUP',
|
||||
function( )
|
||||
console.log( 'GOT A HUP SIGNAL' );
|
||||
print( 'GOT A HUP SIGNAL' )
|
||||
end
|
||||
)
|
||||
|
||||
onsignalPrep(
|
||||
'INT',
|
||||
function( )
|
||||
console.log( 'GOT A INT SIGNAL' );
|
||||
print( 'GOT A INT SIGNAL' )
|
||||
end
|
||||
)
|
||||
|
||||
onsignalPrep(
|
||||
'TERM',
|
||||
function( )
|
||||
console.log( 'GOT A TERM SIGNAL' );
|
||||
print( 'GOT A TERM SIGNAL' )
|
||||
end
|
||||
)
|
||||
|
||||
core.onsignal( mci.sigHandlers )
|
||||
core.onsignal( sigHandlers )
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Called by kernel on catched and queued signals
|
||||
--
|
||||
mci.signalEvent =
|
||||
function
|
||||
(
|
||||
sigtable
|
||||
)
|
||||
for _, signum in ipairs( sigtable )
|
||||
do
|
||||
local handler = sigHandlers[ signum ]
|
||||
|
||||
if not handler
|
||||
then
|
||||
log( 'Error', 'Received signal '..signnum..' without a handler.' )
|
||||
end
|
||||
|
||||
handler( )
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue