rewriting signal system

This commit is contained in:
Axel Kittenberger 2018-04-22 17:52:35 +02:00
parent a63f33dc4a
commit 8377a2d6a4
8 changed files with 46 additions and 52 deletions

View File

@ -10,7 +10,7 @@ find_package( Lua REQUIRED )
include_directories ( ${LUA_INCLUDE_DIR} ) include_directories ( ${LUA_INCLUDE_DIR} )
# Setting Lsyncd sources. # Setting Lsyncd sources.
# Order here doesn't matter much. # Order doesn't matter here.
set( LSYNCD_SRC set( LSYNCD_SRC
core/log.c core/log.c
core/observe.c core/observe.c
@ -51,6 +51,7 @@ include_directories("${PROJECT_BINARY_DIR}")
# on initialization of Lsyncd. # on initialization of Lsyncd.
# #
set( MANTLE_CODE set( MANTLE_CODE
${PROJECT_SOURCE_DIR}/signames.lua
${PROJECT_SOURCE_DIR}/mantle/array.lua ${PROJECT_SOURCE_DIR}/mantle/array.lua
${PROJECT_SOURCE_DIR}/mantle/counter.lua ${PROJECT_SOURCE_DIR}/mantle/counter.lua
${PROJECT_SOURCE_DIR}/mantle/queue.lua ${PROJECT_SOURCE_DIR}/mantle/queue.lua
@ -73,6 +74,13 @@ set( MANTLE_CODE
${PROJECT_SOURCE_DIR}/mantle/userenv.lua ${PROJECT_SOURCE_DIR}/mantle/userenv.lua
) )
# Generates the signal list for this system
add_custom_command( OUTPUT signames.lua
COMMAND ${CMAKE_COMMAND} -E echo "Generating signal name list"
COMMAND ${PROJECT_SOURCE_DIR}/signames.sh signames.lua
DEPENDS signames.sh
)
# The default sync implementations. # The default sync implementations.
# #
# Order here matters as the scripts lua will be executed in this order # Order here matters as the scripts lua will be executed in this order

View File

@ -339,11 +339,19 @@ main1( int argc, char *argv[] )
printf( "kernels clocks_per_sec=%ld\n", clocks_per_sec ); printf( "kernels clocks_per_sec=%ld\n", clocks_per_sec );
} }
signal_init( );
#ifdef WITH_INOTIFY
open_inotify( L );
#endif
mci_load_mantle( L ); mci_load_mantle( L );
mci_load_default( L ); mci_load_default( L );
// checks if there is a "-help" or "--help" // checks if there is a "-help" or "--help"
{ {
// FIXME this should be done in mantle
int i; int i;
for( i = argp; i < argc; i++ ) for( i = argp; i < argc; i++ )
{ {
@ -371,8 +379,8 @@ main1( int argc, char *argv[] )
while( argp < argc ) while( argp < argc )
{ {
lua_pushstring( L, argv[ argp++ ] );
lua_pushnumber( L, idx++ ); lua_pushnumber( L, idx++ );
lua_pushstring( L, argv[ argp++ ] );
lua_settable( L, -3 ); lua_settable( L, -3 );
} }
@ -400,12 +408,6 @@ main1( int argc, char *argv[] )
lua_pop( L, 2 ); lua_pop( L, 2 );
} }
signal_init( );
#ifdef WITH_INOTIFY
open_inotify( L );
#endif
// checks existence of the config file // checks existence of the config file
if( lsyncd_config_file ) if( lsyncd_config_file )
{ {

View File

@ -653,7 +653,6 @@ static const luaL_Reg corelib[ ] =
// { "onsignal", l_onsignal }, // { "onsignal", l_onsignal },
{ "readdir", l_readdir }, { "readdir", l_readdir },
{ "realdir", l_realdir }, { "realdir", l_realdir },
{ "signames", l_signames },
{ "stackdump", l_stackdump }, { "stackdump", l_stackdump },
{ "terminate", l_terminate }, { "terminate", l_terminate },
{ NULL, NULL } { NULL, NULL }

View File

@ -112,29 +112,3 @@ signal_init( )
} }
*/ */
/*
| 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,7 +18,4 @@ extern volatile sig_atomic_t sigcode;
// Initializes signal handling. // Initializes signal handling.
extern void signal_init( ); extern void signal_init( );
// returns signal name/signums as table
int l_signames( lua_State * L );
#endif #endif

View File

@ -1,5 +1,9 @@
#!/bin/sh #!/bin/sh
# removes all stuff generated by cmake / make #
# Removes all stuff generated by cmake / make
#
# This mini script supposes an inplace build.
#
rm -rf build/ CMakeFiles/ rm -rf build/ CMakeFiles/
rm -f \ rm -f \
@ -9,6 +13,7 @@ rm -f \
CMakeCache.txt \ CMakeCache.txt \
cmake_install.cmake \ cmake_install.cmake \
install_manifest.txt \ install_manifest.txt \
signames.lua \
default.c \ default.c \
core.c \ core.c \
*.o \ *.o \

View File

@ -244,6 +244,12 @@ function mci.configure(
args, -- arguments given by user args, -- arguments given by user
monitors -- list of monitors the core can do monitors -- list of monitors the core can do
) )
print( "mci.configure", #args )
for k, v in pairs( args ) do
print( 'a', k, v )
end
Monitor.initialize( monitors ) Monitor.initialize( monitors )
-- --
@ -380,16 +386,11 @@ function mci.initialize
firstTime -- true when Lsyncd startups the first time, firstTime -- true when Lsyncd startups the first time,
-- -- false on resets, due to HUP signal or monitor queue overflow. -- -- false on resets, due to HUP signal or monitor queue overflow.
) )
print( 'HELLO' )
do do
local signames = core.signames( ) for num, name in pairs( signames )
local signum = 0
signame = signames[ 0 ]
while signame ~= nil
do do
print( 'SIG', signum, signame ) print( 'SIG', num, name )
signum = signum + 1
signame = signames[ signum ]
end end
end end

View File

@ -4,27 +4,35 @@
# Creates a .lua file for all signal names understood by the kill command # Creates a .lua file for all signal names understood by the kill command
# on the system Lsyncd is being compiled for. # on the system Lsyncd is being compiled for.
# #
# This script has been tested with bash and dash.
#
# License: GPLv2 (see COPYING) or any later version # License: GPLv2 (see COPYING) or any later version
# Authors: Axel Kittenberger <axkibe@gmail.com> # Authors: Axel Kittenberger <axkibe@gmail.com>
# #
KILL=/bin/kill KILL=/bin/kill
if [ "$#" -ne 1 ]; if [ "$#" -ne 1 ];
then then
echo >&2 "$0 needs excatly one argument -- the lua file to create" echo >&2 "$0 needs excatly one argument -- the lua file to create"
exit 1 exit 1
fi fi
if ! [ "$BASH_VERSION" = '' ];
then
echoe=-e
fi
echo "-- This file is autogenerated by $0 querying `$KILL --version`" > $1 echo "-- This file is autogenerated by $0 querying `$KILL --version`" > $1
echo "siglist =" >> $1 echo "signames =" >> $1
echo "{" >> $1 echo "{" >> $1
n=1 n=1
while name=`kill -l $n 2>/dev/null`; while name=`kill -l $n 2>/dev/null`;
do do
if [[ $name ]] if ! [ -z $name ]
then then
echo -e "\t[ $n ] = '$name'," >> $1 echo $echoe "\t[ $n ] = '$name'," >> $1
fi fi
n=$(( n + 1 )) n=$(( n + 1 ))
done done