+ The called rsync binary is now configureable through rsyncBinary

+ Fsevents MAC Os X 10.6 64-bit support (thanks to Demian Steward)
+ fixed some "make clean" oversights
+ worked on library-set feature macros to include everything lsyncd needs on various systems (old Linux'es, new Linux'es, OSX)
+ internally called "rsyncOpts" as the right spelling, rsyncOps is recognized tough */
This commit is contained in:
Axel Kittenberger 2011-08-16 14:25:30 +00:00
parent 4c56100dd0
commit c5f3a17827
6 changed files with 141 additions and 84 deletions

View File

@ -6,9 +6,9 @@ if INOTIFY
lsyncd_SOURCES += inotify.c lsyncd_SOURCES += inotify.c
endif endif
#if FSEVENTS if FSEVENTS
#lsyncd_SOURCES += fsevents.c lsyncd_SOURCES += fsevents.c
#endif endif
lsyncd_LDADD = $(LUA_LIBS) lsyncd_LDADD = $(LUA_LIBS)
exampledir = $(docdir)/ exampledir = $(docdir)/
@ -29,7 +29,7 @@ TESTS = \
tests/l4rsyncdata.lua tests/l4rsyncdata.lua
dist_man1_MANS = doc/lsyncd.1 dist_man1_MANS = doc/lsyncd.1
EXTRA_DIST = doc/lsyncd.1.txt doc/lsyncd.1.xml EXTRA_DIST = doc/lsyncd.1.txt doc/lsyncd.1.xml inotify.c fsevents.c
doc/lsyncd.1: doc/lsyncd.1.xml doc/lsyncd.1: doc/lsyncd.1.xml
xsltproc -o $@ -nonet /etc/asciidoc/docbook-xsl/manpage.xsl $< xsltproc -o $@ -nonet /etc/asciidoc/docbook-xsl/manpage.xsl $<
@ -37,6 +37,8 @@ doc/lsyncd.1: doc/lsyncd.1.xml
doc/lsyncd.1.xml: doc/lsyncd.1.txt doc/lsyncd.1.xml: doc/lsyncd.1.txt
asciidoc -o $@ -b docbook -d manpage $< asciidoc -o $@ -b docbook -d manpage $<
CLEANFILES = luac.out luac.c
if RUNNER if RUNNER
# installs the runner script # installs the runner script
runnerdir = $(RUNNER_DIR) runnerdir = $(RUNNER_DIR)

View File

@ -43,28 +43,26 @@ AM_CONDITIONAL([RUNNER], [test x${with_runner} != x])
# --without-inotify option # --without-inotify option
AC_ARG_WITH([inotify], AC_ARG_WITH([inotify],
[ --without-inotify Do not use Linux inotify event interface. On by default.]) [ --without-inotify Do not use Linux inotify event interface. On by default.])
if test "x${with_inotify}" == xno; then if test "x${without_inotify}" != x; then
echo "compiling without inotify" echo "compiling with inotify"
AC_DEFINE(LSYNCD_WITH_INOTIFY,,"descr")
else else
echo "compiling with inotify" echo "compiling without inotify"
AC_DEFINE(LSYNCD_WITH_INOTIFY,,"descr")
fi fi
AM_CONDITIONAL([INOTIFY], [test x${with_inotify} != xno]) AM_CONDITIONAL([INOTIFY], [test x${with_inotify} != xno])
#### ###
## --with-fsevents # --with-fsevents
## disabled per default, experimental, works only with OS X 10.5 # disabled per default, experimental, works only with OS X 10.5/10.6
#AC_ARG_WITH([fsevents], AC_ARG_WITH([fsevents],
#[ --with-fsevents Uses MacOS (10.5) /dev/fsevents. EXPERIMENTAL! [ --with-fsevents Uses MacOS (10.5) /dev/fsevents. EXPERIMENTAL!
# Off by default.]) Off by default.])
#if test "x${with_fsevents}" != x; then if test "x${with_fsevents}" != x; then
# echo "compiling with fsevents. WARNING experimental!" echo "compiling with fsevents. WARNING experimental!"
# AC_DEFINE(LSYNCD_WITH_FSEVENTS,,"descr") AC_DEFINE(LSYNCD_WITH_FSEVENTS,,"descr")
#else fi
## echo "compiling without fsevents" AM_CONDITIONAL([FSEVENTS],
#fi [test x${with_fsevents} != x -a xno${with_fsevents} != xno])
#AM_CONDITIONAL([FSEVENTS],
# [test x${with_fsevents} != x -a xno${with_fsevents} != xno])
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions. # Checks for library functions.

View File

@ -3,6 +3,7 @@
* License: GPLv2 (see COPYING) or any later version * License: GPLv2 (see COPYING) or any later version
* *
* Authors: Axel Kittenberger <axkibe@gmail.com> * Authors: Axel Kittenberger <axkibe@gmail.com>
* Damian Steward <damian.stewart@gmail.com>
* *
* ----------------------------------------------------------------------- * -----------------------------------------------------------------------
* *
@ -87,8 +88,7 @@ struct kfs_event {
pid_t pid; pid_t pid;
/* event arguments */ /* event arguments */
struct kfs_event_arg args[]; struct kfs_event_arg* args[FSE_MAX_ARGS];
/* struct kfs_event_arg args[KFS_NUM_ARGS]; */
}; };
/** /**
@ -135,15 +135,17 @@ static size_t const readbuf_size = 131072;
static char * readbuf = NULL; static char * readbuf = NULL;
/** /**
* Handles one fsevents event * The event buffer
* @returns the size of the event
*/ */
static ssize_t static size_t const eventbuf_size = FSEVENT_BUFSIZ;
static char* eventbuf = NULL;
/**
* Handles one fsevents event
*/
static void
handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen) handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
{ {
/* the len of the event */
ssize_t len = sizeof(int32_t) + sizeof(pid_t);
int32_t atype; int32_t atype;
const char *path = NULL; const char *path = NULL;
const char *trg = NULL; const char *trg = NULL;
@ -158,35 +160,32 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
} }
lua_pop(L, 1); lua_pop(L, 1);
hup = 1; hup = 1;
len += sizeof(u_int16_t); return;
return len;
} }
{
atype = event->type & FSE_TYPE_MASK;
/*uint32_t aflags = FSE_GET_FLAGS(event->type);*/
if ((atype < FSE_MAX_EVENTS) && (atype >= -1)) { atype = event->type & FSE_TYPE_MASK;
/*printlogf(L, "Fsevents", "got event %s", eventNames[atype]); /*uint32_t aflags = FSE_GET_FLAGS(event->type);*/
if (aflags & FSE_COMBINED_EVENTS) {
logstring("Fsevents", "combined events"); if ((atype < FSE_MAX_EVENTS) && (atype >= -1)) {
} /*printlogf(L, "Fsevents", "got event %s", eventNames[atype]);
if (aflags & FSE_CONTAINS_DROPPED_EVENTS) { if (aflags & FSE_COMBINED_EVENTS) {
logstring("Fsevents", "contains dropped events"); logstring("Fsevents", "combined events");
}*/
} else {
printlogf(L, "Error", "unknown event(%d) in fsevents.",
atype);
exit(-1); // ERRNO
} }
if (aflags & FSE_CONTAINS_DROPPED_EVENTS) {
logstring("Fsevents", "contains dropped events");
}*/
} else {
printlogf(L, "Error", "unknown event(%d) in fsevents.",
atype);
exit(-1); // ERRNO
} }
{ {
/* assigns the expected arguments */ /* assigns the expected arguments */
struct kfs_event_arg *arg = event->args; int whichArg = 0;
while (len < mlen) { while (whichArg < FSE_MAX_ARGS) {
int eoff; struct kfs_event_arg * arg = event->args[whichArg++];
if (arg->type == FSE_ARG_DONE) { if (arg->type == FSE_ARG_DONE) {
len += sizeof(u_int16_t);
break; break;
} }
@ -225,10 +224,6 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
} }
break; break;
} }
eoff = sizeof(arg->type) + sizeof(arg->len) + arg->len;
len += eoff;
arg = (struct kfs_event_arg *) ((char *) arg + eoff);
} }
} }
@ -279,7 +274,6 @@ handle_event(lua_State *L, struct kfs_event *event, ssize_t mlen)
} }
lua_pop(L, 1); lua_pop(L, 1);
} }
return len;
} }
/** /**
@ -310,8 +304,53 @@ fsevents_ready(lua_State *L, struct observance *obs)
{ {
int off = 0; int off = 0;
while (off < len && !hup && !term) { while (off < len && !hup && !term) {
struct kfs_event *event = (struct kfs_event *) &readbuf[off]; /* deals with alignment issues on 64 bit by copying data bit by bit */
off += handle_event(L, event, len); struct kfs_event* event = (struct kfs_event *) eventbuf;
event->type = *(int32_t*)(readbuf+off);
off += sizeof(int32_t);
event->pid = *(pid_t*)(readbuf+off);
off += sizeof(pid_t);
/* arguments */
int whichArg = 0;
int eventbufOff = sizeof(struct kfs_event);
size_t ptrSize = sizeof(void*);
if ((eventbufOff % ptrSize) != 0) {
eventbufOff += ptrSize-(eventbufOff%ptrSize);
}
while (off < len && whichArg < FSE_MAX_ARGS) {
/* assign argument pointer to eventbuf based on
known current offset into eventbuf */
uint16_t argLen = 0;
event->args[whichArg] = (struct kfs_event_arg *) (eventbuf + eventbufOff);
/* copy type */
uint16_t argType = *(uint16_t*)(readbuf + off);
event->args[whichArg]->type = argType;
off += sizeof(uint16_t);
if (argType == FSE_ARG_DONE) {
/* done */
break;
} else {
/* copy data length */
argLen = *(uint16_t *)(readbuf + off);
event->args[whichArg]->len = argLen;
off += sizeof(uint16_t);
/* copy data */
memcpy(&(event->args[whichArg]->data), readbuf + off, argLen);
off += argLen;
}
/* makes sure alignment is correct for 64 bit systems */
size_t argStructLen = sizeof(uint16_t) + sizeof(uint16_t);
if ((argStructLen % ptrSize) != 0) {
argStructLen += ptrSize-(argStructLen % ptrSize);
}
argStructLen += argLen;
if ((argStructLen % ptrSize) != 0) {
argStructLen += ptrSize-(argStructLen % ptrSize);
}
eventbufOff += argStructLen;
whichArg++;
}
handle_event(L, event, len);
} }
} }
} }
@ -330,6 +369,8 @@ fsevents_tidy(struct observance *obs)
close(fsevents_fd); close(fsevents_fd);
free(readbuf); free(readbuf);
readbuf = NULL; readbuf = NULL;
free(eventbuf);
eventbuf = NULL;
} }
/** /**
@ -386,7 +427,7 @@ open_fsevents(lua_State *L)
exit(-1); // ERRNO exit(-1); // ERRNO
} }
readbuf = s_malloc(readbuf_size); readbuf = s_malloc(readbuf_size);
eventbuf = s_malloc(eventbuf_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

@ -27,6 +27,7 @@
#include <limits.h> #include <limits.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -2048,7 +2049,6 @@ main1(int argc, char *argv[])
return 0; return 0;
} }
/** /**
* Main * Main
*/ */

View File

@ -13,7 +13,8 @@
/* some older machines need this to see pselect */ /* some older machines need this to see pselect */
#define _BSD_SOURCE 1 #define _BSD_SOURCE 1
#define _XOPEN_SOURCE 600 #define _XOPEN_SOURCE 700
#define _DARWIN_C_SOURCE 1
/* includes needed for headerfile */ /* includes needed for headerfile */
#include "config.h" #include "config.h"

View File

@ -3156,9 +3156,9 @@ local default_rsync = {
"Calling rsync with filter-list of new/modified files/dirs\n", "Calling rsync with filter-list of new/modified files/dirs\n",
filterS) filterS)
local config = inlet.getConfig() local config = inlet.getConfig()
spawn(elist, "/usr/bin/rsync", spawn(elist, config.rsyncBinary,
"<", filter0, "<", filter0,
config.rsyncOps, config.rsyncOpts,
"-r", "-r",
"--delete", "--delete",
"--force", "--force",
@ -3185,20 +3185,20 @@ local default_rsync = {
if #excludes == 0 then if #excludes == 0 then
log("Normal", "recursive startup rsync: ", config.source, log("Normal", "recursive startup rsync: ", config.source,
" -> ", config.target) " -> ", config.target)
spawn(event, "/usr/bin/rsync", spawn(event, config.rsyncBinary,
"--delete", "--delete",
config.rsyncOps, "-r", config.rsyncOpts, "-r",
config.source, config.source,
config.target) config.target)
else else
local exS = table.concat(excludes, "\n") local exS = table.concat(excludes, "\n")
log("Normal", "recursive startup rsync: ", config.source, log("Normal", "recursive startup rsync: ", config.source,
" -> ", config.target," excluding\n", exS) " -> ", config.target," excluding\n", exS)
spawn(event, "/usr/bin/rsync", spawn(event, config.rsyncBinary,
"<", exS, "<", exS,
"--exclude-from=-", "--exclude-from=-",
"--delete", "--delete",
config.rsyncOps, "-r", config.rsyncOpts, "-r",
config.source, config.source,
config.target) config.target)
end end
@ -3212,18 +3212,23 @@ local default_rsync = {
error("default.rsync needs 'target' configured", 4) error("default.rsync needs 'target' configured", 4)
end end
if config.rsyncOpts then if config.rsyncOps then
if config.rsyncOps then if config.rsyncOpts then
error("'rsyncOpts' and 'rsyncOps' provided in config, decide for one.") error("'rsyncOpts' and 'rsyncOps' provided in config, decide for one.")
end end
config.rsyncOps = config.rsyncOpts config.rsyncOpts = config.rsyncOps
end end
end, end,
-----
-- The rsync binary called.
--
rsyncBinary = "/usr/bin/rsync",
----- -----
-- Calls rsync with this default short opts. -- Calls rsync with this default short opts.
-- --
rsyncOps = "-lts", rsyncOpts = "-lts",
----- -----
-- exit codes for rsync. -- exit codes for rsync.
@ -3314,9 +3319,9 @@ local default_rsyncssh = {
local zPaths = table.concat(paths, "\000") local zPaths = table.concat(paths, "\000")
log("Normal", "Rsyncing list\n", sPaths) log("Normal", "Rsyncing list\n", sPaths)
spawn( spawn(
elist, "/usr/bin/rsync", elist, rsyncBinary,
"<", zPaths, "<", zPaths,
config.rsyncOps, config.rsyncOpts,
"--from0", "--from0",
"--files-from=-", "--files-from=-",
config.source, config.source,
@ -3383,10 +3388,10 @@ local default_rsyncssh = {
log("Normal", "recursive startup rsync: ", config.source, log("Normal", "recursive startup rsync: ", config.source,
" -> ", config.host .. ":" .. config.targetdir) " -> ", config.host .. ":" .. config.targetdir)
spawn( spawn(
event, "/usr/bin/rsync", event, rsyncBinary,
"--delete", "--delete",
"-r", "-r",
config.rsyncOps, config.rsyncOpts,
config.source, config.source,
config.host .. ":" .. config.targetdir config.host .. ":" .. config.targetdir
) )
@ -3395,12 +3400,12 @@ local default_rsyncssh = {
log("Normal", "recursive startup rsync: ", config.source, log("Normal", "recursive startup rsync: ", config.source,
" -> ", config.host .. ":" .. config.targetdir, " excluding\n") " -> ", config.host .. ":" .. config.targetdir, " excluding\n")
spawn( spawn(
event, "/usr/bin/rsync", event, rsyncBinary,
"<", exS, "<", exS,
"--exclude-from=-", "--exclude-from=-",
"--delete", "--delete",
"-r", "-r",
config.rsyncOps, config.rsyncOpts,
config.source, config.source,
config.host .. ":" .. config.targetdir config.host .. ":" .. config.targetdir
) )
@ -3411,11 +3416,11 @@ local default_rsyncssh = {
-- Checks the configuration. -- Checks the configuration.
-- --
prepare = function(config) prepare = function(config)
if config.rsyncOpts then if config.rsyncOps then
if config.rsyncOps then if config.rsyncOpts then
error("'rsyncOpts' and 'rsyncOps' provided in config, decide for one.") error("'rsyncOpts' and 'rsyncOps' provided in config, decide for one.")
end end
config.rsyncOps = config.rsyncOpts config.rsyncOpts = config.rsyncOps
end end
if not config.host then if not config.host then
error("default.rsyncssh needs 'host' configured", 4) error("default.rsyncssh needs 'host' configured", 4)
@ -3424,11 +3429,16 @@ local default_rsyncssh = {
error("default.rsyncssh needs 'targetdir' configured", 4) error("default.rsyncssh needs 'targetdir' configured", 4)
end end
end, end,
-----
-- The rsync binary called.
--
rsyncBinary = "/usr/bin/rsync",
----- -----
-- Calls rsync with this default short opts. -- Calls rsync with this default short opts.
-- --
rsyncOps = "-lts", rsyncOpts = "-lts",
----- -----
-- allow processes -- allow processes
@ -3451,7 +3461,7 @@ local default_rsyncssh = {
-- available this is simpler than to build filters for rsync for this. -- available this is simpler than to build filters for rsync for this.
-- Default uses '0' as limiter, you might override this for old systems. -- Default uses '0' as limiter, you might override this for old systems.
-- --
xargs = {delimiter = '\000', binary = "xargs", xparams = {"-0", "rm -rf"}} xargs = {delimiter = '\000', binary = "/usr/bin/xargs", xparams = {"-0", "rm -rf"}}
} }
----- -----
@ -3563,10 +3573,15 @@ local default_direct = {
-- --
onMove = true, onMove = true,
-----
-- The rsync binary called.
--
rsyncBinary = "/usr/bin/rsync",
----- -----
-- For startup sync -- For startup sync
-- --
rsyncOps = "-lts", rsyncOpts = "-lts",
----- -----
-- On many system multiple disk operations just rather slow down -- On many system multiple disk operations just rather slow down