This commit is contained in:
Axel Kittenberger 2010-11-02 17:07:42 +00:00
parent 20f24018dc
commit 39472fd48e
2 changed files with 48 additions and 69 deletions

View File

@ -383,6 +383,10 @@ l_log(lua_State *L)
if ((level & 0x0F) < settings.loglevel) { if ((level & 0x0F) < settings.loglevel) {
return 0; return 0;
} }
/* concates if there is more than one string parameter */
lua_concat(L, lua_gettop(L) - 1);
message = luaL_checkstring(L, 2); message = luaL_checkstring(L, 2);
logstring0(level, message); logstring0(level, message);
return 0; return 0;
@ -640,8 +644,12 @@ int
l_writefd(lua_State *L) l_writefd(lua_State *L)
{ {
int fd = luaL_checkinteger(L, 1); int fd = luaL_checkinteger(L, 1);
const char *s = luaL_checkstring(L, 2); /* concates if there is more than one string parameter */
write(fd, s, strlen(s)); lua_concat(L, lua_gettop(L) - 1);
{
const char *s = luaL_checkstring(L, 2);
write(fd, s, strlen(s));
}
return 0; return 0;
} }

View File

@ -57,7 +57,7 @@ local Array = (function()
end end
-- creates a new object -- creates a new object
local new = function() local function new()
local o = {} local o = {}
setmetatable(o, mt) setmetatable(o, mt)
return o return o
@ -105,12 +105,12 @@ local CountArray = (function()
end end
-- TODO -- TODO
local iwalk = function(self) local function iwalk(self)
return ipairs(self[k_nt]) return ipairs(self[k_nt])
end end
-- creates a new count array -- creates a new count array
local new = function() local function new()
-- k_nt is native table, private for this object. -- k_nt is native table, private for this object.
local o = {size = 0, iwalk = iwalk, [k_nt] = {} } local o = {size = 0, iwalk = iwalk, [k_nt] = {} }
setmetatable(o, mt) setmetatable(o, mt)
@ -186,7 +186,7 @@ local Delay = (function()
-- Creates a new delay. -- Creates a new delay.
-- --
-- @param TODO -- @param TODO
local new = function(ename, pathname, alarm) local function new(ename, pathname, alarm)
local o = { local o = {
ename = ename, ename = ename,
alarm = alarm, alarm = alarm,
@ -205,7 +205,7 @@ local Origin = (function()
---- ----
-- TODO -- TODO
-- --
local new = function(source, targetident, config) local function new(source, targetident, config)
local o = { local o = {
config = config, config = config,
delays = CountArray.new(), delays = CountArray.new(),
@ -225,7 +225,7 @@ end)()
-- Puts an action on the delay stack. -- Puts an action on the delay stack.
-- --
function Origin.delay(origin, ename, time, pathname, pathname2) function Origin.delay(origin, ename, time, pathname, pathname2)
log(DEBUG, "delay "..ename.." "..pathname) log(DEBUG, "delay ", ename, " ", pathname)
local o = origin local o = origin
local delays = o.delays local delays = o.delays
local delayname = o.delayname local delayname = o.delayname
@ -255,26 +255,25 @@ function Origin.delay(origin, ename, time, pathname, pathname2)
if newd.ename == "MoveFrom" or newd.ename == "MoveTo" or if newd.ename == "MoveFrom" or newd.ename == "MoveTo" or
oldd.ename == "MoveFrom" or oldd.ename == "MoveTo" then oldd.ename == "MoveFrom" or oldd.ename == "MoveTo" then
-- do not collapse moves -- do not collapse moves
log(NORMAL, "Not collapsing events with moves on "..pathname) log(NORMAL, "Not collapsing events with moves on ", pathname)
-- TODO stackinfo -- TODO stackinfo
return return
else else
local col = o.config.collapse_table[oldd.ename][newd.ename] local col = o.config.collapse_table[oldd.ename][newd.ename]
if col == -1 then if col == -1 then
-- events cancel each other -- events cancel each other
log(NORMAL, "Nullfication: " ..newd.ename.." after ".. log(NORMAL, "Nullfication: ", newd.ename, " after ",
oldd.ename.." on "..pathname) oldd.ename, " on ", pathname)
oldd.ename = "None" oldd.ename = "None"
return return
elseif col == 0 then elseif col == 0 then
-- events tack -- events tack
log(NORMAL, "Stacking " ..newd.ename.." after ".. log(NORMAL, "Stacking ", newd.ename, " after ",
oldd.ename.." on "..pathname) oldd.ename, " on ", pathname)
-- TODO Stack pointer -- TODO Stack pointer
else else
log(NORMAL, "Collapsing "..newd.ename.." upon ".. log(NORMAL, "Collapsing ", newd.ename, " upon ",
oldd.ename.." to " .. oldd.ename, " to ", col, " on ", pathname)
col.." on "..pathname)
oldd.ename = col oldd.ename = col
return return
end end
@ -296,11 +295,11 @@ local Origins = (function()
local list = Array.new() local list = Array.new()
-- adds a configuration -- adds a configuration
local add = function(source, targetident, config) local function add(source, targetident, config)
-- absolute path of source -- absolute path of source
local real_src = lsyncd.real_dir(source) local real_src = lsyncd.real_dir(source)
if not real_src then if not real_src then
log(Error, "Cannot resolve source path: " .. source) log(Error, "Cannot resolve source path: ", source)
terminate(-1) -- ERRNO terminate(-1) -- ERRNO
end end
@ -321,7 +320,7 @@ local Origins = (function()
end end
-- allows to walk through all origins -- allows to walk through all origins
local iwalk = function() local function iwalk()
return ipairs(list) return ipairs(list)
end end
@ -334,31 +333,6 @@ local Origins = (function()
return {add = add, iwalk = iwalk, size = size} return {add = add, iwalk = iwalk, size = size}
end)() end)()
----
-- origins
--
-- table of all root directories to sync.
-- filled during initialization.
--
-- [#] {
-- config = config,
-- source = source_dir,
-- targetident = the identifier of target (like string "host:dir")
-- for lsyncd this passed competly opaquely to the
-- action handlers
--
-- .processes = [pid] .. a sublist of processes[] for this target
-- .delays = [#) { .. the delays stack
-- .ename .. enum, kind of action
-- .alarm .. when it should fire
-- .pathname .. complete path relativ to watch origin
-- (.movepeer) .. for MOVEFROM/MOVETO link to other delay
-- }
-- .delayname[pathname] = [#] .. a list of lists of all delays from a
-- its pathname.
-- }
--
----- -----
-- inotifies -- inotifies
-- --
@ -410,7 +384,7 @@ local function inotify_watch_dir(origin, path)
local wd = lsyncd.add_watch(op); local wd = lsyncd.add_watch(op);
if wd < 0 then if wd < 0 then
-- failed adding the watch -- failed adding the watch
log(ERROR, "Failure adding watch "..op.." -> ignored ") log(ERROR, "Failure adding watch ", op, " -> ignored ")
return return
end end
@ -453,10 +427,9 @@ function lsyncd_collect_process(pid, exitcode)
if not delay then if not delay then
return return
end end
log(DEBUG, "collected "..pid..": ".. log(DEBUG, "collected ", pid, ": ",
delay.ename.." of ".. delay.ename, " of ", origin.source, delay.pathname,
origin.source..delay.pathname.. " = ", exitcode)
" = "..exitcode)
origin.processes[pid] = nil origin.processes[pid] = nil
end end
@ -515,12 +488,12 @@ end
-- --
function lsyncd_status_report(fd) function lsyncd_status_report(fd)
local w = lsyncd.writefd local w = lsyncd.writefd
w(fd, "Lsyncd status report at "..os.date().."\n\n") w(fd, "Lsyncd status report at ", os.date(), "\n\n")
w(fd, "Watching "..inotifies.size.." directories\n") w(fd, "Watching ", inotifies.size, " directories\n")
for wd, v in inotifies:iwalk() do for wd, v in inotifies:iwalk() do
w(fd, " "..wd..": ") w(fd, " ", wd, ": ")
for _, inotify in ipairs(v) do for _, inotify in ipairs(v) do
w(fd, "("..inotify.origin.source.."|"..(inotify.path) or ")..") w(fd, "(", inotify.origin.source, "/", (inotify.path) or ")")
end end
w(fd, "\n") w(fd, "\n")
end end
@ -576,7 +549,7 @@ function lsyncd_initialize(args)
for i = 1, #args do for i = 1, #args do
local a = args[i] local a = args[i]
if a:sub(1, 1) ~= "-" then if a:sub(1, 1) ~= "-" then
log(ERROR, "Unknown option "..a.. log(ERROR, "Unknown option ", a,
". Options must start with '-' or '--'.") ". Options must start with '-' or '--'.")
os.exit(-1) -- ERRNO os.exit(-1) -- ERRNO
end end
@ -594,7 +567,7 @@ function lsyncd_initialize(args)
function(param) function(param)
if not (param == DEBUG or param == NORMAL or if not (param == DEBUG or param == NORMAL or
param == VERBOSE or param == ERROR) then param == VERBOSE or param == ERROR) then
log(ERROR, "unknown settings.loglevel '"..param.."'") log(ERROR, "unknown settings.loglevel '", param, "'")
terminate(-1); -- ERRNO terminate(-1); -- ERRNO
end end
end}, end},
@ -605,11 +578,11 @@ function lsyncd_initialize(args)
for c, p in pairs(settings) do for c, p in pairs(settings) do
local cs = configure_settings[c] local cs = configure_settings[c]
if not cs then if not cs then
log(ERROR, "unknown setting '"..c.."'") log(ERROR, "unknown setting '", c, "'")
terminate(-1) -- ERRNO terminate(-1) -- ERRNO
end end
if cs[1] == 1 and not p then if cs[1] == 1 and not p then
log(ERROR, "setting '"..c.."' needs a parameter") log(ERROR, "setting '", c, "' needs a parameter")
end end
-- calls the check function if its not nil -- calls the check function if its not nil
if cs[2] then if cs[2] then
@ -633,7 +606,7 @@ function lsyncd_initialize(args)
local asrc = lsyncd.real_dir(o.source) local asrc = lsyncd.real_dir(o.source)
local config = o.config local config = o.config
if not asrc then if not asrc then
log(Error, "Cannot resolve source path: " .. o.source) log(Error, "Cannot resolve source path: ", o.source)
terminate(-1) -- ERRNO terminate(-1) -- ERRNO
end end
o.source = asrc o.source = asrc
@ -672,11 +645,11 @@ function lsyncd_initialize(args)
end end
end end
lsyncd.wait_pids(pids, "startup_collector") lsyncd.wait_pids(pids, "startup_collector")
log(NORMAL, "--- Entering normal operation with ".. log(NORMAL, "- Entering normal operation with ",
inotifies.size.." monitored directories ---") inotifies.size, " monitored directories -")
else else
log(NORMAL, "--- Warmstart into normal operation with ".. log(NORMAL, "- Warmstart into normal operation with ",
inotifies.size.." monitored directories ---") inotifies.size, " monitored directories -")
end end
end end
@ -720,13 +693,11 @@ function lsyncd_inotify_event(ename, wd, isdir, time, filename, filename2)
else else
ftype = "file" ftype = "file"
end end
-- TODO comment out to safe performance
if filename2 then if filename2 then
log(DEBUG, "got event "..ename.. log(DEBUG, "got event ", ename, " of ", ftype, " ", filename,
" of "..ftype.." "..filename.." to "..filename2) " to ", filename2)
else else
log(DEBUG, "got event "..ename.. log(DEBUG, "got event ", ename, " of ", ftype, " ", filename)
" of "..ftype.." "..filename)
end end
-- looks up the watch descriptor id -- looks up the watch descriptor id
@ -805,14 +776,14 @@ local default_rsync = {
---- ----
-- Called for every sync/target pair on startup -- Called for every sync/target pair on startup
startup = function(source, target) startup = function(source, target)
log(NORMAL, "startup recursive rsync: "..source.." -> "..target) log(NORMAL, "startup recursive rsync: ", source, " -> ", target)
return exec("/usr/bin/rsync", "-ltrs", return exec("/usr/bin/rsync", "-ltrs",
source, target) source, target)
end, end,
default = function(source, target, path) default = function(source, target, path)
return exec("/usr/bin/rsync", "--delete", "-ltds", return exec("/usr/bin/rsync", "--delete", "-ltds",
source.."/".. path, target .. "/" .. path) source.."/"..path, target.."/"..path)
end end
} }