This commit is contained in:
Axel Kittenberger 2010-11-05 18:04:29 +00:00
parent 27b73038eb
commit 081c20dc33
3 changed files with 75 additions and 82 deletions

View File

@ -31,7 +31,7 @@ slowbash = {
local source = config.source .. event.pathbasename local source = config.source .. event.pathbasename
local target = config.target .. event.pathbasename local target = config.target .. event.pathbasename
log("Normal", "create from ", source, " -> ", target) log("Normal", "create from ", source, " -> ", target)
return shell(prefix..[[cp "$1" "$2"]], source, target) return shell(prefix..[[cp -r "$1" "$2"]], source, target)
end, end,
onModify = function(config, event) onModify = function(config, event)
@ -39,14 +39,14 @@ slowbash = {
local source = config.source .. event.pathbasename local source = config.source .. event.pathbasename
local target = config.target .. event.pathbasename local target = config.target .. event.pathbasename
log("Normal", "modify from ", source, " -> ", target) log("Normal", "modify from ", source, " -> ", target)
return shell(prefix..[[cp "$1" "$2"]], source, target) return shell(prefix..[[cp -r "$1" "$2"]], source, target)
end, end,
onDelete = function(config, event) onDelete = function(config, event)
-- similar for deletes -- similar for deletes
local target = config.target .. event.pathbasename local target = config.target .. event.pathbasename
log("Normal", "delete ", target) log("Normal", "delete ", target)
return shell(prefix..[[rm "$1"]], target) return shell(prefix..[[rm -rf "$1"]], target)
end, end,
} }

View File

@ -346,6 +346,7 @@ printlogf0(lua_State *L,
lua_pop(L, 1); lua_pop(L, 1);
return; return;
} }
/***************************************************************************** /*****************************************************************************
* Simple memory management * Simple memory management
****************************************************************************/ ****************************************************************************/
@ -563,6 +564,19 @@ l_exec(lua_State *L)
int i; int i;
char const **argv = s_calloc(argc + 2, sizeof(char *)); char const **argv = s_calloc(argc + 2, sizeof(char *));
if (check_logcat("Exec") >= settings.log_level) {
lua_pushvalue(L, 1);
for(i = 1; i <= argc; i++) {
lua_pushstring(L, " [");
lua_pushvalue(L, i + 1);
lua_pushstring(L, "]");
}
lua_concat(L, 3 * argc + 1);
logstring0(LOG_DEBUG, "Exec", luaL_checkstring(L, -1));
lua_pop(L, 1);
}
argv[0] = binary; argv[0] = binary;
for(i = 1; i <= argc; i++) { for(i = 1; i <= argc; i++) {
argv[i] = luaL_checkstring(L, i + 1); argv[i] = luaL_checkstring(L, i + 1);
@ -1180,38 +1194,11 @@ masterloop(lua_State *L)
lua_pop(L, 1); lua_pop(L, 1);
} }
/* writes status of lsyncd in a file */ /* lets the runner do stuff every cycle,
/* this is not a real loop, it will only be runned once max. * like starting new processes, writing the statusfile etc. */
* this is just using break as comfortable jump down. */ printlogf(L, "Call", "lsyncd_cycle()");
while (settings.statusfile) {
int fd = open(settings.statusfile,
O_WRONLY | O_CREAT | O_TRUNC, 0664);
if (fd < 0) {
printlogf(L, "Error",
"Cannot open statusfile '%s' for writing.",
settings.statusfile);
break;
}
/* calls the lua runner to write the status. */
printlogf(L, "Call", "lysncd_status_report()");
lua_getglobal(L, "lsyncd_call_error");
lua_getglobal(L, "lsyncd_status_report");
lua_pushinteger(L, fd);
if (lua_pcall(L, 1, 0, -3)) {
exit(-1); // ERRNO
}
lua_pop(L, 1);
/* TODO */
fsync(fd);
close(fd);
break;
}
/* lets the runner spawn new processes */
printlogf(L, "Call", "lsyncd_alarm()");
lua_getglobal(L, "lsyncd_call_error"); lua_getglobal(L, "lsyncd_call_error");
lua_getglobal(L, "lsyncd_alarm"); lua_getglobal(L, "lsyncd_cycle");
lua_pushinteger(L, times(NULL)); lua_pushinteger(L, times(NULL));
if (lua_pcall(L, 1, 0, -3)) { if (lua_pcall(L, 1, 0, -3)) {
exit(-1); // ERRNO exit(-1); // ERRNO

View File

@ -416,44 +416,36 @@ local Inotifies = (function()
----- -----
-- Adds watches for a directory including all subdirectories. -- Adds watches for a directory including all subdirectories.
-- --
-- @param root root directory to observer -- @param root+path directory to observe
-- @param origin link to the observer to be notified. -- @param recurse true if recursing into subdirs or
-- Note: Inotifies should handle this opaquely -- the relative path to root for recursed inotifies
-- @param recurse true if recursing into subdirs -- @param origin link to the observer to be notified.
-- or the relative path to root for recurse -- Note: Inotifies should handle this opaquely
-- local function add(root, path, recurse, origin)
local function add(root, origin, recurse) log("Function",
log("Function", "Inotifies.add(", root, ", ", origin, ", ", recurse, ")") "Inotifies.add(",root,", ",path,", ",recurse,", ",origin,")")
-- register watch and receive watch descriptor -- registers watch
local dir local wd = lsyncd.add_watch(root .. path);
if type(recurse) == "string" then
dir = root..recurse
else
dir = root
if recurse then
recurse = ""
end
end
local wd = lsyncd.add_watch(dir);
if wd < 0 then if wd < 0 then
-- failed adding the watch log("Error","Failure adding watch ",dir," -> ignored ")
log("Error", "Failure adding watch ", dir, " -> ignored ")
return return
end end
local ilist = wdlist[wd] if not wdlist[wd] then
if not ilist then wdlist[wd] = Array.new()
ilist = Array.new()
wdlist[wd] = ilist
end end
local inotify = { root = root, path = recurse, origin = origin } table.insert(wdlist[wd], {
table.insert(ilist, inotify) root = root,
path = path,
recurse = recurse,
origin = origin
})
-- registers and adds watches for all subdirectories -- registers and adds watches for all subdirectories
if recurse then if recurse then
local subdirs = lsyncd.sub_dirs(dir) local subdirs = lsyncd.sub_dirs(root .. path)
for _, dirname in ipairs(subdirs) do for _, dirname in ipairs(subdirs) do
add(root, origin, recurse..dirname.."/") add(root, path..dirname.."/", true, origin)
end end
end end
end end
@ -503,7 +495,7 @@ local Inotifies = (function()
-- adds subdirs for new directories -- adds subdirs for new directories
if inotify.recurse and isdir then if inotify.recurse and isdir then
if ename == "Create" then if ename == "Create" then
add(inotify.root, inotify.origin, pathname) add(inotify.root, pathname, true, inotify.origin)
elseif ename == "Delete" then elseif ename == "Delete" then
-- TODO -- TODO
end end
@ -514,15 +506,16 @@ local Inotifies = (function()
----- -----
-- Writes a status report about inotifies to a filedescriptor -- Writes a status report about inotifies to a filedescriptor
-- --
local function status_report(fd) local function status_report(f)
local w = lsyncd.writefd f:write("Watching ",wdlist:size()," directories\n")
w(fd, "Watching ", wdlist:size(), " directories\n")
for wd, v in wdlist:iwalk() do for wd, v in wdlist:iwalk() do
w(fd, " ", wd, ": ") f:write(" ",wd,": ")
local sep = ""
for _, v in ipairs(v) do for _, v in ipairs(v) do
w(fd, "(", v.root, "/", (v.path) or ")") f:write(v.root,"/",v.path or "",sep)
sep = ", "
end end
w(fd, "\n") f:write("\n")
end end
end end
@ -629,7 +622,7 @@ local Inlet, inlet_control = (function()
pathbasename = function() pathbasename = function()
if string.byte(delay.pathname, -1) == 47 then if string.byte(delay.pathname, -1) == 47 then
return string.sub(delay.pathname, 1, -1) return string.sub(delay.pathname, 1, -2)
else else
return delay.pathname return delay.pathname
end end
@ -702,21 +695,34 @@ end
---- ----
-- Called from core to get a status report written into a file descriptor -- Called from core to get a status report written into a file descriptor
-- --
function lsyncd_status_report(fd) local function write_statusfile()
local w = lsyncd.writefd local f, err = io.open(settings.statusfile, "w")
w(fd, "Lsyncd status report at ", os.date(), "\n\n") if not f then
Inotifies.status_report(fd) log("Error", "Cannot open statusfile '"..settings.statusfile..
"' :"..err)
return
end
f:write("Lsyncd status report at ", os.date(), "\n\n")
Inotifies.status_report(f)
f:close()
end end
---- ----
-- Called from core everytime at the latest of an -- Called from core everytime a masterloop cycle runs through.
-- expired alarm (or more often) -- This happens in case of
-- * an expired alarm.
-- * a returned child process.
-- * received inotify events.
-- * received a HUP or TERM signal.
-- --
-- @param now the time now -- @param now the current kernel time (in jiffies)
-- --
function lsyncd_alarm(now) function lsyncd_cycle(now)
-- goes through all targets and spawns more actions -- goes through all targets and spawns more actions
-- if possible -- if possible
if settings.statusfile then
write_statusfile()
end
for _, o in Origins.iwalk() do for _, o in Origins.iwalk() do
if o.processes:size() < o.config.max_processes then if o.processes:size() < o.config.max_processes then
local delays = o.delays local delays = o.delays
@ -856,7 +862,7 @@ function lsyncd_initialize()
have_startup = true have_startup = true
end end
-- adds the dir watch inclusively all subdirs -- adds the dir watch inclusively all subdirs
Inotifies.add(o.source, o, true) Inotifies.add(o.source, "", true, o)
end end
-- from now on use logging as configured instead of stdout/err. -- from now on use logging as configured instead of stdout/err.
@ -904,7 +910,7 @@ function lsyncd_get_alarm()
end end
end end
end end
log("Debug", "lysncd_get_alarm returns: ", have_alarm, ", ", alarm) log("Debug", "lysncd_get_alarm returns: ",have_alarm,", ",alarm)
return have_alarm, alarm return have_alarm, alarm
end end