mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-12 22:27:50 +00:00
104 lines
2.0 KiB
C
104 lines
2.0 KiB
C
/**
|
|
* fsevents.c from Lsyncd - Live (Mirror) Syncing Demon
|
|
*
|
|
* License: GPLv2 (see COPYING) or any later version
|
|
*
|
|
* Authors: Axel Kittenberger <axkibe@gmail.com>
|
|
*
|
|
* -----------------------------------------------------------------------
|
|
*
|
|
* Interface to Linux' new filesystem monitor - fanotify.
|
|
*/
|
|
#include "lsyncd.h"
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
|
|
#include <lua.h>
|
|
#include <lualib.h>
|
|
#include <lauxlib.h>
|
|
|
|
|
|
#ifdef HAVE_SYS_FANOTIFY_H
|
|
# include <sys/fanotify.h>
|
|
#else
|
|
# warning sys/fanotify.h not found, using own syscalls as workaround.
|
|
# include "fanotify-syscall.h"
|
|
#endif
|
|
|
|
/**
|
|
* The fanotify file descriptor.
|
|
*/
|
|
static int fanotify_fd = -1;
|
|
|
|
/**
|
|
* Adds a filesystem to watch
|
|
*
|
|
* @param dir (Lua stack) the dir to watch the filesystem of.
|
|
* @return nil
|
|
*/
|
|
static int
|
|
l_watchfs(lua_State *L)
|
|
{
|
|
// const char *path = luaL_checkstring(L, 1);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Cores fanotify functions.
|
|
*/
|
|
static const luaL_reg lfanotifylib[] = {
|
|
{"watchfs", l_watchfs },
|
|
{NULL, NULL}
|
|
};
|
|
|
|
/**
|
|
* registers fanoitfy functions.
|
|
*/
|
|
extern void
|
|
register_fanotify(lua_State *L) {
|
|
lua_pushstring(L, "fanotify");
|
|
luaL_register(L, "fanotify", lfanotifylib);
|
|
}
|
|
|
|
/**
|
|
* Called by function pointer from when the inotify file descriptor
|
|
* became ready. Reads it contents and forward all received events
|
|
* to the runner.
|
|
*/
|
|
static void
|
|
fanotify_ready(lua_State *L, struct observance *ob)
|
|
{
|
|
// TODO
|
|
}
|
|
|
|
/**
|
|
* closes fanoitfy
|
|
*/
|
|
extern void
|
|
fanotify_tidy(struct observance *ob) {
|
|
if (ob->fd != fanotify_fd) {
|
|
logstring("Error", "Internal, fanotify_fd != ob->fd");
|
|
exit(-1); // ERRNO
|
|
}
|
|
close(fanotify_fd);
|
|
}
|
|
|
|
|
|
/**
|
|
* opens and initalizes fanotify.
|
|
*/
|
|
extern void
|
|
open_fanotify(lua_State *L) {
|
|
fanotify_fd = fanotify_init(O_CLOEXEC | O_NONBLOCK, O_RDONLY);
|
|
if (fanotify_fd < 0) {
|
|
printlogf(L, "Error",
|
|
"Cannot access fanotify monitor! (%d:%s)",
|
|
errno, strerror(errno));
|
|
exit(-1); // ERRNO
|
|
}
|
|
|
|
observe_fd(fanotify_fd, fanotify_ready, NULL, fanotify_tidy, NULL);
|
|
}
|
|
|