mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-09 03:32:30 +00:00
reworking the signal system
This commit is contained in:
parent
8377a2d6a4
commit
0425ff230c
|
@ -65,6 +65,7 @@ set( MANTLE_CODE
|
||||||
${PROJECT_SOURCE_DIR}/mantle/syncmaster.lua
|
${PROJECT_SOURCE_DIR}/mantle/syncmaster.lua
|
||||||
${PROJECT_SOURCE_DIR}/mantle/monitor.lua
|
${PROJECT_SOURCE_DIR}/mantle/monitor.lua
|
||||||
${PROJECT_SOURCE_DIR}/mantle/fwriter.lua
|
${PROJECT_SOURCE_DIR}/mantle/fwriter.lua
|
||||||
|
${PROJECT_SOURCE_DIR}/mantle/signal.lua
|
||||||
${PROJECT_SOURCE_DIR}/mantle/statusfile.lua
|
${PROJECT_SOURCE_DIR}/mantle/statusfile.lua
|
||||||
${PROJECT_SOURCE_DIR}/mantle/useralarm.lua
|
${PROJECT_SOURCE_DIR}/mantle/useralarm.lua
|
||||||
${PROJECT_SOURCE_DIR}/mantle/mci.lua
|
${PROJECT_SOURCE_DIR}/mantle/mci.lua
|
||||||
|
|
|
@ -386,14 +386,6 @@ 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
|
|
||||||
for num, name in pairs( signames )
|
|
||||||
do
|
|
||||||
print( 'SIG', num, name )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Checks if user overwrote the settings function.
|
-- Checks if user overwrote the settings function.
|
||||||
-- ( was Lsyncd <2.1 style )
|
-- ( was Lsyncd <2.1 style )
|
||||||
if userENV.settings ~= settings
|
if userENV.settings ~= settings
|
||||||
|
@ -407,6 +399,8 @@ function mci.initialize
|
||||||
os.exit( -1 )
|
os.exit( -1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
initSignalHandlers( firstTime )
|
||||||
|
|
||||||
lastReportedWaiting = false
|
lastReportedWaiting = false
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
105
mantle/signal.lua
Normal file
105
mantle/signal.lua
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
--
|
||||||
|
-- signal.lua from Lsyncd -- the Live (Mirror) Syncing Demon
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- Handles signal handlers.
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- License: GPLv2 (see COPYING) or any later version
|
||||||
|
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||||
|
--
|
||||||
|
if mantle
|
||||||
|
then
|
||||||
|
print( 'Error, Lsyncd mantle already loaded' )
|
||||||
|
os.exit( -1 )
|
||||||
|
end
|
||||||
|
|
||||||
|
-- "signames" is a a (mantle-)global table from signames.lua created by the
|
||||||
|
-- build script following code creates a (hash)table for the other direction.
|
||||||
|
local signums = { }
|
||||||
|
|
||||||
|
for num, name in pairs( signames )
|
||||||
|
do
|
||||||
|
signums[ name ] = num
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- a table of all registered signal handlers
|
||||||
|
local sigHandlers = { }
|
||||||
|
|
||||||
|
-- counter of signal handlers
|
||||||
|
-- used to tell the core to enlarge the signal queue if needed
|
||||||
|
-- (the queue must be as large as the number of different signals listened for)
|
||||||
|
local sigHandlerCount = 0
|
||||||
|
|
||||||
|
--
|
||||||
|
-- onsignal function exported to userEnv
|
||||||
|
--
|
||||||
|
function onsignal
|
||||||
|
(
|
||||||
|
signal, -- signal number or name
|
||||||
|
handler -- function to call
|
||||||
|
-- -- or nil to unload the handle
|
||||||
|
-- -- or false to disable default signal handlers
|
||||||
|
)
|
||||||
|
local signum
|
||||||
|
|
||||||
|
if type( signal ) == 'number'
|
||||||
|
then
|
||||||
|
if signal < 0
|
||||||
|
or signal ~= signal
|
||||||
|
or signal - floor( signal ) ~= 0
|
||||||
|
then
|
||||||
|
error( 'signal ' .. signal .. ' is an invalid number.' , 2 )
|
||||||
|
end
|
||||||
|
|
||||||
|
signum = signal
|
||||||
|
elseif type( signal ) == 'string'
|
||||||
|
then
|
||||||
|
signum = signums[ signal ]
|
||||||
|
|
||||||
|
if signum == nil
|
||||||
|
then
|
||||||
|
error( 'signal "' .. signal .. '" unknown.' , 2 )
|
||||||
|
end
|
||||||
|
else
|
||||||
|
error( 'signal of type ' .. type( signal ) .. ' invalid.', 2 )
|
||||||
|
end
|
||||||
|
|
||||||
|
-- FIXME store the handler in a table
|
||||||
|
-- FIXME tell core of max queue size
|
||||||
|
|
||||||
|
core.onsignal( signum, handler );
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Sets up the default HUP/INT/TERM signal handlers.
|
||||||
|
--
|
||||||
|
-- Called after user scripts finished
|
||||||
|
--
|
||||||
|
function initSignalHandlers
|
||||||
|
(
|
||||||
|
firstTime --- TODO check if needed
|
||||||
|
)
|
||||||
|
onsignal(
|
||||||
|
'HUP',
|
||||||
|
function( )
|
||||||
|
console.log( 'GOT A HUP SIGNAL' );
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
onsignal(
|
||||||
|
'INT',
|
||||||
|
function( )
|
||||||
|
console.log( 'GOT A INT SIGNAL' );
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
onsignal(
|
||||||
|
'TERM',
|
||||||
|
function( )
|
||||||
|
console.log( 'GOT A TERM SIGNAL' );
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
|
@ -11,6 +11,9 @@
|
||||||
#
|
#
|
||||||
KILL=/bin/kill
|
KILL=/bin/kill
|
||||||
|
|
||||||
|
# Don't know a better way, checks only until this signal number
|
||||||
|
# To quote, this ought to be enough for anybody.
|
||||||
|
nmax=256
|
||||||
|
|
||||||
if [ "$#" -ne 1 ];
|
if [ "$#" -ne 1 ];
|
||||||
then
|
then
|
||||||
|
@ -28,13 +31,14 @@ echo "signames =" >> $1
|
||||||
echo "{" >> $1
|
echo "{" >> $1
|
||||||
|
|
||||||
n=1
|
n=1
|
||||||
while name=`kill -l $n 2>/dev/null`;
|
while name=`$KILL --list=$n 2>/dev/null`;
|
||||||
do
|
do
|
||||||
if ! [ -z $name ]
|
if ! [ -z $name ]
|
||||||
then
|
then
|
||||||
echo $echoe "\t[ $n ] = '$name'," >> $1
|
echo $echoe "\t[ $n ] = '$name'," >> $1
|
||||||
fi
|
fi
|
||||||
n=$(( n + 1 ))
|
n=$(( n + 1 ))
|
||||||
|
if [ $n -gt $nmax ]; then break; fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "}" >> $1
|
echo "}" >> $1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user