2018-05-12 13:08:14 +00:00
|
|
|
--
|
|
|
|
-- signal.lua from Lsyncd -- the Live (Mirror) Syncing Demon
|
|
|
|
--
|
|
|
|
--
|
|
|
|
-- The default signal handles for HUP, INT and TERM.
|
|
|
|
--
|
|
|
|
--
|
|
|
|
-- License: GPLv2 (see COPYING) or any later version
|
|
|
|
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
|
|
|
--
|
|
|
|
if not default then error( 'default not loaded' ) end
|
|
|
|
|
|
|
|
|
|
|
|
default.signal = { }
|
|
|
|
|
|
|
|
|
2018-05-25 08:10:38 +00:00
|
|
|
--
|
|
|
|
--
|
|
|
|
--
|
|
|
|
local function onCollect
|
|
|
|
(
|
|
|
|
sync -- the user intf to the sync a child finished for
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2018-05-12 13:08:14 +00:00
|
|
|
local function sighup
|
|
|
|
( )
|
|
|
|
print( 'GOT A HUP SIGNAL' )
|
|
|
|
|
|
|
|
os.exit( 1 )
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function sigint
|
|
|
|
( )
|
|
|
|
print( 'GOT AN INT SIGNAL' )
|
|
|
|
|
2018-05-25 08:10:38 +00:00
|
|
|
for _, sync in ipairs( syncs )
|
2018-05-13 12:13:54 +00:00
|
|
|
do
|
2018-05-25 08:10:38 +00:00
|
|
|
sync.stop( )
|
|
|
|
|
|
|
|
if( #sync.pids == 0 )
|
|
|
|
then
|
|
|
|
syncs.remove( sync )
|
|
|
|
else
|
|
|
|
sync.onCollect( onCollect )
|
|
|
|
end
|
2018-05-13 12:13:54 +00:00
|
|
|
end
|
2018-05-25 08:10:38 +00:00
|
|
|
-- os.exit( 1 )
|
2018-05-12 13:08:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function sigterm
|
|
|
|
( )
|
|
|
|
print( 'GOT A TERM SIGNAL' )
|
|
|
|
|
|
|
|
os.exit( 1 )
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Sets up the default HUP/INT/TERM signal handlers.
|
|
|
|
--
|
|
|
|
-- Called after user scripts finished
|
|
|
|
--
|
|
|
|
init =
|
|
|
|
function
|
|
|
|
( )
|
|
|
|
local hup = getsignal( 'HUP' )
|
|
|
|
local int = getsignal( 'INT' )
|
|
|
|
local term = getsignal( 'TERM' )
|
|
|
|
|
2018-05-25 08:10:38 +00:00
|
|
|
print( 'INIT', hup, int, term )
|
|
|
|
|
2018-05-12 13:08:14 +00:00
|
|
|
if hup ~= false then hup = sighup end
|
|
|
|
if int ~= false then int = sigint end
|
|
|
|
if term ~= false then term = sigterm end
|
|
|
|
|
|
|
|
onsignal(
|
|
|
|
'HUP', hup,
|
|
|
|
'INT', int,
|
2018-05-25 08:10:38 +00:00
|
|
|
'TERM', term
|
2018-05-12 13:08:14 +00:00
|
|
|
)
|
|
|
|
end
|