From 83aed80aa716fe992fcaa4deb74a99f6ba94fbe9 Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Wed, 24 Nov 2010 18:19:13 +0000 Subject: [PATCH] removed enum --- inotify.c | 35 +++++++++++++++++++++-------------- lsyncd.h | 12 ------------ lsyncd.lua | 6 +++--- tests/randrsync.lua | 3 ++- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/inotify.c b/inotify.c index 1d17e13..2194c1b 100644 --- a/inotify.c +++ b/inotify.c @@ -39,6 +39,15 @@ #include #include +/*----------------------------------------------------------------------------- + * Event types. + */ +const char * ATTRIB = "Attrib"; +const char * MODIFY = "Modify"; +const char * CREATE = "Create"; +const char * DELETE = "Delete"; +const char * MOVE = "Move"; + /** * The inotify file descriptor. */ @@ -63,6 +72,7 @@ l_addwatch(lua_State *L) { const char *path = luaL_checkstring(L, 1); lua_Integer wd = inotify_add_watch(inotify_fd, path, standard_event_mask); + printlogf(L, "Inotify", "addwatch(%s)->%d", path, wd); lua_pushinteger(L, wd); return 1; } @@ -78,6 +88,7 @@ l_rmwatch(lua_State *L) { lua_Integer wd = luaL_checkinteger(L, 1); inotify_rm_watch(inotify_fd, wd); + printlogf(L, "Inotify", "rmwatch()<-%d", wd); return 0; } @@ -113,7 +124,7 @@ static void handle_event(lua_State *L, struct inotify_event *event) { - int event_type; + const char *event_type = NULL; /* used to execute two events in case of unmatched MOVE_FROM buffer */ struct inotify_event *after_buf = NULL; @@ -141,22 +152,23 @@ handle_event(lua_State *L, /* a buffered MOVE_FROM is not followed by anything, thus it is unary */ event = move_event_buf; - event_type = DELETE; + event_type = "Delete"; move_event = false; } else if (move_event && ( !(IN_MOVED_TO & event->mask) || event->cookie != move_event_buf->cookie) ) { /* there is a MOVE_FROM event in the buffer and this is not the match * continue in this function iteration to handle the buffer instead */ + logstring("Inotify", "icore, changing unary MOVE_FROM into DELETE") after_buf = event; event = move_event_buf; - event_type = DELETE; + event_type = "Delete"; move_event = false; } else if ( move_event && (IN_MOVED_TO & event->mask) && event->cookie == move_event_buf->cookie ) { /* this is indeed a matched move */ - event_type = MOVE; + event_type = "Move"; move_event = false; } else if (IN_MOVED_FROM & event->mask) { /* just the MOVE_FROM, buffers this event, and wait if next event is @@ -189,22 +201,17 @@ handle_event(lua_State *L, /* rm'ed */ event_type = DELETE; } else { - logstring("Inotify", "skipped some inotify event."); + logstring("Inotify", "icore, skipped some inotify event."); return; } /* and hands over to runner */ load_runner_func(L, "inotifyEvent"); - switch(event_type) { - case ATTRIB : lua_pushstring(L, "Attrib"); break; - case MODIFY : lua_pushstring(L, "Modify"); break; - case CREATE : lua_pushstring(L, "Create"); break; - case DELETE : lua_pushstring(L, "Delete"); break; - case MOVE : lua_pushstring(L, "Move"); break; - default : + if (!event_type) { logstring("Error", "Internal: unknown event in handle_event()"); exit(-1); // ERRNO } + lua_pushstring(L, event_type); if (event_type != MOVE) { lua_pushnumber(L, event->wd); } else { @@ -228,7 +235,7 @@ handle_event(lua_State *L, /* if there is a buffered event executes it */ if (after_buf) { - logstring("Inotify", "handling buffered event."); + logstring("Inotify", "icore, handling buffered event."); handle_event(L, after_buf); } } @@ -295,7 +302,7 @@ inotify_ready(lua_State *L, int fd, void *extra) /* checks if there is an unary MOVE_FROM left in the buffer */ if (move_event) { - logstring("Inotify", "handling unary move from."); + logstring("Inotify", "icore, handling unary move from."); handle_event(L, NULL); } } diff --git a/lsyncd.h b/lsyncd.h index 0fffa2b..216e501 100644 --- a/lsyncd.h +++ b/lsyncd.h @@ -50,18 +50,6 @@ extern struct settings { #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) #define time_before_eq(a,b) time_after_eq(b,a) -/*----------------------------------------------------------------------------- - * Event types. - * TODO, needed here? - */ -enum event_type { - NONE = 0, - ATTRIB = 1, - MODIFY = 2, - CREATE = 3, - DELETE = 4, - MOVE = 5, -}; /* pushes a runner function and the runner error handler onto Lua stack */ extern void load_runner_func(lua_State *L, const char *name); diff --git a/lsyncd.lua b/lsyncd.lua index b4d534b..473d415 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -1592,10 +1592,10 @@ local Inotifies = (function() end if filename2 then - log("Inotify", "got event ", etype, " ", filename, - " to ", filename2) + log("Inotify", "got event ",etype," ",filename, + "(",wd,") to ",filename2,"(",wd2,")") else - log("Inotify", "got event ", etype, " ", filename) + log("Inotify","got event ",etype," ",filename,"(",wd,")") end -- looks up the watch descriptor id diff --git a/tests/randrsync.lua b/tests/randrsync.lua index ecb5cd7..4941d6c 100755 --- a/tests/randrsync.lua +++ b/tests/randrsync.lua @@ -16,7 +16,8 @@ local trgdir = tdir.."trg/" posix.mkdir(srcdir) posix.mkdir(trgdir) -local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir,"-log","all") +local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir, + "-log","Inotify","-log","Exec") cwriteln("waiting for Lsyncd to startup") posix.sleep(1)