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 15-10-2015: 2.1.6
enhancement: Lsyncd now locks its pidfile enhancement: Lsyncd now locks its pidfile
enhancement: added ssh.identifyFile and ssh.options options enhancement: added ssh.identifyFile and ssh.options options

100
lsyncd.c
View File

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

View File

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