code cleanups, do no longer workaround settings = {...} deprecation

This commit is contained in:
Axel Kittenberger 2016-12-01 12:52:09 +01:00
parent 2f4dd3aa7e
commit dbbe5dfdf7
4 changed files with 100 additions and 75 deletions

View File

@ -10,6 +10,9 @@
change: _verbatim forced for 'exitcodes' entry. change: _verbatim forced for 'exitcodes' entry.
change: manpage is not rebuild by default. change: manpage is not rebuild by default.
it is provided precompiled. it is provided precompiled.
change:
faulty/deprecated config files that use settings = { ... }, with equal sign
are no longer worked around.
fix: ']' is not escaped for rsync rules, since rsync only applies fix: ']' is not escaped for rsync rules, since rsync only applies
doesn't applie pattern matching if no other pattern chars doesn't applie pattern matching if no other pattern chars
are found. are found.

View File

@ -114,7 +114,7 @@ default.collect = function( agent, exitcode )
elseif rc == 'again' elseif rc == 'again'
then then
if settings('insist') if settings( 'insist' )
then then
log( log(
'Normal', 'Normal',

View File

@ -265,18 +265,22 @@ add_logcat( const char *name, int priority )
if( !strcmp( "all", name ) ) if( !strcmp( "all", name ) )
{ {
settings.log_level = 99; settings.log_level = 99;
return true; return true;
} }
if( !strcmp( "scarce", name ) ) if( !strcmp( "scarce", name ) )
{ {
settings.log_level = LOG_WARNING; settings.log_level = LOG_WARNING;
return true; return true;
} }
// categories must start with a capital letter. // categories must start with a capital letter.
if( name[ 0 ] < 'A' || name[ 0 ] > 'Z' ) if( name[ 0 ] < 'A' || name[ 0 ] > 'Z' )
{ return false; } {
return false;
}
if( !logcats[ name[ 0 ]- 'A' ] ) if( !logcats[ name[ 0 ]- 'A' ] )
{ {
@ -995,7 +999,9 @@ l_log( lua_State *L )
// skips filtered messages // skips filtered messages
if( priority > settings.log_level ) if( priority > settings.log_level )
{ return 0; } {
return 0;
}
// replaces non string values // replaces non string values
{ {
@ -1226,9 +1232,14 @@ l_exec( lua_State *L )
// prepares the arguments // prepares the arguments
argv = s_calloc( argc + 2, sizeof( char * ) ); argv = s_calloc( argc + 2, sizeof( char * ) );
argv[ 0 ] = binary; argv[ 0 ] = binary;
for( i = 1; i <= argc; i++ ) for( i = 1; i <= argc; i++ )
{ argv[i] = luaL_checkstring( L, i + li ); } {
argv[i] = luaL_checkstring( L, i + li );
}
argv[ i ] = NULL; argv[ i ] = NULL;
// the fork! // the fork!
@ -1238,7 +1249,9 @@ l_exec( lua_State *L )
{ {
// replaces stdin for pipes // replaces stdin for pipes
if( pipe_text ) if( pipe_text )
{ dup2( pipefd[ 0 ], STDIN_FILENO ); } {
dup2( pipefd[ 0 ], STDIN_FILENO );
}
// if lsyncd runs as a daemon and has a logfile it will redirect // if lsyncd runs as a daemon and has a logfile it will redirect
// stdout/stderr of child processes to the logfile. // stdout/stderr of child processes to the logfile.
@ -1579,6 +1592,7 @@ static int
l_configure( lua_State *L ) l_configure( lua_State *L )
{ {
const char * command = luaL_checkstring( L, 1 ); const char * command = luaL_checkstring( L, 1 );
if( !strcmp( command, "running" ) ) if( !strcmp( command, "running" ) )
{ {
// set by runner after first initialize // set by runner after first initialize

View File

@ -2313,22 +2313,17 @@ local Syncs = ( function( )
-- --
local function add( config ) local function add( config )
-- workaround for backwards compatibility -- Checks if user overwrote the settings function.
-- FIXME: remove when dropping that -- ( was Lsyncd <2.1 style )
if settings ~= settingsSafe if settings ~= settingsSafe
then then
log( log(
'Warn', 'Error',
'settings = { ... } is deprecated.\n'.. 'Do not use settings = { ... }\n'..
' please use settings{ ... } (without the equal sign)' ' please use settings{ ... } (without the equal sign)'
) )
for k, v in pairs( settings ) os.exit( -1 )
do
uSettings[ k ] = v
end
settings = settingsSafe
end end
-- Creates a new config table which inherits all keys/values -- Creates a new config table which inherits all keys/values
@ -3826,7 +3821,8 @@ function runner.configure( args, monitors )
local o = options[ a ] local o = options[ a ]
if not o then if not o
then
log( log(
'Error', 'Error',
'unknown option command line option ', 'unknown option command line option ',
@ -3835,22 +3831,30 @@ function runner.configure( args, monitors )
os.exit( -1 ) os.exit( -1 )
end end
if o[ 1 ] >= 0 and i + o[ 1 ] > #args then if o[ 1 ] >= 0 and i + o[ 1 ] > #args
then
log( 'Error', a ,' needs ', o[ 1 ],' arguments' ) log( 'Error', a ,' needs ', o[ 1 ],' arguments' )
os.exit( -1 ) os.exit( -1 )
elseif o[1] < 0 then elseif o[1] < 0
then
o[ 1 ] = -o[ 1 ] o[ 1 ] = -o[ 1 ]
end end
if o[ 2 ] then if o[ 2 ]
if o[ 1 ] == 0 then then
if o[ 1 ] == 0
then
o[ 2 ]( ) o[ 2 ]( )
elseif o[ 1 ] == 1 then elseif o[ 1 ] == 1
o[ 2 ]( args[i + 1] ) then
elseif o[ 1 ] == 2 then o[ 2 ]( args[ i + 1] )
o[ 2 ]( args[i + 1], args[i + 2] ) elseif o[ 1 ] == 2
elseif o[ 1 ] == 3 then then
o[ 2 ]( args[i + 1], args[i + 2], args[i + 3] ) o[ 2 ]( args[ i + 1], args[ i + 2] )
elseif o[ 1 ] == 3
then
o[ 2 ]( args[ i + 1], args[ i + 2], args[ i + 3] )
end end
end end
i = i + o[1] i = i + o[1]
@ -3859,35 +3863,33 @@ function runner.configure( args, monitors )
end end
if clSettings.syncs then if clSettings.syncs
then
if #nonopts ~= 0 then if #nonopts ~= 0
then
log( log(
'Error', 'Error',
'There cannot be command line syncs and config file together.' 'There cannot be command line syncs and a config file together.'
) )
os.exit( -1 ) os.exit( -1 )
end end
else else
if #nonopts == 0 then if #nonopts == 0
then
runner.help( args[ 0 ] ) runner.help( args[ 0 ] )
elseif #nonopts == 1
elseif #nonopts == 1 then then
return nonopts[ 1 ] return nonopts[ 1 ]
else else
-- TODO make this possible -- TODO make this possible
log( log(
'Error', 'Error',
'There can only be one config file in command line.' 'There can only be one config file in the command line.'
) )
os.exit( -1 )
os.exit( -1 )
end end
end end
@ -3903,17 +3905,17 @@ end
-- --
function runner.initialize( firstTime ) function runner.initialize( firstTime )
if settings ~= settingsSafe then -- Checks if user overwrote the settings function.
-- ( was Lsyncd <2.1 style )
if settings ~= settingsSafe
then
log( log(
'Warn', 'Error',
'settings = { ... } is deprecated.\n'.. 'Do not use settings = { ... }\n'..
' please use settings{ ... } (without the equal sign)' ' please use settings{ ... } (without the equal sign)'
) )
for k, v in pairs( settings ) do os.exit( -1 )
uSettings[ k ] = v
end
end end
lastReportedWaiting = false lastReportedWaiting = false
@ -3929,9 +3931,10 @@ function runner.initialize( firstTime )
-- FIXME this can be removed when -- FIXME this can be removed when
-- Lsyncd 2.0.x backwards compatibility is dropped -- Lsyncd 2.0.x backwards compatibility is dropped
-- --
for k, v in ipairs( uSettings ) do for k, v in ipairs( uSettings )
do
if uSettings[ v ] then if uSettings[ v ]
then
log( log(
'Error', 'Error',
'Double setting "' .. v.. '"' 'Double setting "' .. v.. '"'
@ -3940,14 +3943,15 @@ function runner.initialize( firstTime )
end end
uSettings[ v ]= true uSettings[ v ]= true
end end
-- --
-- all command line settings overwrite config file settings -- all command line settings overwrite config file settings
-- --
for k, v in pairs( clSettings ) do for k, v in pairs( clSettings )
if k ~= 'syncs' then do
if k ~= 'syncs'
then
uSettings[ k ] = v uSettings[ k ] = v
end end
end end
@ -3955,77 +3959,80 @@ function runner.initialize( firstTime )
-- --
-- implicitly forces 'insist' on Lsyncd resets. -- implicitly forces 'insist' on Lsyncd resets.
-- --
if not firstTime then if not firstTime
then
uSettings.insist = true uSettings.insist = true
end end
-- --
-- adds syncs specified by command line. -- adds syncs specified by command line.
-- --
if clSettings.syncs then if clSettings.syncs
then
for _, s in ipairs( clSettings.syncs ) do for _, s in ipairs( clSettings.syncs )
do
if s[ 1 ] == 'rsync' then if s[ 1 ] == 'rsync'
then
sync{ sync{
default.rsync, default.rsync,
source = s[ 2 ], source = s[ 2 ],
target = s[ 3 ] target = s[ 3 ]
} }
elseif s[ 1 ] == 'rsyncssh'
elseif s[ 1 ] == 'rsyncssh' then then
sync{ sync{
default.rsyncssh, default.rsyncssh,
source = s[ 2 ], source = s[ 2 ],
host = s[ 3 ], host = s[ 3 ],
targetdir=s[ 4 ] targetdir=s[ 4 ]
} }
elseif s[ 1 ] == 'direct'
elseif s[ 1 ] == 'direct' then then
sync{ sync{
default.direct, default.direct,
source=s[ 2 ], source=s[ 2 ],
target=s[ 3 ] target=s[ 3 ]
} }
end end
end end
end end
if uSettings.nodaemon then if uSettings.nodaemon
then
lsyncd.configure( 'nodaemon' ) lsyncd.configure( 'nodaemon' )
end end
if uSettings.logfile then if uSettings.logfile
then
lsyncd.configure( 'logfile', uSettings.logfile ) lsyncd.configure( 'logfile', uSettings.logfile )
end end
if uSettings.logident then if uSettings.logident
then
lsyncd.configure( 'logident', uSettings.logident ) lsyncd.configure( 'logident', uSettings.logident )
end end
if uSettings.logfacility then if uSettings.logfacility
then
lsyncd.configure( 'logfacility', uSettings.logfacility ) lsyncd.configure( 'logfacility', uSettings.logfacility )
end end
if uSettings.pidfile then if uSettings.pidfile
then
lsyncd.configure( 'pidfile', uSettings.pidfile ) lsyncd.configure( 'pidfile', uSettings.pidfile )
end end
-- --
-- Transfers some defaults to uSettings -- Transfers some defaults to uSettings
-- --
if uSettings.statusInterval == nil then if uSettings.statusInterval == nil
then
uSettings.statusInterval = default.statusInterval uSettings.statusInterval = default.statusInterval
end end
-- makes sure the user gave Lsyncd anything to do -- makes sure the user gave Lsyncd anything to do
if Syncs.size() == 0 then if Syncs.size() == 0
then
log( log(
'Error', 'Error',
'Nothing to watch!' 'Nothing to watch!'
@ -4463,6 +4470,7 @@ function settings( a1 )
end end
end end
end end
settingsSafe = settings settingsSafe = settings
-- --