diff --git a/CMakeLists.txt b/CMakeLists.txt index cacb952..b3d244f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,8 @@ set( LSYNCD_SRC core/core.c core/log.c core/smem.c - luacode.c + mantle.c + default.c ) # Tell systemd via the sd-daemon library about the status of Lsyncd. @@ -37,12 +38,12 @@ configure_file ( include_directories("${PROJECT_BINARY_DIR}") -# Building and compiling the part of lsyncd written in Lua +# The mantle written in Lua # # Order here matters as the scripts lua will be executed in this order # on initialization of Lsyncd. # -set( LUA_CODE +set( MANTLE_CODE ${PROJECT_SOURCE_DIR}/mantle/array.lua ${PROJECT_SOURCE_DIR}/mantle/counter.lua ${PROJECT_SOURCE_DIR}/mantle/queue.lua @@ -62,28 +63,49 @@ set( LUA_CODE ${PROJECT_SOURCE_DIR}/mantle/user.lua ${PROJECT_SOURCE_DIR}/mantle/string.lua ${PROJECT_SOURCE_DIR}/mantle/version.lua + ${PROJECT_SOURCE_DIR}/mantle/userenv.lua +) + +# The default sync implementations. +# +# Order here matters as the scripts lua will be executed in this order +# on initialization of Lsyncd. +# +set( DEFAULT_CODE ${PROJECT_SOURCE_DIR}/default/default.lua ${PROJECT_SOURCE_DIR}/default/rsync.lua ${PROJECT_SOURCE_DIR}/default/rsyncssh.lua ${PROJECT_SOURCE_DIR}/default/direct.lua - ${PROJECT_SOURCE_DIR}/mantle/userenv.lua ) -# Creates the Lua bytecode from Lua source -add_custom_command( OUTPUT luacode.out - COMMAND ${CMAKE_COMMAND} -E echo "Compiling luacode" - COMMAND ${LUA_COMPILER} -o luacode.out ${LUA_CODE} - DEPENDS ${LUA_CODE} +# Compiling the mantle to Lua bytecode +add_custom_command( OUTPUT mantle.out + COMMAND ${CMAKE_COMMAND} -E echo "Compiling mantle" + COMMAND ${LUA_COMPILER} -o mantle.out ${MANTLE_CODE} + DEPENDS ${MANTLE_CODE} ) -# Transforms the Lua bytecode into c constants +# Compiling the default sync implementations to Lua bytecode +add_custom_command( OUTPUT default.out + COMMAND ${CMAKE_COMMAND} -E echo "Compiling default" + COMMAND ${LUA_COMPILER} -o default.out ${DEFAULT_CODE} + DEPENDS ${DEFAULT_CODE} +) + +# Transforms the Lua bytecode into C constants # It may be possible to use the linker directly to link binary # Code into the resulting ELF-file, but this proofed to be more # portable and easier. -add_custom_command( OUTPUT luacode.c - COMMAND ${CMAKE_COMMAND} -E echo "Generating luacode linkable" - COMMAND ${LUA_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin2carray.lua luacode.out luacode luacode.c - DEPENDS luacode.out +add_custom_command( OUTPUT mantle.c + COMMAND ${CMAKE_COMMAND} -E echo "Generating mantle linkable" + COMMAND ${LUA_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin2carray.lua mantle.out mantle mantle.c + DEPENDS mantle.out +) + +add_custom_command( OUTPUT default.c + COMMAND ${CMAKE_COMMAND} -E echo "Generating default linkable" + COMMAND ${LUA_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin2carray.lua default.out default default.c + DEPENDS default.out ) # The manpage diff --git a/core/core.c b/core/core.c index b55275f..79607d2 100644 --- a/core/core.c +++ b/core/core.c @@ -45,8 +45,14 @@ /* | The Lua part of Lsyncd */ -extern const char luacode_out[]; -extern size_t luacode_size; +extern const char mantle_out[]; +extern size_t mantle_size; + +/* +| The Lua coded default sync implementations +*/ +extern const char default_out[]; +extern size_t default_size; /* | Makes sure there is one file system monitor. @@ -1953,17 +1959,17 @@ main1( int argc, char *argv[] ) printf( "kernels clocks_per_sec=%ld\n", clocks_per_sec ); } - // loads the lsyncd mantle and defaults - if( luaL_loadbuffer( L, luacode_out, luacode_size, "luacode" ) ) + // loads the lsyncd mantle + if( luaL_loadbuffer( L, mantle_out, mantle_size, "mantle" ) ) { - printlogf( L, "Error", "error loading luacode: %s", lua_tostring( L, -1 ) ); + printlogf( L, "Error", "loading mantle: %s", lua_tostring( L, -1 ) ); exit( -1 ); } // prepares the luacode executing the script if( lua_pcall( L, 0, 0, 0 ) ) { - printlogf( L, "Error", "preparing luacode: %s", lua_tostring( L, -1 ) ); + printlogf( L, "Error", "preparing mantle: %s", lua_tostring( L, -1 ) ); exit( -1 ); } @@ -1988,6 +1994,26 @@ main1( int argc, char *argv[] ) lua_pop( L, 1 ); } + // loads the default sync implementations + if( luaL_loadbuffer( L, default_out, default_size, "default" ) ) + { + printlogf( L, "Error", + "loading default sync implementations: %s", lua_tostring( L, -1 ) ); + exit( -1 ); + } + + // loads the user enivornment + // the default sync implementations are actually not priviledged in any way + lua_getglobal( L, "userENV" ); + lua_setupvalue( L, -2, 1 ); + + // prepares the default sync implementations + if( lua_pcall( L, 0, 0, 0 ) ) + { + printlogf( L, "Error", + "preparing default sync implementations: %s", lua_tostring( L, -1 ) ); + exit( -1 ); + } // checks if there is a "-help" or "--help" { diff --git a/core/smem.c b/core/smem.c index f2847fc..8cc0874 100644 --- a/core/smem.c +++ b/core/smem.c @@ -19,8 +19,11 @@ #include #include -#include "lsyncd.h" +#include +#include "lsyncd.h" +#include "smem.h" +#include "log.h" /* | "Secured" calloc diff --git a/default/rsync.lua b/default/rsync.lua index 5ca1b92..6feb81c 100644 --- a/default/rsync.lua +++ b/default/rsync.lua @@ -624,7 +624,6 @@ rsync.prepare = function end end - -- -- By default do deletes. -- @@ -647,7 +646,6 @@ rsync.rsync = protect_args = true } - -- -- Default delay -- diff --git a/mantle/mci.lua b/mantle/mci.lua index 81d8e62..5cd6c23 100644 --- a/mantle/mci.lua +++ b/mantle/mci.lua @@ -38,22 +38,6 @@ readdir = core.readdir processCount = 0 --- --- All valid entries in a settings{} call. --- -local settingsCheckgauge = -{ - logfile = true, - statusFile = true, - statusInterval = true, - logfacility = true, - logident = true, - inotifyMode = true, - maxProcesses = true, - maxDelays = true, -} - - -- -- Settings specified by command line. -- @@ -455,7 +439,7 @@ function mci.initialize( firstTime ) -- if uSettings.statusInterval == nil then - uSettings.statusInterval = default.statusInterval + uSettings.statusInterval = userENV.default.statusInterval end -- makes sure the user gave Lsyncd anything to do diff --git a/mantle/syncmaster.lua b/mantle/syncmaster.lua index 3f3c56c..88b1b6c 100644 --- a/mantle/syncmaster.lua +++ b/mantle/syncmaster.lua @@ -199,10 +199,8 @@ local function add inherit( config, uconfig ) - -- -- last and least defaults are inherited - -- - inherit( config, default ) + inherit( config, userENV.default ) local inheritSettings = { diff --git a/mantle/user.lua b/mantle/user.lua index ea4123d..d2a0d96 100644 --- a/mantle/user.lua +++ b/mantle/user.lua @@ -178,6 +178,23 @@ end alarm = UserAlarms.alarm +-- +-- All valid entries in a settings{} call. +-- +local settingsCheckgauge = +{ + logfile = true, + statusFile = true, + statusInterval = true, + logfacility = true, + logident = true, + inotifyMode = true, + maxProcesses = true, + maxDelays = true, +} + + + -- -- The settings call -- diff --git a/mantle/userenv.lua b/mantle/userenv.lua index 9c227f7..b65485b 100644 --- a/mantle/userenv.lua +++ b/mantle/userenv.lua @@ -4,6 +4,9 @@ -- -- Setups up the global environment for a user script. -- +-- The default sync implementations will add the 'default' global +-- to this. They are loaded in user context, so they can simply set it. +-- -- -- License: GPLv2 (see COPYING) or any later version -- Authors: Axel Kittenberger @@ -49,7 +52,6 @@ userENV = -- lsyncd mantle available to user scripts Array = Array, Queue = Queue, - default = default, settings = settings, spawn = spawn, spawnShell = spawnShell,