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} )
# 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

View File

@ -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 )
{

View File

@ -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 }

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.
extern void signal_init( );
// returns signal name/signums as table
int l_signames( lua_State * L );
#endif

View File

@ -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 \

View File

@ -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

View File

@ -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 <axkibe@gmail.com>
#
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