and some work on the fsevents front

This commit is contained in:
Axel Kittenberger 2010-12-01 16:12:15 +00:00
parent a28bea5048
commit ea9e8498e0
2 changed files with 43 additions and 4 deletions

View File

@ -100,6 +100,20 @@ static const luaL_reg lfseventslib[] = {
{NULL, NULL} {NULL, NULL}
}; };
// event names
static const char *eventNames[FSE_MAX_EVENTS] = {
"CREATE_FILE",
"DELETE",
"STAT_CHANGED",
"RENAME",
"CONTENT_MODIFIED",
"EXCHANGE",
"FINDER_INFO_CHANGED",
"CREATE_DIR",
"CHOWN",
"XATTR_MODIFIED",
"XATTR_REMOVED",
};
static size_t const readbuf_size = 131072; static size_t const readbuf_size = 131072;
static char * readbuf = NULL; static char * readbuf = NULL;
@ -154,8 +168,21 @@ fsevents_ready(lua_State *L, struct observance *obs)
} }
atype = event->type & FSE_TYPE_MASK; atype = event->type & FSE_TYPE_MASK;
aflags = FSE_GET_FLAGS(event->type); aflags = FSE_GET_FLAGS(event->type);
}
if ((atype < FSE_MAX_EVENTS) && (atype >= -1)) {
printlogf(L, "Fsevents", "got event %s", eventNames[atype]);
if (aflags & FSE_COMBINED_EVENTS) {
logstring("Fsevents", "combined events");
}
if (aflags & FSE_CONTAINS_DROPPED_EVENTS) {
logstring("Fsevents", "contains dropped events");
}
} else {
printlogf(L, "Error", "unknown event(%d) in fsevents.",
atype);
exit(-1); // ERRNO
}
}
} }
} }
} }
@ -171,6 +198,8 @@ fsevents_tidy(struct observance *obs)
exit(-1); // ERRNO exit(-1); // ERRNO
} }
close(fsevents_fd); close(fsevents_fd);
free(readbuf);
readbuf = NULL;
} }
@ -225,6 +254,13 @@ open_fsevents(lua_State *L)
exit(-1); // ERRNO exit(-1); // ERRNO
} }
if (readbuf) {
logstring("Error",
"internal fail, inotify readbuf!=NULL in open_inotify()")
exit(-1); // ERRNO
}
readbuf = s_malloc(readbuf_size);
/* fd has been cloned, closes access fd */ /* fd has been cloned, closes access fd */
close(fd); close(fd);
close_exec_fd(fsevents_fd); close_exec_fd(fsevents_fd);

View File

@ -318,7 +318,8 @@ inotify_ready(lua_State *L, struct observance *obs)
* registers inotify functions. * registers inotify functions.
*/ */
extern void extern void
register_inotify(lua_State *L) { register_inotify(lua_State *L)
{
lua_pushstring(L, "inotify"); lua_pushstring(L, "inotify");
luaL_register(L, "inotify", linotfylib); luaL_register(L, "inotify", linotfylib);
} }
@ -327,7 +328,8 @@ register_inotify(lua_State *L) {
* closes inotify * closes inotify
*/ */
static void static void
inotify_tidy(struct observance *obs) { inotify_tidy(struct observance *obs)
{
if (obs->fd != inotify_fd) { if (obs->fd != inotify_fd) {
logstring("Error", "Internal, inotify_fd != ob->fd"); logstring("Error", "Internal, inotify_fd != ob->fd");
exit(-1); // ERRNO exit(-1); // ERRNO
@ -341,7 +343,8 @@ inotify_tidy(struct observance *obs) {
* opens and initalizes inotify. * opens and initalizes inotify.
*/ */
extern void extern void
open_inotify(lua_State *L) { open_inotify(lua_State *L)
{
if (readbuf) { if (readbuf) {
logstring("Error", logstring("Error",
"internal fail, inotify readbuf!=NULL in open_inotify()") "internal fail, inotify readbuf!=NULL in open_inotify()")