Skip to content

Commit

Permalink
adding -p to cp for default.direct. Put a log message before daemoniz…
Browse files Browse the repository at this point in the history
…ing to test logging. Fix a crash for default.direct
  • Loading branch information
axkibe committed Dec 2, 2016
1 parent c58658e commit b79defa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Expand Up @@ -8,17 +8,22 @@
"omit_dir_times"
"omit_link_times",
enhancement: settings{ } now checks for unknown entries and errors if so.
change: Lsyncd now writes a startup log message before daemonizing
does in case logging fails, it is recognized before it cannot
message anything about it, since it deamonized
change: compatible with Lua5.3 (along with 5.1 and 5.2)
change: _verbatim forced for 'exitcodes' entry.
change: manpage is not rebuild by default.
it is provided precompiled.
change:
faulty/deprecated config files that use settings = { ... }, with equal sign
are no longer worked around.
change: default.direct now calls copy with -p
fix: ']' is not escaped for rsync rules, since rsync only applies
doesn't applie pattern matching if no other pattern chars
are found.
fix: Shell injection hole close for default.direct on mv commands. (Marcin Szewczyk)
fix: Crash of default-direct when source doesn't exit (Michael Ploujnikov)

15-10-2015: 2.1.6
enhancement: Lsyncd now locks its pidfile
Expand Down
8 changes: 6 additions & 2 deletions default-direct.lua
Expand Up @@ -70,6 +70,7 @@ direct.action = function(inlet)
spawn(
event,
'/bin/cp',
'-p',
'--',
event.sourcePath,
event.targetPathdir
Expand All @@ -81,6 +82,7 @@ direct.action = function(inlet)
end
spawn(event,
'/bin/cp',
'-p',
'--',
event.sourcePath,
event.targetPathdir
Expand Down Expand Up @@ -145,8 +147,10 @@ direct.collect = function(agent, exitcode)
local rc = config.rsyncExitCodes[exitcode]
if rc == 'ok' then
log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
elseif rc == 'again' then
if settings.insist then
elseif rc == 'again'
then
if settings( 'insist' )
then
log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode)
else
log('Error', 'Temporary or permanent failure on startup of "',
Expand Down
35 changes: 18 additions & 17 deletions lsyncd.c
Expand Up @@ -1605,22 +1605,27 @@ l_configure( lua_State *L )
settings.log_syslog = true;

const char * log_ident =
settings.log_ident ?
settings.log_ident :
"lsyncd";
settings.log_ident
? settings.log_ident
: "lsyncd";

openlog( log_ident, 0, settings.log_facility );
}

if( settings.pidfile )
{
write_pidfile( L, settings.pidfile );
}

if( !settings.nodaemon && !is_daemon )
{
logstring( "Debug", "daemonizing now." );
logstring( "Normal", "--- Startup, daemonizing ---" );

daemonize( L );
}

if( settings.pidfile )
else
{
write_pidfile( L, settings.pidfile );
logstring( "Normal", "--- Startup ---" );
}

}
Expand Down Expand Up @@ -1649,8 +1654,7 @@ l_configure( lua_State *L )
free( settings.pidfile );
}

settings.pidfile =
s_strdup( file );
settings.pidfile = s_strdup( file );
}
else if( !strcmp( command, "logfacility" ) )
{
Expand Down Expand Up @@ -1694,8 +1698,10 @@ l_configure( lua_State *L )
{
const char * ident = luaL_checkstring( L, 2 );

if (settings.log_ident)
{ free(settings.log_ident); }
if( settings.log_ident )
{
free( settings.log_ident );
}

settings.log_ident = s_strdup( ident );
}
Expand Down Expand Up @@ -2423,6 +2429,7 @@ main1( int argc, char *argv[] )

// load Lua
L = luaL_newstate( );

luaL_openlibs( L );
{
// checks the lua version
Expand Down Expand Up @@ -2500,7 +2507,6 @@ main1( int argc, char *argv[] )
// registers Lsycnd's core library
register_lsyncd( L );


if( check_logcat( "Debug" ) <= settings.log_level )
{
// printlogf doesnt support %ld :-(
Expand Down Expand Up @@ -2658,7 +2664,6 @@ main1( int argc, char *argv[] )
}
}


// checks if there is a "-help" or "--help"
{
int i;
Expand Down Expand Up @@ -2786,15 +2791,11 @@ main1( int argc, char *argv[] )
}

#ifdef WITH_INOTIFY

open_inotify( L );

#endif

#ifdef WITH_FSEVENTS

open_fsevents( L );

#endif

// adds signal handlers
Expand Down
20 changes: 10 additions & 10 deletions lsyncd.lua
Expand Up @@ -836,7 +836,7 @@ local InletFactory = ( function( )
return e2d[ event ].sync.config
end,

-----
--
-- Returns the inlet belonging to an event.
--
inlet = function( event )
Expand Down Expand Up @@ -893,7 +893,7 @@ local InletFactory = ( function( )
return string.match( getPath( event ), '([^/]+)/?$')
end,

---
--
-- Returns the file/dir relative to watch root
-- including a trailing slash for dirs.
--
Expand All @@ -917,7 +917,7 @@ local InletFactory = ( function( )
return cutSlash( getPath( event ) )
end,

---
--
-- Returns the absolute path of the watch root.
-- All symlinks are resolved.
--
Expand All @@ -942,7 +942,7 @@ local InletFactory = ( function( )
( string.match( getPath( event ), '^(.*/)[^/]+/?' ) or '' )
end,

------
--
-- Returns the absolute path of the file/dir
-- excluding a trailing slash for dirs.
--
Expand Down Expand Up @@ -1383,7 +1383,7 @@ local Excludes = ( function( )
end


-----
--
-- Adds a list of patterns to exclude.
--
local function addList(self, plist)
Expand Down Expand Up @@ -2044,7 +2044,7 @@ local Sync = ( function( )

end

------
--
-- Adds and returns a blanket delay thats blocks all.
-- Used as custom marker.
--
Expand Down Expand Up @@ -2475,7 +2475,7 @@ local Syncs = ( function( )
terminate( -1 )
end

--- creates the new sync
-- creates the new sync
local s = Sync.new( config )

table.insert( syncsList, s )
Expand Down Expand Up @@ -4436,8 +4436,8 @@ function spawnShell(
)
end

-----
-- Observes a filedescriptor
--
-- Observes a filedescriptor.
--
function observefd(
fd, -- file descriptor
Expand All @@ -4452,7 +4452,7 @@ function observefd(
end

--
-- Stops observeing a filedescriptor
-- Stops observeing a filedescriptor.
--
function nonobservefd(
fd -- file descriptor
Expand Down

0 comments on commit b79defa

Please sign in to comment.