force _verbatim for 'exitcodes'

This commit is contained in:
Axel Kittenberger 2016-05-03 10:45:22 +02:00
parent 4740a2ca8f
commit 0b9297b790
3 changed files with 88 additions and 32 deletions

View File

@ -1,3 +1,6 @@
??-??-????:
change: _verbatim forced for 'exitcodes' entry.
15-10-2015: 2.1.6
enhancement: Lsyncd now locks its pidfile
enhancement: added ssh.identifyFile and ssh.options options

100
lsyncd.c
View File

@ -80,6 +80,7 @@ static char *monitors[] = {
NULL,
};
/**
| Configuration parameters that matter to the core
*/
@ -92,16 +93,19 @@ struct settings settings = {
.nodaemon = false,
};
/*
| True when Lsyncd daemonized itself.
*/
static bool is_daemon = false;
/*
| The config file loaded by Lsyncd.
*/
char * lsyncd_config_file = NULL;
/*
| False after first time Lsyncd started up.
|
@ -114,6 +118,7 @@ char * lsyncd_config_file = NULL;
*/
static bool first_time = true;
/*
| Set by TERM or HUP signal handler
| telling Lsyncd should end or reset ASAP.
@ -123,11 +128,13 @@ volatile sig_atomic_t term = 0;
volatile sig_atomic_t sigcode = 0;
int pidfile_fd = 0;
/*
| The kernel's clock ticks per second.
*/
static long clocks_per_sec;
/**
* signal handler
*/
@ -136,6 +143,7 @@ sig_child(int sig) {
// nothing
}
/**
* signal handler
*/
@ -156,6 +164,7 @@ sig_handler( int sig )
}
}
/*
| Non glibc builds need a real tms structure for the times( ) call
*/
@ -166,6 +175,7 @@ sig_handler( int sig )
static struct tms * dummy_tms = &_dummy_tms;
#endif
/*
| Returns the absolute path of a path.
|
@ -191,7 +201,6 @@ get_realpath( const char * rpath )
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
( Logging )
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@ -344,6 +353,7 @@ logstring0(
char ct[ 255 ];
// gets current timestamp hour:minute:second
time_t mtime;
time( &mtime );
strftime( ct, sizeof( ct ), "%T", localtime( &mtime ) );
@ -358,18 +368,21 @@ logstring0(
}
// writes to file if configured so
if (settings.log_file)
if( settings.log_file )
{
FILE * flog = fopen( settings.log_file, "a" );
char * ct;
time_t mtime;
// gets current timestamp day-time-year
time( &mtime );
ct = ctime( &mtime );
// cuts trailing linefeed
ct[ strlen( ct ) - 1] = 0;
ct[ strlen( ct ) - 1] = 0;
if( flog == NULL )
{
@ -378,6 +391,7 @@ logstring0(
"Cannot open logfile [%s]!\n",
settings.log_file
);
exit( -1 );
}
@ -420,7 +434,6 @@ printlogf0(lua_State *L,
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
( Simple memory management )
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@ -596,6 +609,7 @@ pipe_tidy( struct observance * observance )
*/
static int runner;
/*
| Dummy variable of which it's address is used as
| the cores index n the lua registry to
@ -612,9 +626,9 @@ close_exec_fd( int fd )
{
int flags;
flags = fcntl( fd, F_GETFD );
flags = fcntl( fd, F_GETFD );
if( flags == -1 )
if( flags == -1 )
{
logstring( "Error", "cannot get descriptor flags!" );
exit( -1 );
@ -638,9 +652,9 @@ non_block_fd( int fd )
{
int flags;
flags = fcntl( fd, F_GETFL );
flags = fcntl( fd, F_GETFL );
if( flags == -1 )
if( flags == -1 )
{
logstring( "Error", "cannot get status flags!" );
exit( -1 );
@ -1325,36 +1339,56 @@ l_realdir( lua_State *L )
const char *rdir = luaL_checkstring(L, 1);
char *adir = get_realpath(rdir);
if (!adir) {
printlogf(L, "Error", "failure getting absolute path of [%s]", rdir);
if( !adir )
{
printlogf(
L, "Error",
"failure getting absolute path of [%s]",
rdir
);
return 0;
}
{
// makes sure its a directory
struct stat st;
if (stat(adir, &st)) {
printlogf(L, "Error",
"cannot get absolute path of dir '%s': %s", rdir, strerror(errno));
free(adir);
if( stat( adir, &st ) )
{
printlogf(
L, "Error",
"cannot get absolute path of dir '%s': %s",
rdir,
strerror( errno )
);
free( adir );
return 0;
}
if (!S_ISDIR(st.st_mode)) {
printlogf(L, "Error",
"cannot get absolute path of dir '%s': is not a directory", rdir);
free(adir);
if( !S_ISDIR( st.st_mode ) )
{
printlogf(
L, "Error",
"cannot get absolute path of dir '%s': is not a directory",
rdir
);
free( adir );
return 0;
}
}
// returns absolute path with a concated '/'
luaL_buffinit(L, &b);
luaL_addstring(&b, adir);
luaL_addchar(&b, '/');
luaL_pushresult(&b);
luaL_buffinit( L, &b );
luaL_addstring( &b, adir );
luaL_addchar( &b, '/' );
luaL_pushresult( &b );
free( adir );
free(adir);
return 1;
}
@ -1380,35 +1414,43 @@ l_stackdump( lua_State * L )
switch( t )
{
case LUA_TSTRING:
printlogf(
L, "Debug",
"%d string: '%s'",
i, lua_tostring( L, i )
);
break;
case LUA_TBOOLEAN:
printlogf(
L, "Debug",
"%d boolean %s",
i, lua_toboolean( L, i ) ? "true" : "false"
);
break;
case LUA_TNUMBER:
printlogf(
L, "Debug",
"%d number: %g",
i, lua_tonumber( L, i )
);
break;
default:
printlogf(
L, "Debug",
"%d %s",
i, lua_typename( L, t )
);
break;
}
}
@ -1434,6 +1476,7 @@ l_readdir ( lua_State *L )
DIR *d;
d = opendir( dirname );
if( d == NULL )
{
printlogf(
@ -1475,6 +1518,7 @@ l_readdir ( lua_State *L )
strlen( de->d_name ) +
2
);
struct stat st;
strcpy( entry, dirname );
@ -1500,6 +1544,7 @@ l_readdir ( lua_State *L )
}
closedir( d );
return 1;
}
@ -1767,6 +1812,7 @@ l_nonobserve_fd( lua_State *L )
return 0;
}
/*
| The Lsnycd's core library
*/
@ -1785,6 +1831,7 @@ static const luaL_Reg lsyncdlib[] =
{ NULL, NULL }
};
/*
| Adds a number in seconds to a jiffy timestamp.
*/
@ -1817,6 +1864,7 @@ l_jiffies_add( lua_State *L )
}
}
/*
| Subracts two jiffy timestamps resulting in a number in seconds
| or substracts a jiffy by a number in seconds resulting a jiffy timestamp.
@ -1849,6 +1897,7 @@ l_jiffies_sub( lua_State *L )
return 1;
}
/*
| Compares two jiffy timestamps
*/
@ -1863,6 +1912,7 @@ l_jiffies_eq( lua_State *L )
return 1;
}
/*
* True if jiffy1 timestamp is eariler than jiffy2 timestamp
*/
@ -1877,6 +1927,7 @@ l_jiffies_lt( lua_State *L )
return 1;
}
/*
| True if jiffy1 before or equals jiffy2
*/
@ -1971,6 +2022,7 @@ load_runner_func(
lua_remove( L, -2 );
}
/*
| Daemonizes.
|
@ -2338,6 +2390,7 @@ masterloop(lua_State *L)
}
}
/*
| The effective main for one run.
|
@ -2805,6 +2858,7 @@ main1( int argc, char *argv[] )
return 0;
}
/*
| Main
*/

View File

@ -2216,24 +2216,25 @@ local Syncs = ( function( )
--
-- table copy source ( cs )
-- table copy destination ( cd )
-- forced verbatim for e.g. exitcodes ( verbatim )
--
-- All entries with integer keys are inherited as additional
-- sources for non-verbatim tables
--
local function inherit( cd, cs )
local function inherit( cd, cs, verbatim )
-- First copies all entries with non-integer keys.
--
-- First copies all entries with non-integer keys
-- tables are merged, already present keys are not
-- Tables are merged; already present keys are not
-- overwritten
--
-- For verbatim tables integer keys are treated like
-- non integer keys
--
-- non-integer keys
for k, v in pairs( cs ) do
if
(
type( k ) ~= 'number' or
verbatim or
cs._verbatim == true
)
and
@ -2246,10 +2247,8 @@ local Syncs = ( function( )
end
end
--
-- recursevely inherits all integer keyed tables
-- ( for non-verbatim tables )
--
if cs._verbatim ~= true then
local n = nil
@ -2281,12 +2280,12 @@ local Syncs = ( function( )
if dtype == 'nil' then
cd[ k ] = { }
inherit( cd[ k ], v )
inherit( cd[ k ], v, k == 'exitcodes' )
elseif
dtype == 'table' and
v._merge ~= false
then
inherit( cd[ k ], v )
inherit( cd[ k ], v, k == 'exitcodes' )
end
elseif dtype == 'nil' then