mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-15 14:42:23 +00:00
moving default sync configs to userENV
This commit is contained in:
parent
3b24bfded2
commit
a057e14c7f
|
@ -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
|
||||
|
|
38
core/core.c
38
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"
|
||||
{
|
||||
|
|
|
@ -19,8 +19,11 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#include "lsyncd.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "lsyncd.h"
|
||||
#include "smem.h"
|
||||
#include "log.h"
|
||||
|
||||
/*
|
||||
| "Secured" calloc
|
||||
|
|
|
@ -624,7 +624,6 @@ rsync.prepare = function
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- By default do deletes.
|
||||
--
|
||||
|
@ -647,7 +646,6 @@ rsync.rsync =
|
|||
protect_args = true
|
||||
}
|
||||
|
||||
|
||||
--
|
||||
-- Default delay
|
||||
--
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 =
|
||||
{
|
||||
|
|
|
@ -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
|
||||
--
|
||||
|
|
|
@ -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 <axkibe@gmail.com>
|
||||
|
@ -49,7 +52,6 @@ userENV =
|
|||
-- lsyncd mantle available to user scripts
|
||||
Array = Array,
|
||||
Queue = Queue,
|
||||
default = default,
|
||||
settings = settings,
|
||||
spawn = spawn,
|
||||
spawnShell = spawnShell,
|
||||
|
|
Loading…
Reference in New Issue
Block a user