From 8377a2d6a43d5286c04ba051ed6ea0b0fbd0671d Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Sun, 22 Apr 2018 17:52:35 +0200 Subject: [PATCH] rewriting signal system --- CMakeLists.txt | 12 ++++++++++-- core/main.c | 18 ++++++++++-------- core/mci.c | 1 - core/signal.c | 26 -------------------------- core/signal.h | 3 --- distclean.sh | 7 ++++++- mantle/mci.lua | 17 +++++++++-------- signames.sh | 14 +++++++++++--- 8 files changed, 46 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffa4cbb..4a51523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ find_package( Lua REQUIRED ) include_directories ( ${LUA_INCLUDE_DIR} ) # Setting Lsyncd sources. -# Order here doesn't matter much. +# Order doesn't matter here. set( LSYNCD_SRC core/log.c core/observe.c @@ -42,7 +42,7 @@ configure_file ( "${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/config.h" ) -include_directories("${PROJECT_BINARY_DIR}") +include_directories( "${PROJECT_BINARY_DIR}" ) # The mantle written in Lua @@ -51,6 +51,7 @@ include_directories("${PROJECT_BINARY_DIR}") # on initialization of Lsyncd. # set( MANTLE_CODE + ${PROJECT_SOURCE_DIR}/signames.lua ${PROJECT_SOURCE_DIR}/mantle/array.lua ${PROJECT_SOURCE_DIR}/mantle/counter.lua ${PROJECT_SOURCE_DIR}/mantle/queue.lua @@ -73,6 +74,13 @@ set( MANTLE_CODE ${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. # # Order here matters as the scripts lua will be executed in this order diff --git a/core/main.c b/core/main.c index 0904350..71f48ba 100644 --- a/core/main.c +++ b/core/main.c @@ -339,11 +339,19 @@ main1( int argc, char *argv[] ) 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_default( L ); // checks if there is a "-help" or "--help" { + // FIXME this should be done in mantle int i; for( i = argp; i < argc; i++ ) { @@ -371,8 +379,8 @@ main1( int argc, char *argv[] ) while( argp < argc ) { - lua_pushstring( L, argv[ argp++ ] ); lua_pushnumber( L, idx++ ); + lua_pushstring( L, argv[ argp++ ] ); lua_settable( L, -3 ); } @@ -392,7 +400,7 @@ main1( int argc, char *argv[] ) if( first_time ) { // If not first time, simply retains the config file given - s = lua_tostring(L, -1); + s = lua_tostring( L, -1 ); if( s ) lsyncd_config_file = s_strdup( s ); } @@ -400,12 +408,6 @@ 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 ) { diff --git a/core/mci.c b/core/mci.c index 6590bdf..60f13e0 100644 --- a/core/mci.c +++ b/core/mci.c @@ -653,7 +653,6 @@ static const luaL_Reg corelib[ ] = // { "onsignal", l_onsignal }, { "readdir", l_readdir }, { "realdir", l_realdir }, - { "signames", l_signames }, { "stackdump", l_stackdump }, { "terminate", l_terminate }, { NULL, NULL } diff --git a/core/signal.c b/core/signal.c index 608d5ad..644a828 100644 --- a/core/signal.c +++ b/core/signal.c @@ -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; -} - diff --git a/core/signal.h b/core/signal.h index ce38656..d9e00d0 100644 --- a/core/signal.h +++ b/core/signal.h @@ -18,7 +18,4 @@ 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 diff --git a/distclean.sh b/distclean.sh index ca305db..cb287df 100755 --- a/distclean.sh +++ b/distclean.sh @@ -1,5 +1,9 @@ #!/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 -f \ @@ -9,6 +13,7 @@ rm -f \ CMakeCache.txt \ cmake_install.cmake \ install_manifest.txt \ + signames.lua \ default.c \ core.c \ *.o \ diff --git a/mantle/mci.lua b/mantle/mci.lua index 3aff78f..1c5fd2d 100644 --- a/mantle/mci.lua +++ b/mantle/mci.lua @@ -244,6 +244,12 @@ function mci.configure( args, -- arguments given by user 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 ) -- @@ -380,16 +386,11 @@ function mci.initialize firstTime -- true when Lsyncd startups the first time, -- -- false on resets, due to HUP signal or monitor queue overflow. ) + print( 'HELLO' ) do - local signames = core.signames( ) - local signum = 0 - signame = signames[ 0 ] - - while signame ~= nil + for num, name in pairs( signames ) do - print( 'SIG', signum, signame ) - signum = signum + 1 - signame = signames[ signum ] + print( 'SIG', num, name ) end end diff --git a/signames.sh b/signames.sh index 6ef3222..1b62161 100755 --- a/signames.sh +++ b/signames.sh @@ -4,27 +4,35 @@ # Creates a .lua file for all signal names understood by the kill command # 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 # Authors: Axel Kittenberger # KILL=/bin/kill + if [ "$#" -ne 1 ]; then echo >&2 "$0 needs excatly one argument -- the lua file to create" exit 1 fi +if ! [ "$BASH_VERSION" = '' ]; +then + echoe=-e +fi + echo "-- This file is autogenerated by $0 querying `$KILL --version`" > $1 -echo "siglist =" >> $1 +echo "signames =" >> $1 echo "{" >> $1 n=1 while name=`kill -l $n 2>/dev/null`; do - if [[ $name ]] + if ! [ -z $name ] then - echo -e "\t[ $n ] = '$name'," >> $1 + echo $echoe "\t[ $n ] = '$name'," >> $1 fi n=$(( n + 1 )) done