diff --git a/Makefile.am b/Makefile.am
index 239028f..21a37cd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,6 +5,9 @@ lsyncd_SOURCES = lsyncd.h lsyncd.c lsyncd.lua
if INOTIFY
lsyncd_SOURCES += inotify.c
endif
+if FSEVENTS
+lsyncd_SOURCES += fsevents.c
+endif
lsyncd_LDADD = $(LIBLUA_LIBS)
exampledir = $(datarootdir)/doc/@PACKAGE@
diff --git a/configure.ac b/configure.ac
index ce219b4..91aceb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@ AC_CHECK_HEADERS([sys/inotify.h])
###
# --with-runner option
AC_ARG_WITH([runner],
-[ --with-runner=
Specify directory where lsyncds part written in Lua will be placed.
+[ --with-runner= Specify directory where lsyncds part written in Lua will be placed.
If missing it will be compiled into the binary])
if test "x${with_runner}" != x; then
AC_DEFINE_UNQUOTED(LSYNCD_DEFAULT_RUNNER_FILE, "${with_runner}/lsyncd.lua", "descr")
@@ -29,7 +29,7 @@ AM_CONDITIONAL([RUNNER], [test x${with_runner} != x])
###
# --without-inotify option
AC_ARG_WITH([inotify],
-[ --without-inotify Do not compile Linux inotify event interface (on by default)])
+[ --without-inotify Do not compile Linux inotify event interface. On by default.])
if test "x${with_inotify}" == xno; then
echo "compiling without inotify"
else
@@ -38,6 +38,22 @@ else
fi
AM_CONDITIONAL([INOTIFY], [test x${with_inotify} != xno])
+###
+# --with-fsevents
+AC_ARG_WITH([fsevents],
+[ --with-fsevents=DIR Uses MacOS (10.5) /dev/fsevents, experimental! Off by default.
+ As DIR specify dir where xnu headers can be found.])
+if test "x${with_fsevents}" == xno; then
+ with_fsevents=
+fi
+if test "x${with_fsevents}" != x; then
+ echo "compiling with fsevents. Warning experimental!"
+ AC_DEFINE(LSYNCD_WITH_FSEVENTS,,"descr")
+else
+ echo "compiling without fsevents"
+fi
+AM_CONDITIONAL([FSEVENTS], [test x${with_fsevents} != x])
+
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile])
diff --git a/fsevents.c b/fsevents.c
new file mode 100644
index 0000000..42d1b0c
--- /dev/null
+++ b/fsevents.c
@@ -0,0 +1,49 @@
+/**
+ * fsevents.c from Lsyncd - Live (Mirror) Syncing Demon
+ *
+ * License: GPLv2 (see COPYING) or any later version
+ *
+ * Authors: Axel Kittenberger
+ *
+ * -----------------------------------------------------------------------
+ *
+ * Event interface for MacOS 10(.5) /dev/fsevents interface.
+ *
+ * WARNING! AFAIK this interface is not strictly considered "public" API
+ * by Apple. Thus it might easily change between versions. Also its said,
+ * altough every event receiver has its own message queue, the OS X kernel
+ * only deletes a message after *all* registered receivers handled it. So
+ * one receiver blocking overflows all receivers. So spotlight might have
+ * to do more stuff, when Lsyncd might cause an overflow. Use at own risk.
+ *
+ * Special thanks go to Amit Singh and his fslogger demonstration that
+ * showed how apples /dev/fsevents can be used.
+ * http://osxbook.com/software/fslogger/
+ */
+
+#include "lsyncd.h"
+
+/**
+ * registers fsevents functions.
+ */
+extern void
+register_fsevents(lua_State *L) {
+ // TODO
+}
+
+/**
+ * opens and initalizes fsevents.
+ */
+extern void
+open_fsevents(lua_State *L) {
+ // TODO
+}
+
+/**
+ * closes fsevents
+ */
+extern void
+close_fsevents() {
+ // TODO
+}
+
diff --git a/lsyncd.c b/lsyncd.c
index 6755704..eff4a2c 100644
--- a/lsyncd.c
+++ b/lsyncd.c
@@ -40,16 +40,18 @@
* The Lua part of lsyncd if compiled into the binary.
*/
#ifndef LSYNCD_DEFAULT_RUNNER_FILE
-extern char _binary_luac_out_start;
-extern char _binary_luac_out_end;
+ extern char _binary_luac_out_start;
+ extern char _binary_luac_out_end;
#endif
/**
* The default notification system to use.
*/
-#ifdef LSYNCD_WITH_INOTIFY
-extern char *default_notify = "Inotify";
+#if defined LSYNCD_WITH_INOTIFY
+ static char *default_notify = "Inotify";
+#elif defined LSYNCD_WITH_FSEVENTS
+ static char *default_notify = "FsEvents";
#else
# error "need at least one notifcation system. please rerun ./configure"
#endif
@@ -73,7 +75,7 @@ static bool is_daemon = false;
* True after first configuration phase. This is to write configuration error
* messages to stdout/stderr after being first started. Then it uses whatever
* it has been configured to. This survives a reset by HUP signal or
- * inotify OVERFLOW!
+ * inotify OVERFLOW.
*/
static bool running = false;
@@ -1142,12 +1144,15 @@ masterloop(lua_State *L)
lua_pop(L, 2);
if (have_alarm && time_before_eq(alarm_time, now)) {
- /* there is a delay that wants to be handled already thus do not
- * read from inotify_fd and jump directly to its handling */
+ /* there is a delay that wants to be handled already thus instead of
+ * reading/writing from observances it jumps directly to handling */
+
+ // TODO: Actually it might be smarter to handler observances eitherway.
+ // since event queues might overflow.
logstring("Masterloop", "immediately handling delays.");
} else {
/* use select() to determine what happens next
- * + a new event on inotify
+ * + a new event on an observance
* + an alarm on timeout
* + the return of a child process */
struct timespec tv;
@@ -1336,8 +1341,14 @@ main1(int argc, char *argv[])
lua_setglobal(L, "lysncd");
lua_getglobal(L, "lysncd");
+#ifdef LSYNCD_WITH_INOTIFY
register_inotify(L);
lua_settable(L, -3);
+#endif
+#ifdef LSYNCD_WITH_FSEVENTS
+ register_fsevents(L);
+ lua_settable(L, -3);
+#endif
lua_pop(L, 1);
if (check_logcat("Debug") >= settings.log_level) {
@@ -1509,7 +1520,12 @@ main1(int argc, char *argv[])
}
}
+#ifdef LSYNCD_WITH_INOTIFY
open_inotify(L);
+#endif
+#ifdef LSYNCD_WITH_FSEVENTS
+ open_fsevents(L);
+#endif
{
/* adds signal handlers *
@@ -1529,7 +1545,8 @@ main1(int argc, char *argv[])
/* runs initialitions from runner
* lua code will set configuration and add watches */
load_runner_func(L, "initialize");
- if (lua_pcall(L, 0, 0, -2)) {
+ lua_pushstring(L, default_notify);
+ if (lua_pcall(L, 1, 0, -3)) {
exit(-1); // ERRNO
}
lua_pop(L, 1);
@@ -1566,7 +1583,12 @@ main1(int argc, char *argv[])
settings.log_level = 0,
settings.nodaemon = false,
+#ifdef LSYNCD_WITH_INOTIFY
close_inotify();
+#endif
+#ifdef LSYNCD_WITH_FSEVENTS
+ close_fsevents();
+#endif
lua_close(L);
return 0;
}
diff --git a/lsyncd.h b/lsyncd.h
index 216e501..80f40c8 100644
--- a/lsyncd.h
+++ b/lsyncd.h
@@ -116,10 +116,20 @@ extern void unobserve_fd(int fd);
/*-----------------------------------------------------------------------------
* inotify
*/
+#ifdef LSYNCD_WITH_INOTIFY
extern void register_inotify(lua_State *L);
extern void open_inotify(lua_State *L);
extern void close_inotify();
+#endif
+/*-----------------------------------------------------------------------------
+ * /dev/fsevents
+ */
+#ifdef LSYNCD_WITH_FSEVENTS
+extern void register_fsevents(lua_State *L);
+extern void open_fsevents(lua_State *L);
+extern void close_fsevents();
+#endif
#endif