This commit is contained in:
Axel Kittenberger 2010-11-03 15:23:36 +00:00
parent 78d9660c8b
commit f8b3c825b4
2 changed files with 38 additions and 21 deletions

View File

@ -188,9 +188,14 @@ static char * s_strdup(const char *src);
* Logging
****************************************************************************/
/**
* if true logs everything
*/
bool logall = true;
/* core logs with CORE flag */
#define logstring(cat, message) \
{int p; if ((p = check_logcat(cat)) >= 0) \
{int p; if ((p = check_logcat(cat)) >= 0 || logall) \
{logstring0(p, cat, message); }}
static void
@ -201,7 +206,7 @@ printlogf0(lua_State *L,
...)
__attribute__((format(printf, 4, 5)));
#define printlogf(L, cat, ...) \
{int p; if ((p = check_logcat(cat)) >= 0) \
{int p; if ((p = check_logcat(cat)) >= 0 || logall) \
{printlogf0(L, p, cat, __VA_ARGS__);}}
/**
@ -287,6 +292,10 @@ add_logcat(const char *name, int priority)
static void
logstring0(int priority, const char *cat, const char *message)
{
/* in case of logall and not found category priority will be -1 */
if (priority < 0) {
priority = LOG_DEBUG;
}
if (!running) {
/* lsyncd is in intial configuration.
* thus just print to normal stdout/stderr. */
@ -803,7 +812,7 @@ l_wait_pids(lua_State *L)
lua_getglobal(L, collector);
lua_pushinteger(L, wp);
lua_pushinteger(L, exitcode);
printlogf(L, "Debug", "calling startup collector");
printlogf(L, "Call", "startup collector");
lua_call(L, 2, 1);
newp = luaL_checkinteger(L, -1);
lua_pop(L, 1);
@ -933,7 +942,7 @@ void handle_event(lua_State *L, struct inotify_event *event) {
if (event && (IN_Q_OVERFLOW & event->mask)) {
/* and overflow happened, lets runner/user decide what to do. */
lua_getglobal(L, "overflow");
printlogf(L, "Call", "calling overflow()");
printlogf(L, "Call", "overflow()");
lua_call(L, 0, 0);
return;
}
@ -1020,7 +1029,7 @@ void handle_event(lua_State *L, struct inotify_event *event) {
lua_pushstring(L, event->name);
lua_pushnil(L);
}
printlogf(L, "Call", "calling lysncd_inotify_event()");
printlogf(L, "Call", "lysncd_inotify_event()");
lua_call(L, 6, 0);
/* if there is a buffered event executes it */
@ -1046,7 +1055,7 @@ masterloop(lua_State *L)
/* query runner about soonest alarm */
lua_getglobal(L, "lsyncd_get_alarm");
printlogf(L, "Call", "calling lsycnd_get_alarm()");
printlogf(L, "Call", "lsycnd_get_alarm()");
lua_call(L, 0, 2);
have_alarm = lua_toboolean(L, -2);
alarm_time = (clock_t) luaL_checkinteger(L, -1);
@ -1137,7 +1146,7 @@ masterloop(lua_State *L)
lua_getglobal(L, "lsyncd_collect_process");
lua_pushinteger(L, pid);
lua_pushinteger(L, WEXITSTATUS(status));
printlogf(L, "Call", "calling lsyncd_collect_process().");
printlogf(L, "Call", "lsyncd_collect_process()");
lua_call(L, 2, 0);
}
@ -1157,7 +1166,7 @@ masterloop(lua_State *L)
lua_getglobal(L, "lsyncd_call_error");
lua_getglobal(L, "lsyncd_status_report");
lua_pushinteger(L, fd);
printlogf(L, "Call", "calling lysncd_status_report()");
printlogf(L, "Call", "lysncd_status_report()");
lua_pcall(L, 1, 0, -3);
/* TODO */
@ -1169,7 +1178,7 @@ masterloop(lua_State *L)
/* lets the runner spawn new processes */
lua_getglobal(L, "lsyncd_alarm");
lua_pushinteger(L, times(NULL));
printlogf(L, "Call", "calling lsyncd_alarm().");
printlogf(L, "Call", "lsyncd_alarm()");
lua_call(L, 1, 0);
}
}

View File

@ -413,17 +413,27 @@ local Inotifies = (function()
-----
-- Adds watches for a directory including all subdirectories.
--
-- @param path relative path of this dir to origin
-- @param root root directory to observer
-- @param origin link to the observer to be notified.
-- Note: Inotifies should handle this opaquely
-- @param recurse true if recursing into subdirs
-- or the relative path to root for recurse
--
local function add(path, origin, recurse)
local function add(root, origin, recurse)
-- register watch and receive watch descriptor
local wd = lsyncd.add_watch(path);
local dir
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
-- failed adding the watch
log("Error", "Failure adding watch ", path, " -> ignored ")
log("Error", "Failure adding watch ", dir, " -> ignored ")
return
end
@ -432,14 +442,14 @@ local Inotifies = (function()
ilist = Array.new()
wdlist[wd] = ilist
end
local inotify = { path = path, origin = origin, recurse = recurse}
local inotify = { root = root, path = recurse, origin = origin }
table.insert(ilist, inotify)
-- registers and adds watches for all subdirectories
if recurse then
local subdirs = lsyncd.sub_dirs(path)
local subdirs = lsyncd.sub_dirs(dir)
for _, dirname in ipairs(subdirs) do
add(path..dirname.."/", origin, true)
add(root, origin, dir..dirname.."/")
end
end
end
@ -487,7 +497,8 @@ local Inotifies = (function()
-- add subdirs for new directories
if inotify.recurse and isdir then
if ename == "Create" then
add(pathname.."/", inotify.origin, true)
add(inotify.root, inotify.origin,
inotify.path.."/"..filename)
-- TODO remove /
end
end
@ -503,10 +514,7 @@ local Inotifies = (function()
for wd, v in wdlist:iwalk() do
w(fd, " ", wd, ": ")
for _, v in ipairs(v) do
print(v.origin)
print(v.path)
print(v.origin.source)
w(fd, "(", v.origin.source, "/", (v.path) or ")")
w(fd, "(", v.root, "/", (v.path) or ")")
end
w(fd, "\n")
end