mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-07 02:40:51 +00:00
This commit is contained in:
parent
0cbc6a7663
commit
7fd0ddadab
97
lsyncd.c
97
lsyncd.c
|
@ -491,6 +491,66 @@ wait_startup(lua_State *L)
|
||||||
free(pids);
|
free(pids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles an inotify event.
|
||||||
|
*/
|
||||||
|
void handle_event(lua_State *L, struct inotify_event *event) {
|
||||||
|
printf("handle_event\n");
|
||||||
|
if (IN_Q_OVERFLOW & event->mask) {
|
||||||
|
/* and overflow happened, lets runner/user decide what to do. */
|
||||||
|
lua_getglobal(L, "overflow");
|
||||||
|
lua_call(L, 0, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IN_IGNORED & event->mask || reset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if (IN_ACCESS & event->mask) {
|
||||||
|
printf("ACCESS id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_MODIFY & event->mask) {
|
||||||
|
printf("MODIFY id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_ATTRIB & event->mask) {
|
||||||
|
printf("ATTRIB id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_CLOSE_WRITE & event->mask) {
|
||||||
|
printf("CLOSE_WRITE id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_CLOSE_NOWRITE & event->mask) {
|
||||||
|
printf("CLOSE_WRITE id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_OPEN & event->mask) {
|
||||||
|
printf("OPEN id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_MOVED_FROM & event->mask) {
|
||||||
|
printf("MOVED_FROM id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_MOVED_TO & event->mask) {
|
||||||
|
printf("MOVED_TO id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_CREATE & event->mask) {
|
||||||
|
printf("CREATE id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_DELETE & event->mask) {
|
||||||
|
printf("DELETE id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_DELETE_SELF & event->mask) {
|
||||||
|
printf("DELETE_SELF id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
if (IN_MOVE_SELF & event->mask) {
|
||||||
|
printf("MOVE_SELF id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("id=%d mask=%d cookie=%d name=%s\n", event->wd, event->mask, event->cookie, event->name);
|
||||||
|
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normal operation happens in here.
|
* Normal operation happens in here.
|
||||||
*/
|
*/
|
||||||
|
@ -544,7 +604,7 @@ masterloop(lua_State *L)
|
||||||
if (do_read) {
|
if (do_read) {
|
||||||
printf("core: theres data on inotify.\n");
|
printf("core: theres data on inotify.\n");
|
||||||
} else {
|
} else {
|
||||||
printf("core: select() timeout, doing delays.\n");
|
printf("core: select() timeout or signal, doing delays.\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if nothing to wait for, enter a blocking read
|
// if nothing to wait for, enter a blocking read
|
||||||
|
@ -552,13 +612,35 @@ masterloop(lua_State *L)
|
||||||
do_read = 1;
|
do_read = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reads possible events from inotify stream */
|
||||||
|
do {
|
||||||
|
int i = 0;
|
||||||
if (do_read) {
|
if (do_read) {
|
||||||
len = read (inotify_fd, readbuf, INOTIFY_BUF_LEN);
|
len = read (inotify_fd, readbuf, INOTIFY_BUF_LEN);
|
||||||
} else {
|
} else {
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
|
while (i < len && !reset) {
|
||||||
|
struct inotify_event *event = (struct inotify_event *) &readbuf[i];
|
||||||
|
handle_event(L, event);
|
||||||
|
i += sizeof(struct inotify_event) + event->len;
|
||||||
|
}
|
||||||
|
/* check if there is more data */
|
||||||
|
if (do_read) {
|
||||||
|
struct timeval tv = {.tv_sec = 0, .tv_usec = 0};
|
||||||
|
fd_set readfds;
|
||||||
|
|
||||||
|
FD_ZERO(&readfds);
|
||||||
|
FD_SET(inotify_fd, &readfds);
|
||||||
|
do_read = select(inotify_fd + 1, &readfds, NULL, NULL, &tv);
|
||||||
|
if (do_read) {
|
||||||
|
printf("core: there is more data on inotify\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} while (do_read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main
|
* Main
|
||||||
|
@ -580,6 +662,19 @@ main(int argc, char *argv[])
|
||||||
luaL_register(L, "lsyncd", lsyncdlib);
|
luaL_register(L, "lsyncd", lsyncdlib);
|
||||||
lua_setglobal(L, "lysncd");
|
lua_setglobal(L, "lysncd");
|
||||||
|
|
||||||
|
/* register inotify identifiers */
|
||||||
|
lua_pushinteger(L, IN_ACCESS); lua_setglobal(L, "IN_ACCESS");
|
||||||
|
lua_pushinteger(L, IN_ATTRIB); lua_setglobal(L, "IN_ATTRIB");
|
||||||
|
lua_pushinteger(L, IN_CLOSE_WRITE); lua_setglobal(L, "IN_CLOSE_WRITE");
|
||||||
|
lua_pushinteger(L, IN_CLOSE_NOWRITE); lua_setglobal(L, "IN_CLOSE_NOWRITE");
|
||||||
|
lua_pushinteger(L, IN_CREATE); lua_setglobal(L, "IN_CREATE");
|
||||||
|
lua_pushinteger(L, IN_DELETE); lua_setglobal(L, "IN_DELETE");
|
||||||
|
lua_pushinteger(L, IN_DELETE_SELF); lua_setglobal(L, "IN_DELETE_SELF");
|
||||||
|
lua_pushinteger(L, IN_MODIFY); lua_setglobal(L, "IN_MODIFY");
|
||||||
|
lua_pushinteger(L, IN_MOVED_FROM); lua_setglobal(L, "IN_MOVED_FROM");
|
||||||
|
lua_pushinteger(L, IN_MOVED_TO); lua_setglobal(L, "IN_MOVED_TO");
|
||||||
|
lua_pushinteger(L, IN_OPEN); lua_setglobal(L, "IN_OPEN");
|
||||||
|
|
||||||
if (luaL_loadfile(L, "lsyncd.lua")) {
|
if (luaL_loadfile(L, "lsyncd.lua")) {
|
||||||
printf("error loading '%s': %s\n",
|
printf("error loading '%s': %s\n",
|
||||||
LSYNCD_RUNNER_FILE, lua_tostring(L, -1));
|
LSYNCD_RUNNER_FILE, lua_tostring(L, -1));
|
||||||
|
|
33
lsyncd.lua
33
lsyncd.lua
|
@ -113,6 +113,39 @@ function add(source_dir, target_path)
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
----
|
||||||
|
-- Called by core when an overflow happened.
|
||||||
|
function default_overflow()
|
||||||
|
print("--- OVERFLOW on inotify event queue ---")
|
||||||
|
lsyncd.terminate(-1) -- TODO reset instead.
|
||||||
|
|
||||||
|
end
|
||||||
|
overflow = default_overflow
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Called by core on event
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- @return the pid of a spawned child process or 0 if no spawn.
|
||||||
|
function default_event()
|
||||||
|
print("got an event")
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
on_access = default_event
|
||||||
|
on_modify = default_event
|
||||||
|
on_attrib = default_event
|
||||||
|
on_close_write = default_event
|
||||||
|
on_close_nowrite = default_event
|
||||||
|
on_open = default_event
|
||||||
|
on_moved_from = default_event -- lsyncd only unary moved from
|
||||||
|
on_moved_to = default_event -- lsyncd only unary moved to
|
||||||
|
on_move = default_event -- lsyncd Addon TODO
|
||||||
|
on_create = default_event
|
||||||
|
on_delete = default_event
|
||||||
|
on_delete_self = default_event
|
||||||
|
on_move_self = default_event
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Called by core after initialization.
|
-- Called by core after initialization.
|
||||||
--
|
--
|
||||||
|
|
Loading…
Reference in New Issue
Block a user