[-]
[+]
|
Changed |
lsyncd.changes
|
|
[-]
[+]
|
Changed |
lsyncd.spec
^
|
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/ChangeLog
^
|
@@ -1,4 +1,34 @@
-??-??-????:
+24-11-2012: 2.1.4
+ fix: making ssh custom port changes work with ssh and rsync
+
+23-11-2012: 2.1.3
+ fix: fixed 2 crash conditions due to failure to read 'uSettings'
+
+03-11-2012: 2.1.2
+ fix: added excludeFrom to checkgauge (thx to DavidWittman)
+ fix: fixed rsync option computation
+ enhancement: added password_file file option to rsync
+
+27-10-2012: 2.1.1
+ fix: fix rsync.rsh, rsync.rsync_path, rsync.tmp_dir, rsync._extra parameters
+ thanks go to Birger Schmidt for this fix.
+
+23-10-2012: 2.1.0
+ fix: fail startup if settings.inist is false and one of the target hosts fails
+ fix: in case of waiting for processes during restart only logs this state now once a minute
+ rather than filling the log crazy about it
+ enhancement: rsyncOpts has been replaced by rsync = {...} parameter lists
+ enhancement: default.rsyncssh has now a ssh = {...} parameter similar to default.rsync to
+ add option to ssh calls. Ditto for xargs = {...}
+ enhancement: the default.* implementations have a checkgauge erroring on any unknown
+ parameters to the sync{} call
+ enhancement: the delete parameter now takes: true, false, 'running' and 'startup'
+ improvement: Dennis Schridde provided various improvements for Lsyncd's autoconf building
+ change: Lsyncd is now Lua 5.2 compatible
+ change: Lsyncd now exits with exitcode 143 on TERM signal
+ change: settings is now be used as call like settings{...} instead of settings = {...}
+
+04-04-2012: 2.0.7
fix: closed a memory leak due to not correct configured weak tables
fix: default.direct, do not use on OSX unrecognized option -t on modify
fix: default.direct, typo leading to compile error
@@ -8,7 +38,7 @@
change: removed --with-default-runner since it was broken, and will be replaced by something
more generic in future
-16-02-2011: 2.0.6
+16-02-2012: 2.0.6
fix: no longer stops syslogging on HUP signals
fix: OSX event watcher no longer misses moves into and out of the watch tree
fix: not refinding a relative path to the config file in case of HUP.
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/Makefile.am
^
|
@@ -1,4 +1,5 @@
-AUTOMAKE_OPTIONS = foreign
+ACLOCAL_AMFLAGS = -I m4
+
CFLAGS += -Wall $(LUA_CFLAGS)
bin_PROGRAMS = lsyncd
lsyncd_SOURCES = lsyncd.h lsyncd.c lsyncd.lua default-rsync.lua
@@ -35,7 +36,7 @@
default.lua default-rsync.lua default-rsyncssh.lua default-direct.lua
doc/lsyncd.1: doc/lsyncd.1.txt
- a2x --format=manpage $<
+ $(A2X) --format=manpage $<
CLEANFILES = runner.out defaults.out runner.c defaults.c
@@ -46,14 +47,14 @@
defaults.o: defaults.c
runner.c: runner.out bin2carray.lua
- lua ./bin2carray.lua $< runner $@
+ $(LUA) ./bin2carray.lua $< runner $@
defaults.c: defaults.out bin2carray.lua
- lua ./bin2carray.lua $< defaults $@
+ $(LUA) ./bin2carray.lua $< defaults $@
runner.out: lsyncd.lua
- luac -o $@ $<
+ $(LUAC) -o $@ $<
defaults.out: default.lua default-rsync.lua default-rsyncssh.lua default-direct.lua
- luac -o $@ $^
+ $(LUAC) -o $@ $^
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/Makefile.in
^
|
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.11.3 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -17,6 +17,23 @@
VPATH = @srcdir@
+am__make_dryrun = \
+ { \
+ am__dry=no; \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
+ | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+ *) \
+ for am__flg in $$MAKEFLAGS; do \
+ case $$am__flg in \
+ *=*|--*) ;; \
+ *n*) am__dry=yes; break;; \
+ esac; \
+ done;; \
+ esac; \
+ test $$am__dry = yes; \
+ }
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -42,7 +59,8 @@
$(srcdir)/config.h.in $(top_srcdir)/configure COPYING \
ChangeLog depcomp install-sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_subst_l.m4 \
+ $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
@@ -72,6 +90,11 @@
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(lsyncd_SOURCES)
DIST_SOURCES = $(am__lsyncd_SOURCES_DIST)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@@ -122,6 +145,7 @@
am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
| sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
distcleancheck_listfiles = find . -type f -print
+A2X = @A2X@
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
@@ -151,6 +175,16 @@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
+LUA = @LUA@
+LUA51 = @LUA51@
+LUA51_CFLAGS = @LUA51_CFLAGS@
+LUA51_LIBS = @LUA51_LIBS@
+LUA52 = @LUA52@
+LUA52_CFLAGS = @LUA52_CFLAGS@
+LUA52_LIBS = @LUA52_LIBS@
+LUAC = @LUAC@
+LUAC51 = @LUAC51@
+LUAC52 = @LUAC52@
LUA_CFLAGS = @LUA_CFLAGS@
LUA_LIBS = @LUA_LIBS@
MAKEINFO = @MAKEINFO@
@@ -213,7 +247,7 @@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-AUTOMAKE_OPTIONS = foreign
+ACLOCAL_AMFLAGS = -I m4
lsyncd_SOURCES = lsyncd.h lsyncd.c lsyncd.lua default-rsync.lua \
$(am__append_1) $(am__append_2)
@@ -299,8 +333,11 @@
-rm -f config.h stamp-h1
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
- test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
+ fi; \
for p in $$list; do echo "$$p $$p"; done | \
sed 's/$(EXEEXT)$$//' | \
while read p p1; do if test -f $$p; \
@@ -363,9 +400,18 @@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
install-man1: $(dist_man1_MANS)
@$(NORMAL_INSTALL)
- test -z "$(man1dir)" || $(MKDIR_P) "$(DESTDIR)$(man1dir)"
- @list='$(dist_man1_MANS)'; test -n "$(man1dir)" || exit 0; \
- { for i in $$list; do echo "$$i"; done; \
+ @list1='$(dist_man1_MANS)'; \
+ list2=''; \
+ test -n "$(man1dir)" \
+ && test -n "`echo $$list1$$list2`" \
+ || exit 0; \
+ echo " $(MKDIR_P) '$(DESTDIR)$(man1dir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(man1dir)" || exit 1; \
+ { for i in $$list1; do echo "$$i"; done; \
+ if test -n "$$list2"; then \
+ for i in $$list2; do echo "$$i"; done \
+ | sed -n '/\.1[a-z]*$$/p'; \
+ fi; \
} | while read p; do \
if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; echo "$$p"; \
@@ -395,8 +441,11 @@
dir='$(DESTDIR)$(man1dir)'; $(am__uninstall_files_from_dir)
install-dist_exampleDATA: $(dist_example_DATA)
@$(NORMAL_INSTALL)
- test -z "$(exampledir)" || $(MKDIR_P) "$(DESTDIR)$(exampledir)"
@list='$(dist_example_DATA)'; test -n "$(exampledir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(exampledir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(exampledir)" || exit 1; \
+ fi; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
@@ -668,7 +717,7 @@
*.zip*) \
unzip $(distdir).zip ;;\
esac
- chmod -R a-w $(distdir); chmod a+w $(distdir)
+ chmod -R a-w $(distdir); chmod u+w $(distdir)
mkdir $(distdir)/_build
mkdir $(distdir)/_inst
chmod a-w $(distdir)
@@ -867,22 +916,22 @@
doc/lsyncd.1: doc/lsyncd.1.txt
- a2x --format=manpage $<
+ $(A2X) --format=manpage $<
runner.o: runner.c
defaults.o: defaults.c
runner.c: runner.out bin2carray.lua
- lua ./bin2carray.lua $< runner $@
+ $(LUA) ./bin2carray.lua $< runner $@
defaults.c: defaults.out bin2carray.lua
- lua ./bin2carray.lua $< defaults $@
+ $(LUA) ./bin2carray.lua $< defaults $@
runner.out: lsyncd.lua
- luac -o $@ $<
+ $(LUAC) -o $@ $<
defaults.out: default.lua default-rsync.lua default-rsyncssh.lua default-direct.lua
- luac -o $@ $^
+ $(LUAC) -o $@ $^
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/aclocal.m4
^
|
@@ -1,4 +1,4 @@
-# generated automatically by aclocal 1.11.3 -*- Autoconf -*-
+# generated automatically by aclocal 1.11.6 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
@@ -14,8 +14,8 @@
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
-m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],,
-[m4_warning([this file was generated for autoconf 2.68.
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
+[m4_warning([this file was generated for autoconf 2.69.
You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically `autoreconf'.])])
@@ -198,7 +198,7 @@
[am__api_version='1.11'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
-m4_if([$1], [1.11.3], [],
+m4_if([$1], [1.11.6], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
@@ -214,7 +214,7 @@
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.11.3])dnl
+[AM_AUTOMAKE_VERSION([1.11.6])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
@@ -1129,3 +1129,4 @@
AC_SUBST([am__untar])
]) # _AM_PROG_TAR
+m4_include([m4/ax_subst_l.m4])
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/configure
^
|
@@ -1,13 +1,11 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for lsyncd 2.0.7.
+# Generated by GNU Autoconf 2.69 for lsyncd 2.1.4.
#
# Report bugs to <axkibe@gmail.com>.
#
#
-# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
-# Foundation, Inc.
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
#
#
# This configure script is free software; the Free Software Foundation
@@ -136,6 +134,31 @@
# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+# Use a proper internal environment variable to ensure we don't fall
+ # into an infinite loop, continuously re-executing ourselves.
+ if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+ _as_can_reexec=no; export _as_can_reexec;
+ # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+ *v*x* | *x*v* ) as_opts=-vx ;;
+ *v* ) as_opts=-v ;;
+ *x* ) as_opts=-x ;;
+ * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+ fi
+ # We don't want this to propagate to other subprocesses.
+ { _as_can_reexec=; unset _as_can_reexec;}
if test "x$CONFIG_SHELL" = x; then
as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
emulate sh
@@ -169,7 +192,8 @@
else
exitcode=1; echo positional parameters were not saved.
fi
-test x\$exitcode = x0 || exit 1"
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
@@ -214,21 +238,25 @@
if test "x$CONFIG_SHELL" != x; then :
- # We cannot yet assume a decent shell, so we have to provide a
- # neutralization value for shells without unset; and this also
- # works around shells that cannot unset nonexistent variables.
- # Preserve -v and -x to the replacement shell.
- BASH_ENV=/dev/null
- ENV=/dev/null
- (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
- export CONFIG_SHELL
- case $- in # ((((
- *v*x* | *x*v* ) as_opts=-vx ;;
- *v* ) as_opts=-v ;;
- *x* ) as_opts=-x ;;
- * ) as_opts= ;;
- esac
- exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"}
+ export CONFIG_SHELL
+ # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+ *v*x* | *x*v* ) as_opts=-vx ;;
+ *v* ) as_opts=-v ;;
+ *x* ) as_opts=-x ;;
+ * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
fi
if test x$as_have_required = xno; then :
@@ -331,6 +359,14 @@
} # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+ test -f "$1" && test -x "$1"
+} # as_fn_executable_p
# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
@@ -452,6 +488,10 @@
chmod +x "$as_me.lineno" ||
{ $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+ # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+ # already done that, so ensure we don't try to do so again and fall
+ # in an infinite loop. This has already happened in practice.
+ _as_can_reexec=no; export _as_can_reexec
# Don't try to exec as it changes $[0], causing all sort of problems
# (the dirname of $[0] is not the place where we might find the
# original and so on. Autoconf is especially sensitive to this).
@@ -486,16 +526,16 @@
# ... but there are two gotchas:
# 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
# 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
- # In both cases, we have to default to `cp -p'.
+ # In both cases, we have to default to `cp -pR'.
ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
elif ln conf$$.file conf$$ 2>/dev/null; then
as_ln_s=ln
else
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
fi
else
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
fi
rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
rmdir conf$$.dir 2>/dev/null
@@ -507,28 +547,8 @@
as_mkdir_p=false
fi
-if test -x / >/dev/null 2>&1; then
- as_test_x='test -x'
-else
- if ls -dL / >/dev/null 2>&1; then
- as_ls_L_option=L
- else
- as_ls_L_option=
- fi
- as_test_x='
- eval sh -c '\''
- if test -d "$1"; then
- test -d "$1/.";
- else
- case $1 in #(
- -*)set "./$1";;
- esac;
- case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
- ???[sx]*):;;*)false;;esac;fi
- '\'' sh
- '
-fi
-as_executable_p=$as_test_x
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -560,8 +580,8 @@
# Identity of this package.
PACKAGE_NAME='lsyncd'
PACKAGE_TARNAME='lsyncd'
-PACKAGE_VERSION='2.0.7'
-PACKAGE_STRING='lsyncd 2.0.7'
+PACKAGE_VERSION='2.1.4'
+PACKAGE_STRING='lsyncd 2.1.4'
PACKAGE_BUGREPORT='axkibe@gmail.com'
PACKAGE_URL=''
@@ -613,11 +633,22 @@
EGREP
GREP
CPP
+LUAC
+LUA
LUA_LIBS
LUA_CFLAGS
+LUAC51
+LUA51
+LUA51_LIBS
+LUA51_CFLAGS
+LUAC52
+LUA52
+LUA52_LIBS
+LUA52_CFLAGS
PKG_CONFIG_LIBDIR
PKG_CONFIG_PATH
PKG_CONFIG
+A2X
am__fastdepCC_FALSE
am__fastdepCC_TRUE
CCDEPMODE
@@ -714,6 +745,10 @@
PKG_CONFIG
PKG_CONFIG_PATH
PKG_CONFIG_LIBDIR
+LUA52_CFLAGS
+LUA52_LIBS
+LUA51_CFLAGS
+LUA51_LIBS
LUA_CFLAGS
LUA_LIBS
CPP'
@@ -1172,8 +1207,6 @@
if test "x$host_alias" != x; then
if test "x$build_alias" = x; then
cross_compiling=maybe
- $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host.
- If a cross compiler is detected then cross compile mode will be used" >&2
elif test "x$build_alias" != "x$host_alias"; then
cross_compiling=yes
fi
@@ -1259,7 +1292,7 @@
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures lsyncd 2.0.7 to adapt to many kinds of systems.
+\`configure' configures lsyncd 2.1.4 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1325,7 +1358,7 @@
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of lsyncd 2.0.7:";;
+ short | recursive ) echo "Configuration of lsyncd 2.1.4:";;
esac
cat <<\_ACEOF
@@ -1356,6 +1389,12 @@
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
+ LUA52_CFLAGS
+ C compiler flags for LUA52, overriding pkg-config
+ LUA52_LIBS linker flags for LUA52, overriding pkg-config
+ LUA51_CFLAGS
+ C compiler flags for LUA51, overriding pkg-config
+ LUA51_LIBS linker flags for LUA51, overriding pkg-config
LUA_CFLAGS C compiler flags for LUA, overriding pkg-config
LUA_LIBS linker flags for LUA, overriding pkg-config
CPP C preprocessor
@@ -1426,10 +1465,10 @@
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-lsyncd configure 2.0.7
-generated by GNU Autoconf 2.68
+lsyncd configure 2.1.4
+generated by GNU Autoconf 2.69
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2012 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
@@ -1478,6 +1517,52 @@
} # ac_fn_c_try_compile
+# ac_fn_c_try_link LINENO
+# -----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_link ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ rm -f conftest.$ac_objext conftest$ac_exeext
+ if { { ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+ (eval "$ac_link") 2>conftest.err
+ ac_status=$?
+ if test -s conftest.err; then
+ grep -v '^ *+' conftest.err >conftest.er1
+ cat conftest.er1 >&5
+ mv -f conftest.er1 conftest.err
+ fi
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest$ac_exeext && {
+ test "$cross_compiling" = yes ||
+ test -x conftest$ac_exeext
+ }; then :
+ ac_retval=0
+else
+ $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_retval=1
+fi
+ # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+ # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+ # interfere with the next link command; also delete a directory that is
+ # left behind by Apple's compiler. We do this before executing the actions.
+ rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+ as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_link
+
# ac_fn_c_try_cpp LINENO
# ----------------------
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
@@ -1682,8 +1767,8 @@
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by lsyncd $as_me 2.0.7, which was
-generated by GNU Autoconf 2.68. Invocation command line was
+It was created by lsyncd $as_me 2.1.4, which was
+generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -2030,9 +2115,6 @@
ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-ac_config_headers="$ac_config_headers config.h"
-
am__api_version='1.11'
ac_aux_dir=
@@ -2101,7 +2183,7 @@
# by default.
for ac_prog in ginstall scoinst install; do
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
if test $ac_prog = install &&
grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
# AIX install. It has an incompatible calling convention.
@@ -2270,7 +2352,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_STRIP="${ac_tool_prefix}strip"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -2310,7 +2392,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_STRIP="strip"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -2361,7 +2443,7 @@
test -z "$as_dir" && as_dir=.
for ac_prog in mkdir gmkdir; do
for ac_exec_ext in '' $ac_executable_extensions; do
- { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue
+ as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue
case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
'mkdir (GNU coreutils) '* | \
'mkdir (coreutils) '* | \
@@ -2414,7 +2496,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_AWK="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -2499,8 +2581,8 @@
# Define the identity of the package.
- PACKAGE=lsyncd
- VERSION=2.0.7
+ PACKAGE='lsyncd'
+ VERSION='2.1.4'
cat >>confdefs.h <<_ACEOF
@@ -2540,6 +2622,13 @@
+
+
+
+ac_config_headers="$ac_config_headers config.h"
+
+
+###
# Checks for programs.
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
@@ -2563,7 +2652,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="${ac_tool_prefix}gcc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -2603,7 +2692,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_CC="gcc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -2656,7 +2745,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="${ac_tool_prefix}cc"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -2697,7 +2786,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
ac_prog_rejected=yes
continue
@@ -2755,7 +2844,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -2799,7 +2888,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_ac_ct_CC="$ac_prog"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -3245,8 +3334,7 @@
/* end confdefs.h. */
#include <stdarg.h>
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
@@ -3555,8 +3643,55 @@
fi
+# Extract the first word of "a2x", so it can be a program name with args.
+set dummy a2x; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_A2X+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $A2X in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_A2X="$A2X" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_A2X="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ test -z "$ac_cv_path_A2X" && ac_cv_path_A2X="no"
+ ;;
+esac
+fi
+A2X=$ac_cv_path_A2X
+if test -n "$A2X"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $A2X" >&5
+$as_echo "$A2X" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+if test x${A2X} = xno ; then
+ as_fn_error $? "Program 'a2x' (package asciidoc) is required" "$LINENO" 5
+fi
+
###
-# Checks for lua
+# Checks for Lua
+
+# Try versioned Lua 5.2 first
@@ -3584,7 +3719,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -3627,7 +3762,7 @@
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
@@ -3679,19 +3814,19 @@
fi
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA52" >&5
+$as_echo_n "checking for LUA52... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA52_CFLAGS"; then
+ pkg_cv_LUA52_CFLAGS="$LUA52_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua5.1 >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua5.1 >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_CFLAGS=`$PKG_CONFIG --cflags "lua5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3699,16 +3834,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA52_LIBS"; then
+ pkg_cv_LUA52_LIBS="$LUA52_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua5.1 >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua5.1 >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_LIBS=`$PKG_CONFIG --libs "lua5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3729,29 +3864,29 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua5.1 >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua5.2" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua5.1 >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua5.2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
+ echo "$LUA52_PKG_ERRORS" >&5
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA52" >&5
+$as_echo_n "checking for LUA52... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA52_CFLAGS"; then
+ pkg_cv_LUA52_CFLAGS="$LUA52_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua51 >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua51 >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua52\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua52") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua51 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_CFLAGS=`$PKG_CONFIG --cflags "lua52" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3759,16 +3894,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA52_LIBS"; then
+ pkg_cv_LUA52_LIBS="$LUA52_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua51 >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua51 >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua52\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua52") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua51 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_LIBS=`$PKG_CONFIG --libs "lua52" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3789,29 +3924,29 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua51 >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua52" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua51 >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua52" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
+ echo "$LUA52_PKG_ERRORS" >&5
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA52" >&5
+$as_echo_n "checking for LUA52... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA52_CFLAGS"; then
+ pkg_cv_LUA52_CFLAGS="$LUA52_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua-5.1 >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua-5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_CFLAGS=`$PKG_CONFIG --cflags "lua-5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3819,16 +3954,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA52_LIBS"; then
+ pkg_cv_LUA52_LIBS="$LUA52_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua-5.1 >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua-5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_LIBS=`$PKG_CONFIG --libs "lua-5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3849,29 +3984,45 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.2" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
+ echo "$LUA52_PKG_ERRORS" >&5
+
+ :
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ :
+else
+ LUA52_CFLAGS=$pkg_cv_LUA52_CFLAGS
+ LUA52_LIBS=$pkg_cv_LUA52_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA52" >&5
+$as_echo_n "checking for LUA52... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA52_CFLAGS"; then
+ pkg_cv_LUA52_CFLAGS="$LUA52_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_CFLAGS=`$PKG_CONFIG --cflags "lua-5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3879,16 +4030,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA52_LIBS"; then
+ pkg_cv_LUA52_LIBS="$LUA52_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_LIBS=`$PKG_CONFIG --libs "lua-5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3909,41 +4060,29 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.2" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
-
- as_fn_error $? "Package requirements (lua >= 5.1.3) were not met:
-
-$LUA_PKG_ERRORS
+ echo "$LUA52_PKG_ERRORS" >&5
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+ :
elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
+ :
+else
+ LUA52_CFLAGS=$pkg_cv_LUA52_CFLAGS
+ LUA52_LIBS=$pkg_cv_LUA52_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
+ LUA52_CFLAGS=$pkg_cv_LUA52_CFLAGS
+ LUA52_LIBS=$pkg_cv_LUA52_LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
@@ -3955,19 +4094,19 @@
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA52" >&5
+$as_echo_n "checking for LUA52... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA52_CFLAGS"; then
+ pkg_cv_LUA52_CFLAGS="$LUA52_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua52\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua52") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_CFLAGS=`$PKG_CONFIG --cflags "lua52" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -3975,16 +4114,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA52_LIBS"; then
+ pkg_cv_LUA52_LIBS="$LUA52_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua52\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua52") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_LIBS=`$PKG_CONFIG --libs "lua52" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4005,73 +4144,29 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua52" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua52" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
-
- as_fn_error $? "Package requirements (lua >= 5.1.3) were not met:
-
-$LUA_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
-elif test $pkg_failed = untried; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
-else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
+ echo "$LUA52_PKG_ERRORS" >&5
-else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
-
-elif test $pkg_failed = untried; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA52" >&5
+$as_echo_n "checking for LUA52... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA52_CFLAGS"; then
+ pkg_cv_LUA52_CFLAGS="$LUA52_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua-5.1 >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua-5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_CFLAGS=`$PKG_CONFIG --cflags "lua-5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4079,16 +4174,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA52_LIBS"; then
+ pkg_cv_LUA52_LIBS="$LUA52_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua-5.1 >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua-5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_LIBS=`$PKG_CONFIG --libs "lua-5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4109,29 +4204,45 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.2" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
+ echo "$LUA52_PKG_ERRORS" >&5
+
+ :
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ :
+else
+ LUA52_CFLAGS=$pkg_cv_LUA52_CFLAGS
+ LUA52_LIBS=$pkg_cv_LUA52_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA52" >&5
+$as_echo_n "checking for LUA52... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA52_CFLAGS"; then
+ pkg_cv_LUA52_CFLAGS="$LUA52_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_CFLAGS=`$PKG_CONFIG --cflags "lua-5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4139,16 +4250,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA52_LIBS"; then
+ pkg_cv_LUA52_LIBS="$LUA52_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.2\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.2") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA52_LIBS=`$PKG_CONFIG --libs "lua-5.2" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4169,65 +4280,157 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.2" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA52_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
-
- as_fn_error $? "Package requirements (lua >= 5.1.3) were not met:
-
-$LUA_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
+ echo "$LUA52_PKG_ERRORS" >&5
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+ :
elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
+ :
else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
+ LUA52_CFLAGS=$pkg_cv_LUA52_CFLAGS
+ LUA52_LIBS=$pkg_cv_LUA52_LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
fi
-elif test $pkg_failed = untried; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+else
+ LUA52_CFLAGS=$pkg_cv_LUA52_CFLAGS
+ LUA52_LIBS=$pkg_cv_LUA52_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+
+else
+ LUA52_CFLAGS=$pkg_cv_LUA52_CFLAGS
+ LUA52_LIBS=$pkg_cv_LUA52_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
+for ac_prog in lua5.2 lua52
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_LUA52+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $LUA52 in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LUA52="$LUA52" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_LUA52="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+LUA52=$ac_cv_path_LUA52
+if test -n "$LUA52"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LUA52" >&5
+$as_echo "$LUA52" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$LUA52" && break
+done
+test -n "$LUA52" || LUA52="no"
+
+for ac_prog in luac5.2 luac52
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_LUAC52+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $LUAC52 in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LUAC52="$LUAC52" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_LUAC52="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+LUAC52=$ac_cv_path_LUAC52
+if test -n "$LUAC52"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LUAC52" >&5
+$as_echo "$LUAC52" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$LUAC52" && break
+done
+test -n "$LUAC52" || LUAC52="no"
+
+
+if test -z "${LUA52_PKG_ERRORS}" -a "${LUA52}" != no -a "${LUAC52}" != no ; then
+ LUA_VERSION="5.2"
+ LUA_CFLAGS="${LUA52_CFLAGS}"
+ LUA_LIBS="${LUA52_LIBS}"
+ LUA="${LUA52}"
+ LUAC="${LUAC52}"
+else
+ # Fall back to versioned Lua 5.1
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA51" >&5
+$as_echo_n "checking for LUA51... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA51_CFLAGS"; then
+ pkg_cv_LUA51_CFLAGS="$LUA51_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua5.1 >= 5.1.3\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua5.1 >= 5.1.3") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_CFLAGS=`$PKG_CONFIG --cflags "lua5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4235,16 +4438,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA51_LIBS"; then
+ pkg_cv_LUA51_LIBS="$LUA51_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua5.1 >= 5.1.3\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua5.1 >= 5.1.3") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_LIBS=`$PKG_CONFIG --libs "lua5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4265,73 +4468,21 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua5.1 >= 5.1.3" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua5.1 >= 5.1.3" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
-
- as_fn_error $? "Package requirements (lua >= 5.1.3) were not met:
+ echo "$LUA51_PKG_ERRORS" >&5
-$LUA_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
-elif test $pkg_failed = untried; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
-else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
-
-else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
-
-else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
-
-elif test $pkg_failed = untried; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA51" >&5
+$as_echo_n "checking for LUA51... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA51_CFLAGS"; then
+ pkg_cv_LUA51_CFLAGS="$LUA51_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua51 >= 5.1.3\""; } >&5
@@ -4339,7 +4490,7 @@
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua51 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_CFLAGS=`$PKG_CONFIG --cflags "lua51 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4347,8 +4498,8 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA51_LIBS"; then
+ pkg_cv_LUA51_LIBS="$LUA51_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua51 >= 5.1.3\""; } >&5
@@ -4356,7 +4507,7 @@
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua51 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_LIBS=`$PKG_CONFIG --libs "lua51 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4377,21 +4528,21 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua51 >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua51 >= 5.1.3" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua51 >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua51 >= 5.1.3" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
+ echo "$LUA51_PKG_ERRORS" >&5
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA51" >&5
+$as_echo_n "checking for LUA51... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA51_CFLAGS"; then
+ pkg_cv_LUA51_CFLAGS="$LUA51_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
@@ -4399,7 +4550,7 @@
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua-5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_CFLAGS=`$PKG_CONFIG --cflags "lua-5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4407,8 +4558,8 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA51_LIBS"; then
+ pkg_cv_LUA51_LIBS="$LUA51_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
@@ -4416,7 +4567,7 @@
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua-5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_LIBS=`$PKG_CONFIG --libs "lua-5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4437,29 +4588,45 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
+ echo "$LUA51_PKG_ERRORS" >&5
+ :
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ :
+else
+ LUA51_CFLAGS=$pkg_cv_LUA51_CFLAGS
+ LUA51_LIBS=$pkg_cv_LUA51_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
+
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA51" >&5
+$as_echo_n "checking for LUA51... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA51_CFLAGS"; then
+ pkg_cv_LUA51_CFLAGS="$LUA51_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.1 >= 5.1.3") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_CFLAGS=`$PKG_CONFIG --cflags "lua-5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4467,16 +4634,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA51_LIBS"; then
+ pkg_cv_LUA51_LIBS="$LUA51_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.1 >= 5.1.3") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_LIBS=`$PKG_CONFIG --libs "lua-5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4497,41 +4664,29 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
-
- as_fn_error $? "Package requirements (lua >= 5.1.3) were not met:
-
-$LUA_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
+ echo "$LUA51_PKG_ERRORS" >&5
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+ :
elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
+ :
+else
+ LUA51_CFLAGS=$pkg_cv_LUA51_CFLAGS
+ LUA51_LIBS=$pkg_cv_LUA51_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
+ LUA51_CFLAGS=$pkg_cv_LUA51_CFLAGS
+ LUA51_LIBS=$pkg_cv_LUA51_LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
@@ -4543,19 +4698,19 @@
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA51" >&5
+$as_echo_n "checking for LUA51... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA51_CFLAGS"; then
+ pkg_cv_LUA51_CFLAGS="$LUA51_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua51 >= 5.1.3\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua51 >= 5.1.3") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_CFLAGS=`$PKG_CONFIG --cflags "lua51 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4563,16 +4718,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA51_LIBS"; then
+ pkg_cv_LUA51_LIBS="$LUA51_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua51 >= 5.1.3\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua51 >= 5.1.3") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_LIBS=`$PKG_CONFIG --libs "lua51 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4593,65 +4748,21 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua51 >= 5.1.3" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua51 >= 5.1.3" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
-
- as_fn_error $? "Package requirements (lua >= 5.1.3) were not met:
-
-$LUA_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
-elif test $pkg_failed = untried; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
-else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
-
-else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
+ echo "$LUA51_PKG_ERRORS" >&5
-elif test $pkg_failed = untried; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA51" >&5
+$as_echo_n "checking for LUA51... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA51_CFLAGS"; then
+ pkg_cv_LUA51_CFLAGS="$LUA51_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
@@ -4659,7 +4770,7 @@
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua-5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_CFLAGS=`$PKG_CONFIG --cflags "lua-5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4667,8 +4778,8 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA51_LIBS"; then
+ pkg_cv_LUA51_LIBS="$LUA51_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
@@ -4676,7 +4787,7 @@
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua-5.1 >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_LIBS=`$PKG_CONFIG --libs "lua-5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4697,29 +4808,45 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
+ echo "$LUA51_PKG_ERRORS" >&5
+
+ :
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ :
+else
+ LUA51_CFLAGS=$pkg_cv_LUA51_CFLAGS
+ LUA51_LIBS=$pkg_cv_LUA51_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
-$as_echo_n "checking for LUA... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA51" >&5
+$as_echo_n "checking for LUA51... " >&6; }
-if test -n "$LUA_CFLAGS"; then
- pkg_cv_LUA_CFLAGS="$LUA_CFLAGS"
+if test -n "$LUA51_CFLAGS"; then
+ pkg_cv_LUA51_CFLAGS="$LUA51_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.1 >= 5.1.3") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_CFLAGS=`$PKG_CONFIG --cflags "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_CFLAGS=`$PKG_CONFIG --cflags "lua-5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4727,16 +4854,16 @@
else
pkg_failed=untried
fi
-if test -n "$LUA_LIBS"; then
- pkg_cv_LUA_LIBS="$LUA_LIBS"
+if test -n "$LUA51_LIBS"; then
+ pkg_cv_LUA51_LIBS="$LUA51_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua >= 5.1.3\""; } >&5
- ($PKG_CONFIG --exists --print-errors "lua >= 5.1.3") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lua-5.1 >= 5.1.3\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "lua-5.1 >= 5.1.3") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_LUA_LIBS=`$PKG_CONFIG --libs "lua >= 5.1.3" 2>/dev/null`
+ pkg_cv_LUA51_LIBS=`$PKG_CONFIG --libs "lua-5.1 >= 5.1.3" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
@@ -4757,51 +4884,143 @@
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- LUA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
else
- LUA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua >= 5.1.3" 2>&1`
+ LUA51_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lua-5.1 >= 5.1.3" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
- echo "$LUA_PKG_ERRORS" >&5
-
- as_fn_error $? "Package requirements (lua >= 5.1.3) were not met:
-
-$LUA_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
+ echo "$LUA51_PKG_ERRORS" >&5
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+ :
elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
+ :
+else
+ LUA51_CFLAGS=$pkg_cv_LUA51_CFLAGS
+ LUA51_LIBS=$pkg_cv_LUA51_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
+ LUA51_CFLAGS=$pkg_cv_LUA51_CFLAGS
+ LUA51_LIBS=$pkg_cv_LUA51_LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
fi
-elif test $pkg_failed = untried; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+else
+ LUA51_CFLAGS=$pkg_cv_LUA51_CFLAGS
+ LUA51_LIBS=$pkg_cv_LUA51_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi
+ for ac_prog in lua5.1 lua51
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_LUA51+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $LUA51 in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LUA51="$LUA51" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_LUA51="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+LUA51=$ac_cv_path_LUA51
+if test -n "$LUA51"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LUA51" >&5
+$as_echo "$LUA51" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
+fi
+ test -n "$LUA51" && break
+done
+test -n "$LUA51" || LUA51="no"
+
+ for ac_prog in luac5.1 luac51
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_LUAC51+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $LUAC51 in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LUAC51="$LUAC51" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_LUAC51="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+LUAC51=$ac_cv_path_LUAC51
+if test -n "$LUAC51"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LUAC51" >&5
+$as_echo "$LUAC51" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ test -n "$LUAC51" && break
+done
+test -n "$LUAC51" || LUAC51="no"
+
+
+ if test -z "${LUA51_PKG_ERRORS}" -a "${LUA51}" != no -a "${LUAC51}" != no ; then
+ LUA_VERSION="5.1"
+ LUA_CFLAGS="${LUA51_CFLAGS}"
+ LUA_LIBS="${LUA51_LIBS}"
+ LUA="${LUA51}"
+ LUAC="${LUAC51}"
+ else
+ # Try any Lua now
+
pkg_failed=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LUA" >&5
$as_echo_n "checking for LUA... " >&6; }
@@ -4860,31 +5079,11 @@
# Put the nasty error message in config.log where it belongs
echo "$LUA_PKG_ERRORS" >&5
- as_fn_error $? "Package requirements (lua >= 5.1.3) were not met:
-
-$LUA_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+ :
elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables LUA_CFLAGS
-and LUA_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
+ :
else
LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
LUA_LIBS=$pkg_cv_LUA_LIBS
@@ -4892,34 +5091,148 @@
$as_echo "yes" >&6; }
fi
-
+ # Extract the first word of "lua", so it can be a program name with args.
+set dummy lua; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_LUA+:} false; then :
+ $as_echo_n "(cached) " >&6
else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
+ case $LUA in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LUA="$LUA" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_LUA="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+ test -z "$ac_cv_path_LUA" && ac_cv_path_LUA="no"
+ ;;
+esac
fi
+LUA=$ac_cv_path_LUA
+if test -n "$LUA"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LUA" >&5
+$as_echo "$LUA" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ # Extract the first word of "luac", so it can be a program name with args.
+set dummy luac; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_LUAC+:} false; then :
+ $as_echo_n "(cached) " >&6
else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
+ case $LUAC in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LUAC="$LUAC" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_LUAC="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+ test -z "$ac_cv_path_LUAC" && ac_cv_path_LUAC="no"
+ ;;
+esac
fi
+LUAC=$ac_cv_path_LUAC
+if test -n "$LUAC"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LUAC" >&5
+$as_echo "$LUAC" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+ if test -z "${LUA_PKG_ERRORS}" -a "${LUA}" != no -a "${LUAC}" != no ; then
+ LUA_VERSION="(unknown version)"
+ else
+ as_fn_error $? "Need a Lua toolchain with matching versions ('lua' library and 'lua' and 'luac' programs)" "$LINENO" 5
+ fi
+ fi
+fi
+
+_LIBS="${LIBS}"
+_CFLAGS="${CFLAGS}"
+_CPPFLAGS="${CPPFLAGS}"
+LIBS="${LIBS} ${LUA_LIBS}"
+CFLAGS="${CFLAGS} ${LUA_CFLAGS}"
+CPPFLAGS="${CPPFLAGS} ${LUA_CFLAGS}"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether Lua library was compiled with compat support" >&5
+$as_echo_n "checking whether Lua library was compiled with compat support... " >&6; }
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+ #define LUA_COMPAT_ALL
+ #include <lauxlib.h>
+int
+main ()
+{
+luaL_register(0,0,0);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ lua_compat_support=yes
else
- LUA_CFLAGS=$pkg_cv_LUA_CFLAGS
- LUA_LIBS=$pkg_cv_LUA_LIBS
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
+ lua_compat_support=no
fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lua_compat_support}" >&5
+$as_echo "${lua_compat_support}" >&6; }
+
+if test "x${lua_compat_support}" = xno ; then
+ as_fn_error $? "Lua library needs to be compiled with compat support" "$LINENO" 5
+fi
+
+LIBS="${_LIBS}"
+CFLAGS="${_CFLAGS}"
+CPPFLAGS="${_CPPFLAGS}"
+unset _LIBS _CFLAGS _CPPFLAGS
+
+
+
+
+
###
# Checks for header files.
-
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -5074,7 +5387,7 @@
for ac_prog in grep ggrep; do
for ac_exec_ext in '' $ac_executable_extensions; do
ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
- { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+ as_fn_executable_p "$ac_path_GREP" || continue
# Check for GNU ac_path_GREP and select it if it is found.
# Check for GNU $ac_path_GREP
case `"$ac_path_GREP" --version 2>&1` in
@@ -5140,7 +5453,7 @@
for ac_prog in egrep; do
for ac_exec_ext in '' $ac_executable_extensions; do
ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
- { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+ as_fn_executable_p "$ac_path_EGREP" || continue
# Check for GNU ac_path_EGREP and select it if it is found.
# Check for GNU $ac_path_EGREP
case `"$ac_path_EGREP" --version 2>&1` in
@@ -5816,16 +6129,16 @@
# ... but there are two gotchas:
# 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
# 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
- # In both cases, we have to default to `cp -p'.
+ # In both cases, we have to default to `cp -pR'.
ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
elif ln conf$$.file conf$$ 2>/dev/null; then
as_ln_s=ln
else
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
fi
else
- as_ln_s='cp -p'
+ as_ln_s='cp -pR'
fi
rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
rmdir conf$$.dir 2>/dev/null
@@ -5885,28 +6198,16 @@
as_mkdir_p=false
fi
-if test -x / >/dev/null 2>&1; then
- as_test_x='test -x'
-else
- if ls -dL / >/dev/null 2>&1; then
- as_ls_L_option=L
- else
- as_ls_L_option=
- fi
- as_test_x='
- eval sh -c '\''
- if test -d "$1"; then
- test -d "$1/.";
- else
- case $1 in #(
- -*)set "./$1";;
- esac;
- case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
- ???[sx]*):;;*)false;;esac;fi
- '\'' sh
- '
-fi
-as_executable_p=$as_test_x
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+ test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -5927,8 +6228,8 @@
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by lsyncd $as_me 2.0.7, which was
-generated by GNU Autoconf 2.68. Invocation command line was
+This file was extended by lsyncd $as_me 2.1.4, which was
+generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
CONFIG_HEADERS = $CONFIG_HEADERS
@@ -5993,11 +6294,11 @@
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-lsyncd config.status 2.0.7
-configured by $0, generated by GNU Autoconf 2.68,
+lsyncd config.status 2.1.4
+configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2012 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."
@@ -6088,7 +6389,7 @@
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
if \$ac_cs_recheck; then
- set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+ set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
shift
\$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
CONFIG_SHELL='$SHELL'
@@ -6854,4 +7155,11 @@
fi
-
+{ $as_echo "$as_me:${as_lineno-$LINENO}:
+Summary:
+ Using Lua ${LUA_VERSION}
+" >&5
+$as_echo "$as_me:
+Summary:
+ Using Lua ${LUA_VERSION}
+" >&6;}
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/configure.ac
^
|
@@ -1,24 +1,102 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
+
#AC_PREREQ(2.60)
-AC_INIT(lsyncd, 2.0.7, axkibe@gmail.com)
+AC_INIT(lsyncd, 2.1.4, axkibe@gmail.com)
+AM_INIT_AUTOMAKE([foreign])
+
+AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([lsyncd.c])
AC_CONFIG_HEADER([config.h])
-AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
+
+###
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
+AC_PATH_PROG([A2X], [a2x], [no])
+if test x${A2X} = xno ; then
+ AC_MSG_ERROR([Program 'a2x' (package asciidoc) is required])
+fi
+
###
-# Checks for lua
-PKG_CHECK_MODULES([LUA], [lua5.1 >= 5.1.3],,[
-PKG_CHECK_MODULES([LUA], [lua51 >= 5.1.3],,[
-PKG_CHECK_MODULES([LUA], [lua-5.1 >= 5.1.3],,[
-PKG_CHECK_MODULES([LUA], [lua >= 5.1.3])
-])
-])
+# Checks for Lua
+
+# Try versioned Lua 5.2 first
+PKG_CHECK_MODULES([LUA52], [lua5.2],,[
+ PKG_CHECK_MODULES([LUA52], [lua52],,[
+ PKG_CHECK_MODULES([LUA52], [lua-5.2],,[:])
+ ])
])
+AC_PATH_PROGS([LUA52], [lua5.2 lua52], [no])
+AC_PATH_PROGS([LUAC52], [luac5.2 luac52], [no])
+
+if test -z "${LUA52_PKG_ERRORS}" -a "${LUA52}" != no -a "${LUAC52}" != no ; then
+ LUA_VERSION="5.2"
+ LUA_CFLAGS="${LUA52_CFLAGS}"
+ LUA_LIBS="${LUA52_LIBS}"
+ LUA="${LUA52}"
+ LUAC="${LUAC52}"
+else
+ # Fall back to versioned Lua 5.1
+ PKG_CHECK_MODULES([LUA51], [lua5.1 >= 5.1.3],,[
+ PKG_CHECK_MODULES([LUA51], [lua51 >= 5.1.3],,[
+ PKG_CHECK_MODULES([LUA51], [lua-5.1 >= 5.1.3],,[:])
+ ])
+ ])
+ AC_PATH_PROGS([LUA51], [lua5.1 lua51], [no])
+ AC_PATH_PROGS([LUAC51], [luac5.1 luac51], [no])
+
+ if test -z "${LUA51_PKG_ERRORS}" -a "${LUA51}" != no -a "${LUAC51}" != no ; then
+ LUA_VERSION="5.1"
+ LUA_CFLAGS="${LUA51_CFLAGS}"
+ LUA_LIBS="${LUA51_LIBS}"
+ LUA="${LUA51}"
+ LUAC="${LUAC51}"
+ else
+ # Try any Lua now
+ PKG_CHECK_MODULES([LUA], [lua >= 5.1.3],,[:])
+ AC_PATH_PROG([LUA], [lua], [no])
+ AC_PATH_PROG([LUAC], [luac], [no])
+
+ if test -z "${LUA_PKG_ERRORS}" -a "${LUA}" != no -a "${LUAC}" != no ; then
+ LUA_VERSION="(unknown version)"
+ else
+ AC_MSG_ERROR([Need a Lua toolchain with matching versions ('lua' library and 'lua' and 'luac' programs)])
+ fi
+ fi
+fi
+
+_LIBS="${LIBS}"
+_CFLAGS="${CFLAGS}"
+_CPPFLAGS="${CPPFLAGS}"
+LIBS="${LIBS} ${LUA_LIBS}"
+CFLAGS="${CFLAGS} ${LUA_CFLAGS}"
+CPPFLAGS="${CPPFLAGS} ${LUA_CFLAGS}"
+
+AC_MSG_CHECKING([whether Lua library was compiled with compat support])
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([
+ #define LUA_COMPAT_ALL
+ #include <lauxlib.h>
+ ],[luaL_register(0,0,0);])],
+ [lua_compat_support=yes],
+ [lua_compat_support=no]
+)
+AC_MSG_RESULT([${lua_compat_support}])
+
+if test "x${lua_compat_support}" = xno ; then
+ AC_MSG_ERROR([Lua library needs to be compiled with compat support])
+fi
+
+LIBS="${_LIBS}"
+CFLAGS="${_CFLAGS}"
+CPPFLAGS="${_CPPFLAGS}"
+unset _LIBS _CFLAGS _CPPFLAGS
+
+AX_SUBST_L([LUA_CFLAGS], [LUA_LIBS], [LUA], [LUAC])
+
###
# Checks for header files.
@@ -55,4 +133,7 @@
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
-
+AC_MSG_NOTICE([
+Summary:
+ Using Lua ${LUA_VERSION}
+])
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/default-direct.lua
^
|
@@ -9,6 +9,7 @@
-- Note:
-- this is infact just a configuration using Layer 1 configuration
-- like any other. It only gets compiled into the binary by default.
+--
-- You can simply use a modified one, by copying everything into a
-- config file of yours and name it differently.
--
@@ -17,158 +18,190 @@
--
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-if not default then error('default not loaded'); end
-if not default.rsync then error('default-direct (currently) needs default.rsync loaded'); end
-if default.direct then error('default-direct already loaded'); end
-
-default.direct = {
- -----
- -- Spawns rsync for a list of events
+if not default then
+ error('default not loaded')
+end
+
+if not default.rsync then
+ error('default-direct (currently) needs default.rsync loaded')
+end
+
+if default.direct then
+ error('default-direct already loaded')
+end
+
+local direct = { }
+
+default.direct = direct
+
+
+--
+-- known configuration parameters
+--
+direct.checkgauge = {
--
- action = function(inlet)
- -- gets all events ready for syncing
- local event, event2 = inlet.getEvent()
- local config = inlet.getConfig()
-
- if event.etype == 'Create' then
- if event.isdir then
- spawn(
- event,
- '/bin/mkdir',
- event.targetPath
- )
- else
- -- 'cp -t', not supported on OSX
- spawn(
- event,
- '/bin/cp',
- event.sourcePath,
- event.targetPathdir
- )
- end
- elseif event.etype == 'Modify' then
- if event.isdir then
- error("Do not know how to handle 'Modify' on dirs")
- end
- spawn(event,
+ -- inherits rsync config params
+ --
+ default.rsync.checkgauge,
+
+ rsyncExitCodes = true,
+ onMove = true,
+}
+
+
+--
+-- Spawns rsync for a list of events
+--
+direct.action = function(inlet)
+ -- gets all events ready for syncing
+ local event, event2 = inlet.getEvent()
+ local config = inlet.getConfig()
+
+ if event.etype == 'Create' then
+ if event.isdir then
+ spawn(
+ event,
+ '/bin/mkdir',
+ event.targetPath
+ )
+ else
+ -- 'cp -t', not supported on OSX
+ spawn(
+ event,
'/bin/cp',
event.sourcePath,
event.targetPathdir
)
- elseif event.etype == 'Delete' then
- if not config.delete then
- inlet.discardEvent(event)
- end
-
- local tp = event.targetPath
- -- extra security check
- if tp == '' or tp == '/' or not tp then
- error('Refusing to erase your harddisk!')
- end
- spawn(event, '/bin/rm', '-rf', tp)
- elseif event.etype == 'Move' then
- local tp = event.targetPath
- -- extra security check
- if tp == '' or tp == '/' or not tp then
- error('Refusing to erase your harddisk!')
- end
- local command = '/bin/mv $1 $2 || /bin/rm -rf $1'
- if not config.delete then command = '/bin/mv $1 $2'; end
- spawnShell(
- event,
- command,
- event.targetPath,
- event2.targetPath)
- else
- log('Warn', 'ignored an event of type "',event.etype, '"')
+ end
+ elseif event.etype == 'Modify' then
+ if event.isdir then
+ error("Do not know how to handle 'Modify' on dirs")
+ end
+ spawn(event,
+ '/bin/cp',
+ event.sourcePath,
+ event.targetPathdir
+ )
+ elseif event.etype == 'Delete' then
+
+ if
+ config.delete ~= true and
+ config.delete ~= 'running'
+ then
inlet.discardEvent(event)
+ return
end
- end,
- -----
- -- Called when collecting a finished child process
- --
- collect = function(agent, exitcode)
- local config = agent.config
+ local tp = event.targetPath
- if not agent.isList and agent.etype == 'Init' then
- local rc = config.rsyncExitCodes[exitcode]
- if rc == 'ok' then
- log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
- elseif rc == 'again' then
- if settings.insist then
- log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode)
- else
- log('Error', 'Temporary or permanent failure on startup of "',
- agent.source, '". Terminating since "insist" is not set.');
- terminate(-1) -- ERRNO
- end
- elseif rc == 'die' then
- log('Error', 'Failure on startup of "',agent.source,'": ', exitcode)
- else
- log('Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode)
- rc = 'die'
- end
- return rc
+ -- extra security check
+ if tp == '' or tp == '/' or not tp then
+ error('Refusing to erase your harddisk!')
end
- -- everything else is just as it is,
- -- there is no network to retry something.
- return
- end,
+ spawn(event, '/bin/rm', '-rf', tp)
- -----
- -- Spawns the recursive startup sync
- -- (currently) identical to default rsync.
- --
- init = default.rsync.init,
+ elseif event.etype == 'Move' then
+ local tp = event.targetPath
- -----
- -- Checks the configuration.
- --
- prepare = function(config)
- if not config.target then
- error('default.direct needs "target".', 4)
+ -- extra security check
+ if tp == '' or tp == '/' or not tp then
+ error('Refusing to erase your harddisk!')
end
- if config.rsyncOps then
- error('did you mean rsyncOpts with "t"?', 4)
+ local command = '/bin/mv $1 $2 || /bin/rm -rf $1'
+
+ if
+ config.delete ~= true and
+ config.delete ~= 'running'
+ then
+ command = '/bin/mv $1 $2'
end
- end,
- -----
- -- Default delay is very short.
- --
- delay = 1,
+ spawnShell(
+ event,
+ command,
+ event.targetPath,
+ event2.targetPath
+ )
+
+ else
+ log('Warn', 'ignored an event of type "',event.etype, '"')
+ inlet.discardEvent(event)
+ end
+end
- ------
- -- Let the core not split move events.
- --
- onMove = true,
+--
+-- Called when collecting a finished child process
+--
+direct.collect = function(agent, exitcode)
- -----
- -- The rsync binary called.
- --
- rsyncBinary = '/usr/bin/rsync',
+ local config = agent.config
- -----
- -- For startup sync
- --
- rsyncOpts = '-lts',
+ if not agent.isList and agent.etype == 'Init' then
+ local rc = config.rsyncExitCodes[exitcode]
+ if rc == 'ok' then
+ log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
+ elseif rc == 'again' then
+ if settings.insist then
+ log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode)
+ else
+ log('Error', 'Temporary or permanent failure on startup of "',
+ agent.source, '". Terminating since "insist" is not set.');
+ terminate(-1) -- ERRNO
+ end
+ elseif rc == 'die' then
+ log('Error', 'Failure on startup of "',agent.source,'": ', exitcode)
+ else
+ log('Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode)
+ rc = 'die'
+ end
+ return rc
+ end
- -----
- -- By default do deletes.
- --
- delete = true,
+ -- everything else is just as it is,
+ -- there is no network to retry something.
+ return
+end
- -----
- -- rsync exit codes
- --
- rsyncExitCodes = default.rsyncExitCodes,
+--
+-- Spawns the recursive startup sync
+-- (currently) identical to default rsync.
+--
+direct.init = default.rsync.init
- -----
- -- On many system multiple disk operations just rather slow down
- -- than speed up.
+--
+-- Checks the configuration.
+--
+direct.prepare = function( config, level )
- maxProcesses = 1,
-}
+ default.rsync.prepare( config, level + 1 )
+
+end
+
+--
+-- Default delay is very short.
+--
+direct.delay = 1
+
+--
+-- Let the core not split move events.
+--
+direct.onMove = true
+
+--
+-- Rsync configuration for startup.
+--
+direct.rsync = default.rsync.rsync
+direct.rsyncExitCodes = default.rsyncExitCodes
+
+--
+-- By default do deletes.
+--
+direct.delete = true
+
+--
+-- On many system multiple disk operations just rather slow down
+-- than speed up.
+
+direct.maxProcesses = 1
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/default-rsync.lua
^
|
@@ -15,171 +15,508 @@
--
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-if not default then error('default not loaded'); end
-if default.rsync then error('default-rsync already loaded'); end
-default.rsync = {
- -----
- -- Spawns rsync for a list of events
- --
- action = function(inlet)
- -- gets all events ready for syncing
- local elist = inlet.getEvents(
- function(event)
- return event.etype ~= 'Init' and event.etype ~= 'Blanket'
- end
- )
+if not default then
+ error( 'default not loaded' )
+end
- -----
- -- replaces filter rule by literals
- --
- local function sub(p)
- if not p then
- return
- end
- return p:gsub('%?', '\\?'):
- gsub('%*', '\\*'):
- gsub('%[', '\\['):
- gsub('%]', '\\]')
- end
-
- local paths = elist.getPaths(
- function(etype, path1, path2)
- if string.byte(path1, -1) == 47 and etype == 'Delete' then
- return sub(path1)..'***', sub(path2)
- else
- return sub(path1), sub(path2)
- end
- end)
- -- stores all filters with integer index
- -- local filterI = inlet.getExcludes();
- local filterI = {}
- -- stores all filters with path index
- local filterP = {}
-
- -- adds one entry into the filter
- -- @param path ... path to add
- -- @param leaf ... true if this the original path
- -- false if its a parent
- local function addToFilter(path)
- if filterP[path] then
- return
+
+if default.rsync then
+ error( 'default-rsync already loaded' )
+end
+
+
+local rsync = { }
+default.rsync = rsync
+
+-- uses default collect
+
+--
+-- used to ensure there aren't typos in the keys
+--
+rsync.checkgauge = {
+
+ -- unsets default user action handlers
+ onCreate = false,
+ onModify = false,
+ onDelete = false,
+ onStartup = false,
+ onMove = false,
+
+ delete = true,
+ exclude = true,
+ excludeFrom = true,
+ target = true,
+
+ rsync = {
+ acls = true,
+ archive = true,
+ binary = true,
+ checksum = true,
+ compress = true,
+ copy_links = true,
+ cvs_exclude = true,
+ dry_run = true,
+ executability = true,
+ group = true,
+ hard_links = true,
+ ignore_times = true,
+ ipv4 = true,
+ ipv6 = true,
+ keep_dirlinks = true,
+ links = true,
+ one_file_system = true,
+ owner = true,
+ perms = true,
+ protect_args = true,
+ prune_empty_dirs = true,
+ quiet = true,
+ rsh = true,
+ rsync_path = true,
+ sparse = true,
+ temp_dir = true,
+ times = true,
+ update = true,
+ verbose = true,
+ whole_file = true,
+ xattrs = true,
+ _extra = true,
+ },
+}
+
+
+--
+-- Spawns rsync for a list of events
+--
+-- Exlcusions are already handled by not having
+-- events for them.
+--
+rsync.action = function( inlet )
+
+ --
+ -- gets all events ready for syncing
+ --
+ local elist = inlet.getEvents(
+ function(event)
+ return event.etype ~= 'Init' and event.etype ~= 'Blanket'
+ end
+ )
+
+ --
+ -- Replaces what rsync would consider filter rules by literals
+ --
+ local function sub( p )
+ if not p then
+ return
+ end
+
+ return p:
+ gsub( '%?', '\\?' ):
+ gsub( '%*', '\\*' ):
+ gsub( '%[', '\\[' ):
+ gsub( '%]', '\\]' )
+ end
+
+ --
+ -- Gets the list of paths for the event list
+ --
+ -- Deletes create multi match patterns
+ --
+ local paths = elist.getPaths(
+ function( etype, path1, path2 )
+ if string.byte( path1, -1 ) == 47 and etype == 'Delete' then
+ return sub( path1 )..'***', sub( path2 )
+ else
+ return sub( path1 ), sub( path2 )
end
- filterP[path]=true
- table.insert(filterI, path)
end
+ )
- -- adds a path to the filter, for rsync this needs
- -- to have entries for all steps in the path, so the file
- -- d1/d2/d3/f1 needs filters
- -- 'd1/', 'd1/d2/', 'd1/d2/d3/' and 'd1/d2/d3/f1'
- for _, path in ipairs(paths) do
- if path and path ~= '' then
- addToFilter(path)
- local pp = string.match(path, '^(.*/)[^/]+/?')
- while pp do
- addToFilter(pp)
- pp = string.match(pp, '^(.*/)[^/]+/?')
- end
+ --
+ -- stores all filters by integer index
+ --
+ local filterI = { }
+
+ --
+ -- Stores all filters with path index
+ --
+ local filterP = { }
+
+ --
+ -- Adds one path to the filter
+ --
+ local function addToFilter( path )
+
+ if filterP[ path ] then
+ return
+ end
+
+ filterP[ path ] = true
+
+ table.insert( filterI, path )
+ end
+
+ --
+ -- Adds a path to the filter.
+ --
+ -- Rsync needs to have entries for all steps in the path,
+ -- so the file for example d1/d2/d3/f1 needs following filters:
+ -- 'd1/', 'd1/d2/', 'd1/d2/d3/' and 'd1/d2/d3/f1'
+ --
+ for _, path in ipairs( paths ) do
+
+ if path and path ~= '' then
+
+ addToFilter(path)
+
+ local pp = string.match( path, '^(.*/)[^/]+/?' )
+
+ while pp do
+ addToFilter(pp)
+ pp = string.match( pp, '^(.*/)[^/]+/?' )
end
+
end
- local filterS = table.concat(filterI, '\n')
- local filter0 = table.concat(filterI, '\000')
- log('Normal', 'Calling rsync with filter-list of new/modified files/dirs\n', filterS)
- local config = inlet.getConfig()
- local delete = nil
- if config.delete then delete = { '--delete', '--ignore-errors' }; end
- spawn(elist, config.rsyncBinary,
- '<', filter0,
- config.rsyncOpts,
+ end
+
+ local filterS = table.concat( filterI, '\n' )
+ local filter0 = table.concat( filterI, '\000' )
+
+ log(
+ 'Normal',
+ 'Calling rsync with filter-list of new/modified files/dirs\n',
+ filterS
+ )
+
+ local config = inlet.getConfig( )
+ local delete = nil
+
+ if config.delete == true or config.delete == 'running' then
+ delete = { '--delete', '--ignore-errors' }
+ end
+
+ spawn(
+ elist,
+ config.rsync.binary,
+ '<', filter0,
+ config.rsync._computed,
+ '-r',
+ delete,
+ '--force',
+ '--from0',
+ '--include-from=-',
+ '--exclude=*',
+ config.source,
+ config.target
+ )
+
+end
+
+
+--
+-- Spawns the recursive startup sync
+--
+rsync.init = function(event)
+
+ local config = event.config
+ local inlet = event.inlet
+ local excludes = inlet.getExcludes( )
+ local delete = nil
+ local target = config.target
+
+ if not target then
+ if not config.host then
+ error('Internal fail, Neither target nor host is configured')
+ end
+
+ target = config.host .. ':' .. config.targetdir
+ end
+
+ if config.delete == true or config.delete == 'startup' then
+ delete = { '--delete', '--ignore-errors' }
+ end
+
+ if #excludes == 0 then
+ -- start rsync without any excludes
+ log(
+ 'Normal',
+ 'recursive startup rsync: ',
+ config.source,
+ ' -> ',
+ target
+ )
+
+ spawn(
+ event,
+ config.rsync.binary,
+ delete,
+ config.rsync._computed,
'-r',
+ config.source,
+ target
+ )
+
+ else
+ -- start rsync providing an exclude list
+ -- on stdin
+ local exS = table.concat( excludes, '\n' )
+
+ log(
+ 'Normal',
+ 'recursive startup rsync: ',
+ config.source,
+ ' -> ',
+ target,
+ ' excluding\n',
+ exS
+ )
+
+ spawn(
+ event,
+ config.rsync.binary,
+ '<', exS,
+ '--exclude-from=-',
delete,
- '--force',
- '--from0',
- '--include-from=-',
- '--exclude=*',
+ config.rsync._computed,
+ '-r',
config.source,
- config.target)
- end,
+ target
+ )
+ end
+end
- -----
- -- Spawns the recursive startup sync
- --
- init = function(event)
- local config = event.config
- local inlet = event.inlet
- local excludes = inlet.getExcludes()
- local delete = nil
- if config.delete then delete = { '--delete', '--ignore-errors' }; end
-
- if #excludes == 0 then
- log('Normal', 'recursive startup rsync: ', config.source, ' -> ', config.target)
- spawn(event, config.rsyncBinary,
- delete,
- config.rsyncOpts,
- '-r',
- config.source,
- config.target)
- else
- local exS = table.concat(excludes, '\n')
- log('Normal', 'recursive startup rsync: ',config.source,
- ' -> ',config.target,' excluding\n',exS)
- spawn(event, config.rsyncBinary,
- '<', exS,
- '--exclude-from=-',
- delete,
- config.rsyncOpts,
- '-r',
- config.source,
- config.target)
- end
- end,
-
- -----
- -- Checks the configuration.
- --
- prepare = function(config)
- if not config.target then
- error('default.rsync needs "target" configured', 4)
- end
-
- if config.rsyncOps then
- error('did you mean rsyncOpts with "t"?', 4)
- end
-
- -- appends a / to target if not present
- if string.sub(config.target, -1) ~= '/' then
- config.target = config.target..'/'
- end
- end,
-
- -----
- -- rsync uses default collect
- ----
- -----
- -- By default do deletes.
- --
- delete = true,
+--
+-- Prepares and checks a syncs configuration on startup.
+--
+rsync.prepare = function(
+ config, -- the configuration
+ level, -- additional error level for inherited use ( by rsyncssh )
+ skipTarget -- used by rsyncssh, do not check for target
+)
- -----
- -- The rsync binary to be called.
--
- rsyncBinary = '/usr/bin/rsync',
+ -- First let default.prepare test the checkgauge
+ --
+ default.prepare( config, level + 6 )
+
+ if not skipTarget and not config.target then
+ error(
+ 'default.rsync needs "target" configured',
+ level
+ )
+ end
+
+ if config.rsyncOps then
+ error(
+ '"rsyncOps" is outdated please use the new rsync = { ... } syntax.',
+ level
+ )
+ end
+
+ if config.rsyncOpts and config.rsync._extra then
+ error(
+ '"rsyncOpts" is outdated in favor of the new rsync = { ... } syntax\n"' +
+ 'for which you provided the _extra attribute as well.\n"' +
+ 'Please remove rsyncOpts from your config.',
+ level
+ )
+ end
+
+ if config.rsyncOpts then
+ log(
+ 'Warn',
+ '"rsyncOpts" is outdated. Please use the new rsync = { ... } syntax."'
+ )
+
+ config.rsync._extra = config.rsyncOpts
+ config.rsyncOpts = nil
+ end
+
+ if config.rsyncBinary and config.rsync.binary then
+ error(
+ '"rsyncBinary is outdated in favor of the new rsync = { ... } syntax\n"'+
+ 'for which you provided the binary attribute as well.\n"' +
+ "Please remove rsyncBinary from your config.'",
+ level
+ )
+ end
+
+ if config.rsyncBinary then
+ log(
+ 'Warn',
+ '"rsyncBinary" is outdated. Please use the new rsync = { ... } syntax."'
+ )
+
+ config.rsync.binary = config.rsyncBinary
+ config.rsyncOpts = nil
+ end
+
+ -- checks if the _computed argument exists already
+ if config.rsync._computed then
+ error(
+ 'please do not use the internal rsync._computed parameter',
+ level
+ )
+ end
- -----
- -- Calls rsync with this default short opts.
--
- rsyncOpts = '-lts',
+ -- computes the rsync arguments into one list
+ --
+ local crsync = config.rsync;
- -----
- -- Exit codes for rsync.
--
- exitcodes = default.rsyncExitCodes,
+ -- everything implied by archive = true
+ --
+ local archiveFlags = {
+ recursive = true,
+ links = true,
+ perms = true,
+ times = true,
+ group = true,
+ owner = true,
+ devices = true,
+ specials = true,
+ hard_links = false,
+ acls = false,
+ xattrs = false,
+ }
- -----
- -- Default delay
--
- delay = 15,
+ -- if archive given the implications are filled in
+ --
+ if crsync.archive then
+ for k, v in pairs( archiveFlags ) do
+ if crsync[ k ] == nil then
+ crsync[ k ] = v
+ end
+ end
+ end
+
+
+ crsync._computed = { true }
+ local computed = crsync._computed
+ local computedN = 2
+
+ local shortFlags = {
+ acls = 'A',
+ checksum = 'c',
+ compress = 'z',
+ copy_links = 'L',
+ cvs_exclude = 'C',
+ dry_run = 'n',
+ executability = 'E',
+ group = 'g',
+ hard_links = 'H',
+ ignore_times = 'I',
+ ipv4 = '4',
+ ipv6 = '6',
+ keep_dirlinks = 'K',
+ links = 'l',
+ one_file_system = 'x',
+ owner = 'o',
+ perms = 'p',
+ protect_args = 's',
+ prune_empty_dirs = 'm',
+ quiet = 'q',
+ sparse = 'S',
+ times = 't',
+ update = 'u',
+ verbose = 'v',
+ whole_file = 'W',
+ xattrs = 'X',
+ }
+
+ local shorts = { '-' }
+ local shortsN = 2
+
+ if crsync._extra then
+ for k, v in ipairs( crsync._extra ) do
+ computed[ computedN ] = v
+ computedN = computedN + 1
+ end
+ end
+
+ for k, flag in pairs( shortFlags ) do
+ if crsync[ k ] then
+ shorts[ shortsN ] = flag
+ shortsN = shortsN + 1
+ end
+ end
+
+ if crsync.devices and crsync.specials then
+ shorts[ shortsN ] = 'D'
+ shortsN = shortsN + 1
+ else
+ if crsync.devices then
+ computed[ computedN ] = '--devices'
+ computedN = computedN + 1
+ end
+
+ if crsync.specials then
+ computed[ computedN ] = '--specials'
+ computedN = computedN + 1
+ end
+ end
+
+ if crsync.password_file then
+ computed[ computedN ] = '--password-file=' .. crsync.password_file
+ computedN = computedN + 1
+ end
+
+ if crsync.rsh then
+ computed[ computedN ] = '--rsh=' .. crsync.rsh
+ computedN = computedN + 1
+ end
+
+ if crsync.rsync_path then
+ computed[ computedN ] = '--rsync-path=' .. crsync.rsync_path
+ computedN = computedN + 1
+ end
+
+ if crsync.temp_dir then
+ computed[ computedN ] = '--temp-dir=' .. crsync.temp_dir
+ computedN = computedN + 1
+ end
+
+ if shortsN ~= 2 then
+ computed[ 1 ] = table.concat( shorts, '' )
+ else
+ computed[ 1 ] = { }
+ end
+
+ -- appends a / to target if not present
+ if not skipTarget and string.sub(config.target, -1) ~= '/' then
+ config.target = config.target..'/'
+ end
+
+end
+
+
+--
+-- By default do deletes.
+--
+rsync.delete = true
+
+--
+-- Rsyncd exitcodes
+--
+rsync.exitcodes = default.rsyncExitCodes
+
+--
+-- Calls rsync with this default options
+--
+rsync.rsync = {
+ -- The rsync binary to be called.
+ binary = '/usr/bin/rsync',
+ links = true,
+ times = true,
+ protect_args = true
}
+
+
+--
+-- Default delay
+--
+rsync.delay = 15
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/default-rsyncssh.lua
^
|
@@ -1,4 +1,4 @@
---~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--
-- default-rsyncssh.lua
--
-- Improved rsync - sync with rsync, but moves and deletes executed over ssh.
@@ -13,261 +13,382 @@
-- License: GPLv2 (see COPYING) or any later version
-- Authors: Axel Kittenberger <axkibe@gmail.com>
--
---~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--
+
+if not default then
+ error( 'default not loaded' );
+end
+
+if not default.rsync then
+ error( 'default.rsync not loaded' );
+end
+
+if default.rsyncssh then
+ error( 'default-rsyncssh already loaded' );
+end
+
+--
+-- rsyncssh extends default.rsync
+--
+local rsyncssh = { default.rsync }
+default.rsyncssh = rsyncssh
+
+--
+-- used to ensure there aren't typos in the keys
+--
+rsyncssh.checkgauge = {
+
+ -- unsets the inherited value of from default.rsync
+ target = false,
+ onMove = true,
+
+ -- rsyncssh users host and targetdir
+ host = true,
+ targetdir = true,
+ sshExitCodes = true,
+ rsyncExitCodes = true,
+
+ -- ssh settings
+ ssh = {
+ binary = true,
+ port = true,
+ _extra = true
+ },
+
+ -- xargs settings
+ xargs = {
+ binary = true,
+ delimiter = true,
+ _extra = true
+ }
+}
+
+--
+-- Spawns rsync for a list of events
+--
+rsyncssh.action = function( inlet )
-if not default then error('default not loaded'); end
-if default.rsyncssh then error('default-rsyncssh already loaded'); end
+ local event, event2 = inlet.getEvent()
+ local config = inlet.getConfig()
-default.rsyncssh = {
- -----
- -- Spawns rsync for a list of events
- --
- action = function(inlet)
- local event, event2 = inlet.getEvent()
- local config = inlet.getConfig()
-
- -- makes move local on host
- -- if fails deletes the source...
- if event.etype == 'Move' then
- log('Normal', 'Moving ',event.path,' -> ',event2.path)
- spawn(event, '/usr/bin/ssh',
- config.host,
- 'mv',
- '\"' .. config.targetdir .. event.path .. '\"',
- '\"' .. config.targetdir .. event2.path .. '\"',
- '||', 'rm', '-rf',
- '\"' .. config.targetdir .. event.path .. '\"')
+ -- makes move local on target host
+ -- if the move fails, it deletes the source
+ if event.etype == 'Move' then
+ log('Normal', 'Moving ',event.path,' -> ',event2.path)
+
+ spawn(
+ event,
+ config.ssh.binary,
+ config.ssh._computed,
+ config.host,
+ 'mv',
+ '\"' .. config.targetdir .. event.path .. '\"',
+ '\"' .. config.targetdir .. event2.path .. '\"',
+ '||', 'rm', '-rf',
+ '\"' .. config.targetdir .. event.path .. '\"')
+ return
+ end
+
+ -- uses ssh to delete files on remote host
+ -- instead of constructing rsync filters
+
+ if event.etype == 'Delete' then
+
+ if
+ config.delete ~= true and
+ config.delete ~= 'running'
+ then
+ inlet.discardEvent(event)
return
end
- -- uses ssh to delete files on remote host
- -- instead of constructing rsync filters
- if event.etype == 'Delete' then
- if not config.delete then
- inlet.discardEvent(event)
- return
+ -- gets all other deletes ready to be
+ -- executed
+ local elist = inlet.getEvents(
+ function( e )
+ return e.etype == 'Delete'
end
+ )
- local elist = inlet.getEvents(
- function(e)
- return e.etype == 'Delete'
- end)
-
- local paths = elist.getPaths(
- function(etype, path1, path2)
- if path2 then
- return config.targetdir..path1, config.targetdir..path2
- else
- return config.targetdir..path1
- end
- end)
-
- for _, v in pairs(paths) do
- if string.match(v, '^%s*/+%s*$') then
- log('Error', 'refusing to `rm -rf /` the target!')
- terminate(-1) -- ERRNO
+ -- returns the paths of the delete list
+ local paths = elist.getPaths(
+ function( etype, path1, path2 )
+ if path2 then
+ return config.targetdir..path1, config.targetdir..path2
+ else
+ return config.targetdir..path1
end
end
+ )
- local sPaths = table.concat(paths, '\n')
- local zPaths = table.concat(paths, config.xargs.delimiter)
- log('Normal', 'Deleting list\n', sPaths)
- spawn(elist, '/usr/bin/ssh',
- '<', zPaths,
- config.host,
- config.xargs.binary, config.xargs.xparams)
- return
- end
-
- -- for everything else spawn a rsync
- local elist = inlet.getEvents(
- function(e)
- -- TODO use a table
- return e.etype ~= 'Move' and
- e.etype ~= 'Delete' and
- e.etype ~= 'Init' and
- e.etype ~= 'Blanket'
- end)
- local paths = elist.getPaths()
-
- -- removes trailing slashes from dirs.
- for k, v in ipairs(paths) do
- if string.byte(v, -1) == 47 then
- paths[k] = string.sub(v, 1, -2)
+ -- ensures none of the paths is '/'
+ for _, v in pairs( paths ) do
+ if string.match(v, '^%s*/+%s*$') then
+ log('Error', 'refusing to `rm -rf /` the target!')
+ terminate(-1) -- ERRNO
end
end
- local sPaths = table.concat(paths, '\n')
- local zPaths = table.concat(paths, '\000')
- log('Normal', 'Rsyncing list\n', sPaths)
+
+ log(
+ 'Normal',
+ 'Deleting list\n',
+ table.concat( paths, '\n' )
+ )
+
+ local params = { }
+
spawn(
- elist, config.rsyncBinary,
- '<', zPaths,
- config.rsyncOpts,
- '--from0',
- '--files-from=-',
- config.source,
- config.host .. ':' .. config.targetdir
+ elist,
+ config.ssh.binary,
+ '<', table.concat(paths, config.xargs.delimiter),
+ params,
+ config.ssh._computed,
+ config.host,
+ config.xargs.binary,
+ config.xargs._extra
)
- end,
- -----
- -- Called when collecting a finished child process
+ return
+ end
+
+ --
+ -- for everything else a rsync is spawned
--
- collect = function(agent, exitcode)
- local config = agent.config
+ local elist = inlet.getEvents(
+ function(e)
+ -- TODO use a table
+ return e.etype ~= 'Move' and
+ e.etype ~= 'Delete' and
+ e.etype ~= 'Init' and
+ e.etype ~= 'Blanket'
+ end
+ )
- if not agent.isList and agent.etype == 'Init' then
- local rc = config.rsyncExitCodes[exitcode]
- if rc == 'ok' then
- log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
- elseif rc == 'again' then
- if settings.insist then
- log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode)
- else
- log('Error', 'Temporary or permanent failure on startup of "',
- agent.source, '". Terminating since "insist" is not set.');
- terminate(-1) -- ERRNO
- end
- elseif rc == 'die' then
- log('Error', 'Failure on startup of "',agent.source,'": ', exitcode)
- else
- log('Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode)
- rc = 'die'
- end
- return rc
+ local paths = elist.getPaths( )
+
+ --
+ -- removes trailing slashes from dirs.
+ --
+ for k, v in ipairs( paths ) do
+ if string.byte(v, -1) == 47 then
+ paths[k] = string.sub(v, 1, -2)
end
- if agent.isList then
- local rc = config.rsyncExitCodes[exitcode]
- if rc == 'ok' then log('Normal', 'Finished (list): ',exitcode)
- elseif rc == 'again' then log('Normal', 'Retrying (list): ',exitcode)
- elseif rc == 'die' then log('Error', 'Failure (list): ', exitcode)
+ end
+
+ local sPaths = table.concat(paths, '\n')
+ local zPaths = table.concat(paths, '\000')
+
+ log('Normal', 'Rsyncing list\n', sPaths)
+
+ spawn(
+ elist,
+ config.rsync.binary,
+ '<', zPaths,
+ config.rsync._computed,
+ '--from0',
+ '--files-from=-',
+ config.source,
+ config.host .. ':' .. config.targetdir
+ )
+end
+
+-----
+-- Called when collecting a finished child process
+--
+rsyncssh.collect = function( agent, exitcode )
+
+ local config = agent.config
+
+ if not agent.isList and agent.etype == 'Init' then
+ local rc = config.rsyncExitCodes[exitcode]
+
+ if rc == 'ok' then
+ log('Normal', 'Startup of "',agent.source,'" finished: ', exitcode)
+ elseif rc == 'again' then
+ if settings('insist') then
+ log('Normal', 'Retrying startup of "',agent.source,'": ', exitcode)
else
- log('Error', 'Unknown exitcode (list): ',exitcode)
- rc = 'die'
+ log('Error', 'Temporary or permanent failure on startup of "',
+ agent.source, '". Terminating since "insist" is not set.');
+ terminate(-1) -- ERRNO
end
- return rc
+
+ elseif rc == 'die' then
+ log('Error', 'Failure on startup of "',agent.source,'": ', exitcode)
else
- local rc = config.sshExitCodes[exitcode]
- if rc == 'ok' then
- log('Normal', 'Finished ',agent.etype,' ',agent.sourcePath,': ',exitcode)
- elseif rc == 'again' then
- log('Normal', 'Retrying ',agent.etype,' ',agent.sourcePath,': ',exitcode)
- elseif rc == 'die' then
- log('Normal', 'Failure ',agent.etype,' ',agent.sourcePath,': ',exitcode)
- else
- log('Error', 'Unknown exitcode ',agent.etype,' ',agent.sourcePath,': ',exitcode)
- rc = 'die'
- end
- return rc
+ log('Error', 'Unknown exitcode on startup of "', agent.source,': "',exitcode)
+ rc = 'die'
end
- end,
- -----
- -- Spawns the recursive startup sync
- --
- init = function(event)
- local config = event.config
- local inlet = event.inlet
- local excludes = inlet.getExcludes()
- local target = config.host .. ':' .. config.targetdir
- local delete = nil
- if config.delete then delete = { '--delete', '--ignore-errors' }; end
-
- if #excludes == 0 then
- log('Normal', 'Recursive startup rsync: ',config.source,' -> ',target)
- spawn(
- event, config.rsyncBinary,
- delete,
- '-r',
- config.rsyncOpts,
- config.source,
- target
- )
+ return rc
+
+ end
+
+ if agent.isList then
+ local rc = config.rsyncExitCodes[exitcode]
+ if rc == 'ok' then
+ log('Normal', 'Finished (list): ',exitcode)
+ elseif rc == 'again' then
+ log('Normal', 'Retrying (list): ',exitcode)
+ elseif rc == 'die' then
+ log('Error', 'Failure (list): ', exitcode)
else
- local exS = table.concat(excludes, '\n')
- log('Normal', 'Recursive startup rsync: ',config.source,
- ' -> ',target,' with excludes.')
- spawn(
- event, config.rsyncBinary,
- '<', exS,
- '--exclude-from=-',
- delete,
- '-r',
- config.rsyncOpts,
- config.source,
- target
- )
+ log('Error', 'Unknown exitcode (list): ',exitcode)
+ rc = 'die'
end
- end,
+ return rc
+ else
+ local rc = config.sshExitCodes[exitcode]
+
+ if rc == 'ok' then
+ log('Normal', 'Finished ',agent.etype,' ',agent.sourcePath,': ',exitcode)
+ elseif rc == 'again' then
+ log('Normal', 'Retrying ',agent.etype,' ',agent.sourcePath,': ',exitcode)
+ elseif rc == 'die' then
+ log('Normal', 'Failure ',agent.etype,' ',agent.sourcePath,': ',exitcode)
+ else
+ log('Error', 'Unknown exitcode ',agent.etype,' ',agent.sourcePath,': ',exitcode)
+ rc = 'die'
+ end
+
+ return rc
+ end
+
+end
+
+--
+-- checks the configuration.
+--
+rsyncssh.prepare = function( config, level )
+
+ default.rsync.prepare( config, level + 1, true )
+
+ if not config.host then
+ error(
+ 'default.rsyncssh needs "host" configured',
+ level
+ )
+ end
+
+ if not config.targetdir then
+ error(
+ 'default.rsyncssh needs "targetdir" configured',
+ level
+ )
+ end
- -----
- -- Checks the configuration.
--
- prepare = function(config)
- if not config.host then error('default.rsyncssh needs "host" configured', 4) end
- if not config.targetdir then error('default.rsyncssh needs "targetdir" configured', 4) end
+ -- computes the ssh options
+ --
+ if config.ssh._computed then
+ error(
+ 'please do not use the internal rsync._computed parameter',
+ level
+ )
+ end
- if config.rsyncOps then
- error('did you mean rsyncOpts with "t"?', 4)
+ local cssh = config.ssh;
+ cssh._computed = { }
+ local computed = cssh._computed
+ local computedN = 1
+
+ if cssh._extra then
+ for k, v in ipairs( cssh._extra ) do
+ computed[ computedN ] = v
+ computedN = computedN + 1
end
+ end
- -- appends a slash to the targetdir if missing
- if string.sub(config.targetdir, -1) ~= '/' then
- config.targetdir = config.targetdir .. '/'
- end
- end,
+ if cssh.port then
+ computed[ computedN ] = '-p'
+ computed[ computedN + 1 ] = cssh.port
+ computedN = computedN + 2
+
+ local rsyncc = config.rsync._computed
+ rsyncc[ #rsyncc ] = '--rsh=ssh -p ' .. cssh.port
+ end
+
+ -- appends a slash to the targetdir if missing
+ if string.sub(config.targetdir, -1) ~= '/' then
+ config.targetdir = config.targetdir .. '/'
+ end
- -----
- -- The rsync binary called.
- --
- rsyncBinary = '/usr/bin/rsync',
+end
- -----
- -- Calls rsync with this default short opts.
- --
- rsyncOpts = '-lts',
+--
+-- allow processes
+--
+rsyncssh.maxProcesses = 1
+
+--
+-- The core should not split move events
+--
+rsyncssh.onMove = true
+
+--
+-- default delay
+--
+rsyncssh.delay = 15
+
+
+--
+-- no default exit codes
+--
+rsyncssh.exitcodes = false
+
+--
+-- rsync exit codes
+--
+rsyncssh.rsyncExitCodes = default.rsyncExitCodes
+
+--
+-- ssh exit codes
+--
+rsyncssh.sshExitCodes = default.sshExitCodes
+
+--
+-- xargs calls configuration
+--
+-- xargs is used to delete multiple remote files, when ssh access is
+-- available this is simpler than to build filters for rsync for this.
+--
+rsyncssh.xargs = {
- -----
- -- allow processes
--
- maxProcesses = 1,
+ -- the binary called (on target host)
+ binary = '/usr/bin/xargs',
- ------
- -- Let the core not split move events.
--
- onMove = true,
+ -- delimiter, uses null by default, you might want to override this for older
+ -- by for example '\n'
+ delimiter = '\000',
- -----
- -- Default delay.
--
- delay = 15,
+ -- extra parameters
+ _extra = { '-0', 'rm -rf' }
+}
+--
+-- ssh calls configuration
+--
+-- ssh is used to move and delete files on the target host
+--
+rsyncssh.ssh = {
- -----
- -- By default do deletes.
--
- delete = true,
-
- -----
- -- rsync exit codes
+ -- the binary called
--
- rsyncExitCodes = default.rsyncExitCodes,
+ binary = '/usr/bin/ssh',
- -----
- -- ssh exit codes
--
- sshExitCodes = default.sshExitCodes,
+ -- if set connect to this port
+ --
+ port = nil,
- -----
- -- Delimiter, the binary and the paramters passed to xargs
- -- xargs is used to delete multiple remote files, when ssh access is
- -- available this is simpler than to build filters for rsync for this.
- -- Default uses '0' as limiter, you might override this for old systems.
--
- xargs = {
- binary = '/usr/bin/xargs',
- delimiter = '\000',
- xparams = {'-0', 'rm -rf'}
- }
+ -- extra parameters
+ --
+ _extra = { }
}
+
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/default.lua
^
|
@@ -8,159 +8,349 @@
-- Authors: Axel Kittenberger <axkibe@gmail.com>
--============================================================================
-if default then error('default already loaded'); end
+if default then
+ error( 'default already loaded' )
+end
+
+default = { }
+
+
+--
+-- Only this items are inherited from the default
+-- table
+--
+default._merge = {
+ action = true,
+ checkgauge = true,
+ collect = true,
+ delay = true,
+ init = true,
+ maxDelays = true,
+ maxProcesses = true,
+ prepare = true,
+}
-default = {
- -----
- -- Default action calls user scripts on**** functions.
- --
- action = function(inlet)
- -- in case of moves getEvent returns the origin and dest of the move
- local event, event2 = inlet.getEvent()
- local config = inlet.getConfig()
- local func = config['on'.. event.etype]
- if func then
- func(event, event2)
- end
- -- if function didnt change the wait status its not interested
- -- in this event -> drop it.
- if event.status == 'wait' then
- inlet.discardEvent(event)
- end
- end,
+--
+-- used to ensure there aren't typos in the keys
+--
+default.checkgauge = {
+ action = true,
+ checkgauge = true,
+ collect = true,
+ delay = true,
+ exitcodes = true,
+ init = true,
+ maxDelays = true,
+ maxProcesses = true,
+ onCreate = true,
+ onModify = true,
+ onDelete = true,
+ onStartup = true,
+ onMove = true,
+ prepare = true,
+ source = true,
+ target = true,
+}
+--
+-- On default action the user's on*** scripts are called.
+--
+default.action = function( inlet )
+
+ -- in case of moves getEvent returns the origin and dest of the move
+ local event, event2 = inlet.getEvent( )
+ local config = inlet.getConfig( )
+
+ local func = config[ 'on'.. event.etype ]
+
+ if type( func ) == 'function' then
+ func( event, event2 )
+ end
+
+ -- if function didnt change the wait status its not interested
+ -- in this event -> drop it.
+ if event.status == 'wait' then
+ inlet.discardEvent( event )
+ end
+
+end
+
+
+--
+-- Default collector.
+--
+-- Called when collecting a finished child process
+--
+default.collect = function( agent, exitcode )
+
+ local config = agent.config
+ local rc
+
+ if config.exitcodes then
+ rc = config.exitcodes[exitcode]
+ elseif exitcode == 0 then
+ rc = 'ok'
+ else
+ rc = 'die'
+ end
+
+ -- TODO synchronize with similar code before
+ if not agent.isList and agent.etype == 'Init' then
+ if rc == 'ok' then
+ log('Normal', 'Startup of "',agent.source,'" finished.')
+ return 'ok'
+ elseif rc == 'again' then
+ if settings('insist') then
+ log(
+ 'Normal',
+ 'Retrying startup of "',
+ agent.source,
+ '": ',
+ exitcode
+ )
- -----
- -- Default collector.
- --
- -- Called when collecting a finished child process
- --
- collect = function(agent, exitcode)
- local config = agent.config
- local rc
- if config.exitcodes then
- rc = config.exitcodes[exitcode]
- elseif exitcode == 0 then
- rc = 'ok'
- else
- rc = 'die'
- end
-
- -- TODO synchronize with similar code before
- if not agent.isList and agent.etype == 'Init' then
- if rc == 'ok' then
- log('Normal', 'Startup of "',agent.source,'" finished.')
- return 'ok'
- elseif rc == 'again' then
- log('Normal', 'Retrying startup of "',agent.source,'".')
- return "again"
- elseif rc == 'die' then
- log('Error', 'Failure on startup of "',agent.source,'".')
- terminate(-1) -- ERRNO
+ return 'again'
else
- log('Error', 'Unknown exitcode "',exitcode,'" on startup of "',agent.source,'".')
- return 'die'
+ log(
+ 'Error',
+ 'Temporary or permanent failure on startup of "',
+ agent.source,
+ '". Terminating since "insist" is not set.'
+ )
+
+ terminate( -1 )
end
+ elseif rc == 'die' then
+ log(
+ 'Error',
+ 'Failure on startup of "',
+ agent.source,
+ '".'
+ )
+
+ terminate( -1 )
+ else
+ log(
+ 'Error',
+ 'Unknown exitcode "',
+ exitcode,
+ '" on startup of "',
+ agent.source,
+ '".'
+ )
+ return 'die'
end
+ end
- if agent.isList then
- if rc == 'ok' then log('Normal', 'Finished a list = ',exitcode)
- elseif rc == 'again' then log('Normal', 'Retrying a list on exitcode = ',exitcode)
- elseif rc == 'die' then log('Error', 'Failure with a list on exitcode = ',exitcode)
- else
- log('Error', 'Unknown exitcode "',exitcode,'" with a list')
- rc = 'die'
- end
+ if agent.isList then
+ if rc == 'ok' then
+ log(
+ 'Normal',
+ 'Finished a list after exitcode: ',
+ exitcode
+ )
+ elseif rc == 'again' then
+ log(
+ 'Normal',
+ 'Retrying a list after exitcode = ',
+ exitcode
+ )
+ elseif rc == 'die' then
+ log(
+ 'Error',
+ 'Failure with a list width exitcode = ',
+ exitcode
+ )
else
- if rc == 'ok' then
- log('Normal', 'Retrying ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
- elseif rc == 'again' then
- log('Normal', 'Finished ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
- elseif rc == 'die' then
- log('Error', 'Failure with ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
- else
- log('Normal', 'Unknown exitcode "',exitcode,'" with ', agent.etype,
- ' on ',agent.sourcePath,' = ',exitcode)
- rc = 'die'
- end
+ log(
+ 'Error',
+ 'Unknown exitcode "',exitcode,'" with a list'
+ )
+
+ rc = 'die'
end
- return rc
- end,
+ else
+ if rc == 'ok' then
+ log('Normal', 'Retrying ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
+ elseif rc == 'again' then
+ log('Normal', 'Finished ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
+ elseif rc == 'die' then
+ log('Error', 'Failure with ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
+ else
+ log('Normal', 'Unknown exitcode "',exitcode,'" with ', agent.etype,
+ ' on ',agent.sourcePath,' = ',exitcode)
+ rc = 'die'
+ end
+ end
+
+ return rc
+end
+
+
+--
+-- Called on the Init event sent
+-- on (re)initialization of Lsyncd for every sync
+--
+default.init = function(event)
+ local config = event.config
+ local inlet = event.inlet
+
+ -- user functions
+ -- calls a startup if given by user script.
+ if type(config.onStartup) == 'function' then
+ local startup = config.onStartup(event)
+ -- TODO honor some return codes of startup like "warmstart".
+ end
+
+ if event.status == 'wait' then
+ -- user script did not spawn anything
+ -- thus the blanket event is deleted again.
+ inlet.discardEvent(event)
+ end
+end
+
+
+--
+-- The collapsor tries not to have more than these delays.
+-- So it dealy stack does not grow too large,
+-- since calculation for stacking events is n*log(n) (or so)
+--
+default.maxDelays = 1000
+
+
+--
+-- The maximum number of processes Lsyncd will
+-- simultanously spawn for this sync.
+--
+default.maxProcesses = 1
+
+
+--
+-- Exitcodes of rsync and what to do.
+-- TODO move to rsync
+--
+default.rsyncExitCodes = {
- -----
- -- called on (re)initialization of Lsyncd.
--
- init = function(event)
- local config = event.config
- local inlet = event.inlet
- -- user functions
- -- calls a startup if given by user script.
- if type(config.onStartup) == 'function' then
- local startup = config.onStartup(event)
- -- TODO honor some return codes of startup like "warmstart".
- end
+ -- if another config provides the same table
+ -- this will not be inherited (merged) into that one
+ --
+ -- if it does not, integer keys are to be copied
+ -- verbatim
+ --
+ _merge = false,
+ _verbatim = true,
- if event.status == 'wait' then
- -- user script did not spawn anything
- -- thus the blanket event is deleted again.
- inlet.discardEvent(event)
- end
- end,
+ [ 0 ] = 'ok',
+ [ 1 ] = 'die',
+ [ 2 ] = 'die',
+ [ 3 ] = 'again',
+ [ 4 ] = 'die',
+ [ 5 ] = 'again',
+ [ 6 ] = 'again',
+ [ 10 ] = 'again',
+ [ 11 ] = 'again',
+ [ 12 ] = 'again',
+ [ 14 ] = 'again',
+ [ 20 ] = 'again',
+ [ 21 ] = 'again',
+ [ 22 ] = 'again',
+
+ -- partial transfers are ok, since Lsyncd has registered the event that
+ -- caused the transfer to be partial and will recall rsync.
+ [ 23 ] = 'ok',
+ [ 24 ] = 'ok',
+
+ [ 25 ] = 'die',
+ [ 30 ] = 'again',
+ [ 35 ] = 'again',
- -----
- -- The maximum number of processes Lsyncd will spawn simultanously for
- -- one sync.
- --
- maxProcesses = 1,
-
- -----
- -- Try not to have more than these delays.
- -- not too large, since total calculation for stacking
- -- events is n*log(n) or so..
- --
- maxDelays = 1000,
-
- -----
- -- a default configuration using /bin/cp|rm|mv.
- --
- direct = default_direct,
-
- ------
- -- Exitcodes of rsync and what to do.
- --
- rsyncExitCodes = {
- [ 0] = 'ok',
- [ 1] = 'die',
- [ 2] = 'die',
- [ 3] = 'again',
- [ 4] = 'die',
- [ 5] = 'again',
- [ 6] = 'again',
- [ 10] = 'again',
- [ 11] = 'again',
- [ 12] = 'again',
- [ 14] = 'again',
- [ 20] = 'again',
- [ 21] = 'again',
- [ 22] = 'again',
- [ 23] = 'ok', -- partial transfers are ok, since Lsyncd has registered the event that
- [ 24] = 'ok', -- caused the transfer to be partial and will recall rsync.
- [ 25] = 'die',
- [ 30] = 'again',
- [ 35] = 'again',
- [255] = 'again',
- },
-
- -----
- -- Exitcodes of ssh and what to do.
- --
- sshExitCodes = {
- [0] = 'ok',
- [255] = 'again',
- },
+ [ 255 ] = 'again',
+}
- -----
- -- Minimum seconds between two writes of a status file.
+
+--
+-- Exitcodes of ssh and what to do.
+--
+default.sshExitCodes = {
+
+ --
+ -- if another config provides the same table
+ -- this will not be inherited (merged) into that one
--
- statusInterval = 10,
+ -- if it does not, integer keys are to be copied
+ -- verbatim
+ --
+ _merge = false,
+ _verbatim = true,
+
+ [ 0 ] = 'ok',
+ [ 255 ] = 'again',
}
+
+
+--
+-- Minimum seconds between two writes of a status file.
+--
+default.statusInterval = 10
+
+
+--
+-- checks all keys to be in the checkgauge
+--
+
+local function check(
+ config,
+ gauge,
+ subtable,
+ level
+)
+ for k, v in pairs( config ) do
+
+ if not gauge[k] then
+ error(
+ 'Parameter "'
+ .. subtable
+ .. k
+ .. '" unknown.'
+ .. ' (if this is not a typo add it to checkgauge)',
+ level
+ );
+ end
+
+ if type( gauge [ k ] ) == 'table' then
+
+ if type( v ) ~= 'table' then
+
+ error(
+ 'Parameter "'
+ .. subtable
+ .. k
+ .. '" must be a table.',
+ level
+ )
+
+ end
+
+ check(
+ config[ k ],
+ gauge[ k ],
+ subtable .. k .. '.',
+ level + 1
+ )
+
+ end
+ end
+end
+
+default.prepare = function( config, level )
+
+ local gauge = config.checkgauge
+
+ if not gauge then
+ return
+ end
+
+ check( config, gauge, '', level + 1 )
+end
+
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/depcomp
^
|
@@ -1,10 +1,10 @@
#! /bin/sh
# depcomp - compile a program generating dependencies as side-effects
-scriptversion=2011-12-04.11; # UTC
+scriptversion=2012-03-27.16; # UTC
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
-# 2011 Free Software Foundation, Inc.
+# 2011, 2012 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
case $1 in
'')
- echo "$0: No command. Try \`$0 --help' for more information." 1>&2
+ echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
@@ -40,8 +40,8 @@
Environment variables:
depmode Dependency tracking mode.
- source Source file read by `PROGRAMS ARGS'.
- object Object file output by `PROGRAMS ARGS'.
+ source Source file read by 'PROGRAMS ARGS'.
+ object Object file output by 'PROGRAMS ARGS'.
DEPDIR directory where to store dependencies.
depfile Dependency file to output.
tmpdepfile Temporary file to use when outputting dependencies.
@@ -57,6 +57,12 @@
;;
esac
+# A tabulation character.
+tab=' '
+# A newline character.
+nl='
+'
+
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
echo "depcomp: Variables source, object and depmode must be set" 1>&2
exit 1
@@ -102,6 +108,12 @@
depmode=msvc7
fi
+if test "$depmode" = xlc; then
+ # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.
+ gccflag=-qmakedep=gcc,-MF
+ depmode=gcc
+fi
+
case "$depmode" in
gcc3)
## gcc 3 implements dependency tracking that does exactly what
@@ -156,15 +168,14 @@
## The second -e expression handles DOS-style file names with drive letters.
sed -e 's/^[^:]*: / /' \
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
-## This next piece of magic avoids the `deleted header file' problem.
+## This next piece of magic avoids the "deleted header file" problem.
## The problem is that when a header file which appears in a .P file
## is deleted, the dependency causes make to die (because there is
## typically no way to rebuild the header). We avoid this by adding
## dummy dependencies for each header file. Too bad gcc doesn't do
## this for us directly.
- tr ' ' '
-' < "$tmpdepfile" |
-## Some versions of gcc put a space before the `:'. On the theory
+ tr ' ' "$nl" < "$tmpdepfile" |
+## Some versions of gcc put a space before the ':'. On the theory
## that the space means something, we add a space to the output as
## well. hp depmode also adds that space, but also prefixes the VPATH
## to the object. Take care to not repeat it in the output.
@@ -203,18 +214,15 @@
# clever and replace this with sed code, as IRIX sed won't handle
# lines with more than a fixed number of characters (4096 in
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
- # the IRIX cc adds comments like `#:fec' to the end of the
+ # the IRIX cc adds comments like '#:fec' to the end of the
# dependency line.
- tr ' ' '
-' < "$tmpdepfile" \
+ tr ' ' "$nl" < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
- tr '
-' ' ' >> "$depfile"
+ tr "$nl" ' ' >> "$depfile"
echo >> "$depfile"
# The second pass generates a dummy entry for each header file.
- tr ' ' '
-' < "$tmpdepfile" \
+ tr ' ' "$nl" < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
>> "$depfile"
else
@@ -226,10 +234,17 @@
rm -f "$tmpdepfile"
;;
+xlc)
+ # This case exists only to let depend.m4 do its work. It works by
+ # looking at the text of this script. This case will never be run,
+ # since it is checked for above.
+ exit 1
+ ;;
+
aix)
# The C for AIX Compiler uses -M and outputs the dependencies
# in a .u file. In older versions, this file always lives in the
- # current directory. Also, the AIX compiler puts `$object:' at the
+ # current directory. Also, the AIX compiler puts '$object:' at the
# start of each line; $object doesn't have directory information.
# Version 6 uses the directory in both cases.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
@@ -259,12 +274,11 @@
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
- # Each line is of the form `foo.o: dependent.h'.
+ # Each line is of the form 'foo.o: dependent.h'.
# Do two passes, one to just change these to
- # `$object: dependent.h' and one to simply `dependent.h:'.
+ # '$object: dependent.h' and one to simply 'dependent.h:'.
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
- # That's a tab and a space in the [].
- sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+ sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
else
# The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile
@@ -275,23 +289,26 @@
;;
icc)
- # Intel's C compiler understands `-MD -MF file'. However on
- # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
+ # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
+ # However on
+ # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
# ICC 7.0 will fill foo.d with something like
# foo.o: sub/foo.c
# foo.o: sub/foo.h
- # which is wrong. We want:
+ # which is wrong. We want
# sub/foo.o: sub/foo.c
# sub/foo.o: sub/foo.h
# sub/foo.c:
# sub/foo.h:
# ICC 7.1 will output
# foo.o: sub/foo.c sub/foo.h
- # and will wrap long lines using \ :
+ # and will wrap long lines using '\':
# foo.o: sub/foo.c ... \
# sub/foo.h ... \
# ...
-
+ # tcc 0.9.26 (FIXME still under development at the moment of writing)
+ # will emit a similar output, but also prepend the continuation lines
+ # with horizontal tabulation characters.
"$@" -MD -MF "$tmpdepfile"
stat=$?
if test $stat -eq 0; then :
@@ -300,15 +317,21 @@
exit $stat
fi
rm -f "$depfile"
- # Each line is of the form `foo.o: dependent.h',
- # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+ # Each line is of the form 'foo.o: dependent.h',
+ # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
# Do two passes, one to just change these to
- # `$object: dependent.h' and one to simply `dependent.h:'.
- sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
- # Some versions of the HPUX 10.20 sed can't process this invocation
- # correctly. Breaking it into two sed invocations is a workaround.
- sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
- sed -e 's/$/ :/' >> "$depfile"
+ # '$object: dependent.h' and one to simply 'dependent.h:'.
+ sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \
+ < "$tmpdepfile" > "$depfile"
+ sed '
+ s/[ '"$tab"'][ '"$tab"']*/ /g
+ s/^ *//
+ s/ *\\*$//
+ s/^[^:]*: *//
+ /^$/d
+ /:$/d
+ s/$/ :/
+ ' < "$tmpdepfile" >> "$depfile"
rm -f "$tmpdepfile"
;;
@@ -344,7 +367,7 @@
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
- # Add `dependent.h:' lines.
+ # Add 'dependent.h:' lines.
sed -ne '2,${
s/^ *//
s/ \\*$//
@@ -359,9 +382,9 @@
tru64)
# The Tru64 compiler uses -MD to generate dependencies as a side
- # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
+ # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
- # dependencies in `foo.d' instead, so we check for that too.
+ # dependencies in 'foo.d' instead, so we check for that too.
# Subdirectories are respected.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
test "x$dir" = "x$object" && dir=
@@ -407,8 +430,7 @@
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
- # That's a tab and a space in the [].
- sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+ sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
else
echo "#dummy" > "$depfile"
fi
@@ -443,11 +465,11 @@
p
}' | $cygpath_u | sort -u | sed -n '
s/ /\\ /g
-s/\(.*\)/ \1 \\/p
+s/\(.*\)/'"$tab"'\1 \\/p
s/.\(.*\) \\/\1:/
H
$ {
- s/.*/ /
+ s/.*/'"$tab"'/
G
p
}' >> "$depfile"
@@ -478,7 +500,7 @@
shift
fi
- # Remove `-o $object'.
+ # Remove '-o $object'.
IFS=" "
for arg
do
@@ -498,15 +520,14 @@
done
test -z "$dashmflag" && dashmflag=-M
- # Require at least two characters before searching for `:'
+ # Require at least two characters before searching for ':'
# in the target name. This is to cope with DOS-style filenames:
- # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
+ # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
"$@" $dashmflag |
- sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
+ sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
- tr ' ' '
-' < "$tmpdepfile" | \
+ tr ' ' "$nl" < "$tmpdepfile" | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
@@ -562,8 +583,7 @@
# makedepend may prepend the VPATH from the source file name to the object.
# No need to regex-escape $object, excess matching of '.' is harmless.
sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
- sed '1,2d' "$tmpdepfile" | tr ' ' '
-' | \
+ sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
@@ -583,7 +603,7 @@
shift
fi
- # Remove `-o $object'.
+ # Remove '-o $object'.
IFS=" "
for arg
do
@@ -652,8 +672,8 @@
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
- sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
- echo " " >> "$depfile"
+ sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
+ echo "$tab" >> "$depfile"
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
rm -f "$tmpdepfile"
;;
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/doc/lsyncd.1
^
|
@@ -2,12 +2,12 @@
.\" Title: lsyncd
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
-.\" Date: August 2011
+.\" Date: April 2012
.\" Manual: Lsyncd
-.\" Source: Lsyncd 2.0.6
+.\" Source: Lsyncd 2.0.7
.\" Language: English
.\"
-.TH "LSYNCD" "1" "August 2011" "Lsyncd 2\&.0\&.6" "Lsyncd"
+.TH "LSYNCD" "1" "April 2012" "Lsyncd 2\&.0\&.7" "Lsyncd"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -33,30 +33,38 @@
.PP
config file
.RS 4
-\ \&*lsyncd* [\fIOPTIONS\fR]
+\ \&
+\fBlsyncd\fR
+[\fIOPTIONS\fR]
\fICONFIG\-FILE\fR
.RE
.PP
default rsync behaviour
.RS 4
-\ \&*lsyncd* [\fIOPTIONS\fR] \-rsync
+\ \&
+\fBlsyncd\fR
+[\fIOPTIONS\fR] \-rsync
\fISOURCEDIR\fR
\fITARGET\fR
\&...
.RE
.PP
-default rync+ssh bevahiour (moves and deletes through ssh)
+default rync+ssh behaviour (moves and deletes through ssh)
.RS 4
-\ \&*lsyncd* [\fIOPTIONS\fR] \-rsyncssh
+\ \&
+\fBlsyncd\fR
+[\fIOPTIONS\fR] \-rsyncssh
\fISOURCEDIR\fR
\fITARGETHOST\fR
\fITARGETDIR\fR
\&...
.RE
.PP
-default direct bevahiour (local file operations/rsync)
+default direct behaviour (local file operations/rsync)
.RS 4
-\ \&*lsyncd* [\fIOPTIONS\fR] \-direct
+\ \&
+\fBlsyncd\fR
+[\fIOPTIONS\fR] \-direct
\fISOURCEDIR\fR
\fITARGETDIR\fR
\&...
@@ -144,10 +152,10 @@
Online Manual: http://code\&.google\&.com/p/lsyncd/wiki/Lsyncd2
.SH "VERSION"
.sp
-This man page is for lsyncd(1) version 2\&.0\&.5
+This man page is for lsyncd(1) version 2\&.0\&.7
.SH "AUTHOR"
.sp
-Axel Kittenberger, <axkibe@gmail\&.com> 2010\-2011
+Axel Kittenberger, <axkibe@gmail\&.com> 2010\-2012
.SH "COPYING"
.sp
-Copyright (C) 2010\-2011 Axel Kittenberger\&. Free use of this software is granted under the terms of the GNU General Public License (GPL) version 2, or any later version\&. Free redistrubition of this Documentation (/doc directory) is granted under the terms of the Creative Commons 3\&.0 Attribution License (CC\-3\&.0\-BY)\&.
+Copyright (C) 2010\-2012 Axel Kittenberger\&. Free use of this software is granted under the terms of the GNU General Public License (GPL) version 2, or any later version\&. Free redistrubition of this Documentation (/doc directory) is granted under the terms of the Creative Commons 3\&.0 Attribution License (CC\-3\&.0\-BY)\&.
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/doc/lsyncd.1.txt
^
|
@@ -3,8 +3,8 @@
:doctype: manpage
:man source: Lsyncd
:man manual: Lsyncd
-:man version: 2.0.6
-:date: August 2011
+:man version: 2.0.7
+:date: April 2012
NAME
----
@@ -13,16 +13,16 @@
SYNOPSIS
--------
config file:::
- {nbsp}*lsyncd* ['OPTIONS'] 'CONFIG-FILE'
+{nbsp} *lsyncd* ['OPTIONS'] 'CONFIG-FILE'
default rsync behaviour:::
- {nbsp}*lsyncd* ['OPTIONS'] -rsync 'SOURCEDIR' 'TARGET' ...
+{nbsp} *lsyncd* ['OPTIONS'] -rsync 'SOURCEDIR' 'TARGET' ...
-default rync+ssh bevahiour (moves and deletes through ssh):::
- {nbsp}*lsyncd* ['OPTIONS'] -rsyncssh 'SOURCEDIR' 'TARGETHOST' 'TARGETDIR' ...
+default rync+ssh behaviour (moves and deletes through ssh):::
+{nbsp} *lsyncd* ['OPTIONS'] -rsyncssh 'SOURCEDIR' 'TARGETHOST' 'TARGETDIR' ...
-default direct bevahiour (local file operations/rsync):::
- {nbsp}*lsyncd* ['OPTIONS'] -direct 'SOURCEDIR' 'TARGETDIR' ...
+default direct behaviour (local file operations/rsync):::
+{nbsp} *lsyncd* ['OPTIONS'] -direct 'SOURCEDIR' 'TARGETDIR' ...
DESCRIPTION
------------
@@ -92,15 +92,15 @@
VERSION
------
-This man page is for lsyncd(1) version 2.0.5
+This man page is for lsyncd(1) version 2.0.7
AUTHOR
------
-Axel Kittenberger, <axkibe@gmail.com> 2010-2011
+Axel Kittenberger, <axkibe@gmail.com> 2010-2012
COPYING
-------
-Copyright \(C) 2010-2011 Axel Kittenberger. Free use of this software is granted
+Copyright \(C) 2010-2012 Axel Kittenberger. Free use of this software is granted
under the terms of the GNU General Public License (GPL) version 2, or any later
version. Free redistrubition of this Documentation (/doc directory) is granted
under the terms of the Creative Commons 3.0 Attribution License (CC-3.0-BY).
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/examples/lbash.lua
^
|
@@ -1,7 +1,7 @@
-----
-- User configuration file for lsyncd.
---
--- This example uses local bash commands to keep two local
+--
+-- This example uses local bash commands to keep two local
-- directory trees in sync.
--
settings = {
@@ -28,16 +28,16 @@
-- calls `cp -r SOURCE/* TARGET` only when there is something in SOURCE
-- otherwise it deletes contents in the target if there.
onStartup = [[
-if [ "$(ls -A ^source)" ]; then
- cp -r ^source* ^target;
-else
+if [ "$(ls -A ^source)" ]; then
+ cp -r ^source* ^target;
+else
if [ "$(ls -A ^target)" ]; then rm -rf ^target/*; fi
fi]],
onCreate = prefix..[[cp -r ^sourcePath ^targetPathdir]],
-
+
onModify = prefix..[[cp -r ^sourcePath ^targetPathdir]],
-
+
onDelete = prefix..[[rm -rf ^targetPath]],
onMove = prefix..[[mv ^o.targetPath ^d.targetPath]],
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/examples/lecho.lua
^
|
@@ -1,7 +1,7 @@
-----
-- User configuration file for lsyncd.
---
--- This example uses local bash commands to keep two local
+--
+-- This example uses local bash commands to keep two local
-- directory trees in sync.
--
@@ -11,7 +11,7 @@
echo = {
maxProcesses = 1,
delay = 1,
- onStartup = "/bin/echo telling about ^source",
+ onStartup = "/bin/echo telling about ^source",
onAttrib = "/bin/echo attrib ^pathname",
onCreate = "/bin/echo create ^pathname",
onDelete = "/bin/echo delete ^pathname",
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/examples/lgforce.lua
^
|
@@ -1,22 +1,22 @@
-----
-- User configuration file for lsyncd.
---
--- This example refers to a common problem in unix.
---
+--
+-- This example refers to one common challenge in multiuser unix systems.
+--
-- You have a shared directory for a set of users and you want
-- to ensure all users have read and write permissions on all
--- files in there. Unfortunally sometimes users mess with their
+-- files in there. Unfortunally sometimes users mess with their
-- umask, and create files in there that are not read/write/deleteable
-- by others. Usually this involves frequent handfixes by a sysadmin,
-- or a cron job that recursively chmods/chowns the whole directory.
--
-- This is another approach to use lsyncd to continously fix permissions.
---
--- One second after a file is created/modified it checks for its permissions
+--
+-- One second after a file is created/modified it checks for its permissions
-- and forces group permissions on it.
--
-- This example regards more the handcraft of bash scripting than lsyncd.
--- An alternative to this would be to load a Lua-Posix library and do the
+-- An alternative to this would be to load a Lua-Posix library and do the
-- permission changes right within the onAction handlers.
----
@@ -27,29 +27,29 @@
-----
-- script for all changes.
--
-command =
--- checks if the group is the one enforced and sets them if not
+command =
+-- checks if the group is the one enforced and sets them if not
[[
perm=`stat -c %A ^sourcePathname`
if [ `stat -c %G ^sourcePathname` != ]]..fgroup..[[ ]; then
- /bin/chgrp ]]..fgroup..[[ ^sourcePathname || /bin/true;
-fi
+ /bin/chgrp ]]..fgroup..[[ ^sourcePathname || /bin/true;
+fi
]] ..
--- checks if the group permissions are rw and sets them
+-- checks if the group permissions are rw and sets them
[[
-if [ `expr match $perm "....rw"` == 0 ]; then
- /bin/chmod g+rw ^sourcePathname || /bin/true;
-fi
+if [ `expr match $perm "....rw"` == 0 ]; then
+ /bin/chmod g+rw ^sourcePathname || /bin/true;
+fi
]] ..
-- and forces the executable bit for directories.
[[
if [ -d ^sourcePathname ]; then
- if [ `expr match $perm "......x"` == 0 ]; then
+ if [ `expr match $perm "......x"` == 0 ]; then
/bin/chmod g+x ^^sourcePathname || /bin/true;
- fi
-fi
+ fi
+fi
]]
-- on startup recursevily sets all group ownerships
@@ -58,11 +58,11 @@
--
-- the carret as first char tells Lsycnd to call a shell altough it
-- starts with a slash otherwisw
---
-startup =
+--
+startup =
[[^/bin/chgrp -R ]]..fgroup..[[ ^source || /bin/true &&
/bin/chmod -R g+rw ^source || /bin/true &&
-/usr/bin/find ^source -type d | xargs chmod g+x
+/usr/bin/find ^source -type d | xargs chmod g+x
]]
gforce = {
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/examples/limagemagic.lua
^
|
@@ -1,6 +1,6 @@
----
-- Lsyncd user-script that creates a "magic" image converter directory.
---
+--
-- This configuration will automatically convert all images that are placed
-- in the directory 'magicdir' all resulting images are placed in the same
-- directory!
@@ -50,7 +50,7 @@
if cmd ~= "" then
cmd = cmd .. " && "
end
- cmd = cmd..
+ cmd = cmd..
'/usr/bin/convert "'..
event.source..p..'" "'..
event.source..base..'.'..k..
@@ -61,7 +61,7 @@
spawnShell(event, cmd)
return
end
-
+
-- deletes all formats if you delete one
if event.etype == "Delete" then
-- builds one bash command
@@ -99,8 +99,8 @@
local inlet = event.inlet
if event.etype == "Create" or
- event.etype == "Modify" or
- event.etype == "Delete"
+ event.etype == "Modify" or
+ event.etype == "Delete"
then
for k, _ in pairs(formats) do
inlet.rmExclude(base..'.'..k)
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/examples/lpostcmd.lua
^
|
@@ -26,12 +26,12 @@
-- triggering an error if not.
local isPostcmd = rawget(event, "isPostcmd")
if event.isPostcmd then
- spawn(event, "/usr/bin/ssh",
+ spawn(event, "/usr/bin/ssh",
config.host, config.postcmd)
return
else
-- this is the startup, forwards it to default routine.
- return default.rsync.action(inlet)
+ return default.rsync.action(inlet)
end
error("this should never be reached")
end
@@ -78,7 +78,7 @@
sync {
- rsyncpostcmd,
+ rsyncpostcmd,
source = "src",
host = "beetle",
targetdir = "/path/to/trg",
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/examples/lrsync.lua
^
|
@@ -9,8 +9,8 @@
}
sync{
- default.rsync,
- source="src",
- target="trg",
+ default.rsync,
+ source="src",
+ target="trg",
}
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/inotify.c
^
|
@@ -1,14 +1,14 @@
-/**
- * inotify.c from Lsyncd - Live (Mirror) Syncing Demon
- *
- * License: GPLv2 (see COPYING) or any later version
- *
- * Authors: Axel Kittenberger <axkibe@gmail.com>
- *
- * -----------------------------------------------------------------------
- *
- * Event interface for Lsyncd to Linux´ inotify.
- */
+/*
+| inotify.c from Lsyncd - Live (Mirror) Syncing Demon
+|
+| License: GPLv2 (see COPYING) or any later version
+|
+| Authors: Axel Kittenberger <axkibe@gmail.com>
+|
+| -----------------------------------------------------------------------
+|
+| Event interface for Lsyncd to Linux´ inotify.
+*/
#include "lsyncd.h"
@@ -39,83 +39,130 @@
#include <lualib.h>
#include <lauxlib.h>
-/*-----------------------------------------------------------------------------
- * Event types.
- */
+
+/*
+| Event types.
+*/
static const char * ATTRIB = "Attrib";
static const char * MODIFY = "Modify";
static const char * CREATE = "Create";
static const char * DELETE = "Delete";
static const char * MOVE = "Move";
-/**
+
+/*
* The inotify file descriptor.
*/
static int inotify_fd = -1;
-/**
- * Standard inotify events to listen to.
- */
-static const uint32_t standard_event_mask =
- IN_ATTRIB | IN_CLOSE_WRITE | IN_CREATE |
- IN_DELETE | IN_DELETE_SELF | IN_MOVED_FROM |
- IN_MOVED_TO | IN_DONT_FOLLOW | IN_ONLYDIR;
-
-/**
- * Adds an inotify watch
- *
- * @param dir (Lua stack) path to directory
- * @param inotifyMode (Lua stack) path to directory
- * @return (Lua stack) numeric watch descriptor
- */
+/*
+| Standard inotify events to listen to.
+*/
+static const uint32_t standard_event_mask =
+ IN_ATTRIB |
+ IN_CLOSE_WRITE |
+ IN_CREATE |
+ IN_DELETE |
+ IN_DELETE_SELF |
+ IN_MOVED_FROM |
+ IN_MOVED_TO |
+ IN_DONT_FOLLOW |
+ IN_ONLYDIR;
+
+
+/*
+| Adds an inotify watch
+|
+| param dir (Lua stack) path to directory
+| param inotifyMode (Lua stack) which inotify event to react upon
+| "CloseWrite", "CloseWrite or Modify"
+|
+| returns (Lua stack) numeric watch descriptor
+*/
static int
-l_addwatch(lua_State *L)
+l_addwatch( lua_State *L )
{
- const char *path = luaL_checkstring(L, 1);
- const char *imode = luaL_checkstring(L, 2);
+ const char *path = luaL_checkstring( L, 1 );
+ const char *imode = luaL_checkstring( L, 2 );
uint32_t mask = standard_event_mask;
- if (*imode) {
- if (!strcmp(imode, "Modify")) {
- // act on modify instead of closeWrite
- mask |= IN_MODIFY;
+
+ // checks the desired inotify reaction mode
+ if (*imode)
+ {
+ if ( !strcmp( imode, "Modify" ) )
+ {
+ // acts on modify instead of closeWrite
+ mask |= IN_MODIFY;
mask &= ~IN_CLOSE_WRITE;
- } else if (!strcmp(imode, "CloseWrite")) {
- // default
- } else if (!strcmp(imode, "CloseWrite or Modify")) {
+ }
+ else if ( !strcmp( imode, "CloseWrite" ) )
+ {
+ // thats default
+ }
+ else if ( !strcmp( imode, "CloseWrite or Modify" ) )
+ {
// acts on modify and closeWrite
mask |= IN_MODIFY;
- } else if (!strcmp(imode, "CloseWrite after Modify")) {
+ }
+ else if ( ! strcmp( imode, "CloseWrite after Modify") )
+ {
// might be done in future
- printlogf(L, "Error", "'CloseWrite after Modify' not implemented.");
- exit(-1); // ERRNO
- } else {
- printlogf(L, "Error", "'%s' not a valid inotfiyMode.", imode);
- exit(-1); // ERRNO
+ printlogf(
+ L, "Error",
+ "'CloseWrite after Modify' not implemented."
+ );
+ exit(-1);
+ }
+ else
+ {
+ printlogf(
+ L, "Error",
+ "'%s' not a valid inotfiyMode.",
+ imode
+ );
+ exit(-1);
}
}
+ // kernel call to create the inotify watch
+ int wd = inotify_add_watch( inotify_fd, path, mask );
- int wd = inotify_add_watch(inotify_fd, path, mask);
- if (wd < 0) {
- if (errno == ENOSPC) {
- printlogf(L, "Error", "Terminating since out of inotify watches.");
- printlogf(L, "Error", "Consider increasing /proc/sys/fs/inotify/max_user_watches");
+ if (wd < 0)
+ {
+ if (errno == ENOSPC)
+ {
+ printlogf(
+ L, "Error",
+ "%s\n%s",
+ "Terminating since out of inotify watches.",
+ "Consider increasing /proc/sys/fs/inotify/max_user_watches"
+ );
exit(-1); // ERRNO.
}
- printlogf(L, "Inotify", "addwatch(%s)->%d; err=%d:%s", path, wd, errno, strerror(errno));
- } else {
- printlogf(L, "Inotify", "addwatch(%s)->%d", path, wd);
+
+ printlogf(
+ L, "Inotify",
+ "addwatch( %s )-> % d; err= %d : %s",
+ path, wd, errno, strerror( errno )
+ );
+ }
+ else
+ {
+ printlogf(L, "Inotify", "addwatch( %s )-> %d ", path, wd );
}
- lua_pushinteger(L, wd);
+ lua_pushinteger( L, wd );
+
return 1;
}
-/**
- * Removes an inotify watch
+
+/*
+ * Removes an inotify watch.
+ *
+ * param dir (Lua stack) numeric watch descriptor
*
- * @param dir (Lua stack) numeric watch descriptor
- * @return nil
+ * return nil
*/
static int
l_rmwatch(lua_State *L)
@@ -126,147 +173,214 @@
return 0;
}
-/**
- * Cores inotify functions.
- */
-static const luaL_reg linotfylib[] = {
- {"addwatch", l_addwatch },
- {"rmwatch", l_rmwatch },
- {NULL, NULL}
+
+/*
+| Lsyncd's core's inotify functions.
+*/
+static const luaL_Reg linotfylib[] = {
+ { "addwatch", l_addwatch },
+ { "rmwatch", l_rmwatch },
+ { NULL, NULL}
};
-/**
- * Buffer for MOVE_FROM events.
- * Lsyncd buffers MOVE_FROM events to check if
- * they are followed by MOVE_TO events with identical cookie
- * then they are condensed into one move event to be sent to the
- * runner
- */
+
+/*
+| Buffer for MOVE_FROM events.
+| Lsyncd buffers MOVE_FROM events to check if
+| they are followed by MOVE_TO events with identical cookie
+| then they are condensed into one move event to be sent to the
+| runner
+*/
static struct inotify_event * move_event_buf = NULL;
-/**
- * Memory allocated for move_event_buf
- */
+
+/*
+| Memory allocated for move_event_buf
+*/
static size_t move_event_buf_size = 0;
-/**
- * true if the buffer is used.
- */
+
+/*
+| True if the buffer is used.
+*/
static bool move_event = false;
-/**
- * Handles an inotify event.
- */
+
+/*
+| Handles an inotify event.
+*/
static void
-handle_event(lua_State *L,
- struct inotify_event *event)
+handle_event(
+ lua_State *L,
+ struct inotify_event *event
+)
{
const char *event_type = NULL;
// used to execute two events in case of unmatched MOVE_FROM buffer
struct inotify_event *after_buf = NULL;
- if (event && (IN_Q_OVERFLOW & event->mask)) {
- /* and overflow happened, tells the runner */
- load_runner_func(L, "overflow");
- if (lua_pcall(L, 0, 0, -2)) {
- exit(-1); // ERRNO
+ if( event && ( IN_Q_OVERFLOW & event->mask ) )
+ {
+ // and overflow happened, tells the runner
+ load_runner_func( L, "overflow" );
+
+ if( lua_pcall( L, 0, 0, -2 ) )
+ {
+ exit( -1 );
}
- lua_pop(L, 1);
+ lua_pop( L, 1 );
hup = 1;
return;
}
+
// cancel on ignored or resetting
- if (event && (IN_IGNORED & event->mask)) {
+ if( event && ( IN_IGNORED & event->mask ) )
+ {
return;
}
- if (event && event->len == 0) {
+
+ if( event && event->len == 0 )
+ {
// sometimes inotify sends such strange events,
// (e.g. when touching a dir
return;
}
- if (event == NULL) {
+ if( event == NULL )
+ {
// a buffered MOVE_FROM is not followed by anything,
// thus it is unary
event = move_event_buf;
event_type = "Delete";
move_event = false;
- } else if (move_event &&
- ( !(IN_MOVED_TO & event->mask) ||
- event->cookie != move_event_buf->cookie) ) {
+ }
+ else if(
+ move_event &&
+ (
+ !( IN_MOVED_TO & event->mask ) ||
+ event->cookie != move_event_buf->cookie
+ )
+ )
+ {
// there is a MOVE_FROM event in the buffer and this is not the match
// continue in this function iteration to handle the buffer instead */
- logstring("Inotify", "icore, changing unary MOVE_FROM into DELETE")
+ logstring(
+ "Inotify",
+ "icore, changing unary MOVE_FROM into DELETE"
+ )
after_buf = event;
event = move_event_buf;
event_type = "Delete";
move_event = false;
- } else if ( move_event &&
- (IN_MOVED_TO & event->mask) &&
- event->cookie == move_event_buf->cookie ) {
+ }
+ else if(
+ move_event &&
+ (
+ IN_MOVED_TO & event->mask ) &&
+ event->cookie == move_event_buf->cookie
+ )
+ {
// this is indeed a matched move */
event_type = "Move";
move_event = false;
- } else if (IN_MOVED_FROM & event->mask) {
+ }
+ else if( IN_MOVED_FROM & event->mask )
+ {
// just the MOVE_FROM, buffers this event, and wait if next event is
// a matching MOVED_TO of this was an unary move out of the watched
// tree.
- size_t el = sizeof(struct inotify_event) + event->len;
- if (move_event_buf_size < el) {
+ size_t el = sizeof( struct inotify_event ) + event->len;
+
+ if( move_event_buf_size < el )
+ {
move_event_buf_size = el;
- move_event_buf = s_realloc(move_event_buf, el);
+ move_event_buf = s_realloc( move_event_buf, el );
}
- memcpy(move_event_buf, event, el);
+ memcpy( move_event_buf, event, el );
move_event = true;
return;
- } else if (IN_MOVED_TO & event->mask) {
+
+ }
+ else if( IN_MOVED_TO & event->mask )
+ {
// must be an unary move-to
event_type = CREATE;
- } else if (IN_ATTRIB & event->mask) {
+ }
+ else if( IN_ATTRIB & event->mask )
+ {
// just attrib change
event_type = ATTRIB;
- } else if ((IN_CLOSE_WRITE | IN_MODIFY) & event->mask) {
+ }
+ else if( ( IN_CLOSE_WRITE | IN_MODIFY) & event->mask )
+ {
// modify, or closed after written something
// the event type received depends settings.inotifyMode
event_type = MODIFY;
- } else if (IN_CREATE & event->mask) {
+ }
+ else if( IN_CREATE & event->mask )
+ {
// a new file
event_type = CREATE;
- } else if (IN_DELETE & event->mask) {
+ }
+ else if( IN_DELETE & event->mask )
+ {
// rm'ed
event_type = DELETE;
- } else {
- logstring("Inotify", "icore, skipped some inotify event.");
+ }
+ else
+ {
+ logstring(
+ "Inotify",
+ "skipped some inotify event."
+ );
return;
}
- // and hands over to runner
- load_runner_func(L, "inotifyEvent");
- if (!event_type) {
- logstring("Error", "Internal: unknown event in handle_event()");
- exit(-1); // ERRNO
- }
- lua_pushstring(L, event_type);
- if (event_type != MOVE) {
- lua_pushnumber(L, event->wd);
- } else {
- lua_pushnumber(L, move_event_buf->wd);
- }
- lua_pushboolean(L, (event->mask & IN_ISDIR) != 0);
- l_now(L);
- if (event_type == MOVE) {
- lua_pushstring(L, move_event_buf->name);
- lua_pushnumber(L, event->wd);
- lua_pushstring(L, event->name);
- } else {
- lua_pushstring(L, event->name);
- lua_pushnil(L);
- lua_pushnil(L);
+ // hands the event over to the runner
+ load_runner_func( L, "inotifyEvent" );
+
+ if( !event_type )
+ {
+ logstring(
+ "Error",
+ "internal failure: unknown event in handle_event()"
+ );
+
+ exit( -1 );
+ }
+
+ lua_pushstring( L, event_type );
+ if( event_type != MOVE )
+ {
+ lua_pushnumber( L, event->wd );
+ }
+ else
+ {
+ lua_pushnumber( L, move_event_buf->wd );
}
- if (lua_pcall(L, 7, 0, -9)) {
- exit(-1); // ERRNO
+ lua_pushboolean( L, ( event->mask & IN_ISDIR ) != 0 );
+
+ l_now( L );
+
+ if( event_type == MOVE )
+ {
+ lua_pushstring( L, move_event_buf->name );
+ lua_pushnumber( L, event->wd );
+ lua_pushstring( L, event->name );
+ }
+ else
+ {
+ lua_pushstring( L, event->name );
+ lua_pushnil( L );
+ lua_pushnil( L );
+ }
+
+ if( lua_pcall( L, 7, 0, -9 ) )
+ {
+ exit( -1 );
}
- lua_pop(L, 1);
+
+ lua_pop( L, 1 );
// if there is a buffered event, executes it
if (after_buf) {
@@ -275,31 +389,44 @@
}
}
-/**
- * buffer to read inotify events into
- */
+
+/*
+| buffer to read inotify events into
+*/
static size_t readbuf_size = 2048;
static char * readbuf = NULL;
-/**
- * Called by function pointer from when the inotify file descriptor
- * became ready. Reads it contents and forward all received events
- * to the runner.
- */
+
+/*
+| Called when the inotify file descriptor became ready.
+| Reads it contents and forwards all received events
+| to the runner.
+*/
static void
-inotify_ready(lua_State *L, struct observance *obs)
+inotify_ready(
+ lua_State *L,
+ struct observance *obs
+)
{
- if (obs->fd != inotify_fd) {
- logstring("Error", "Internal, inotify_fd != ob->fd");
- exit(-1); // ERRNO
+ // sanity check
+ if( obs->fd != inotify_fd )
+ {
+ logstring(
+ "Error",
+ "internal failure, inotify_fd != ob->fd"
+ );
+ exit( -1 );
}
- while(true) {
+
+ while( true )
+ {
ptrdiff_t len;
int err;
do {
- len = read (inotify_fd, readbuf, readbuf_size);
+ len = read( inotify_fd, readbuf, readbuf_size );
err = errno;
- if (len < 0 && err == EINVAL) {
+ if( len < 0 && err == EINVAL )
+ {
// kernel > 2.6.21 indicates that way that way that
// the buffer was too small to fit a filename.
// double its size and try again. When using a lower
@@ -309,91 +436,138 @@
readbuf_size *= 2;
readbuf = s_realloc(readbuf, readbuf_size);
}
- } while(len < 0 && err == EINVAL);
- if (len == 0) {
- // nothing more inotify
+ } while( len < 0 && err == EINVAL );
+
+ if( len == 0 )
+ {
+ // no more inotify events
break;
}
- if (len < 0) {
+
+ if (len < 0)
+ {
if (err == EAGAIN) {
// nothing more inotify
break;
- } else {
- printlogf(L, "Error", "Read fail on inotify");
- exit(-1); // ERRNO
+ }
+ else
+ {
+ printlogf(
+ L, "Error",
+ "Read fail on inotify"
+ );
+ exit( -1 );
}
}
+
{
int i = 0;
- while (i < len && !hup && !term) {
+ while( i < len && !hup && !term )
+ {
struct inotify_event *event =
- (struct inotify_event *) &readbuf[i];
- handle_event(L, event);
- i += sizeof(struct inotify_event) + event->len;
+ ( struct inotify_event * )
+ (readbuf + i);
+
+ handle_event( L, event );
+
+ i += sizeof( struct inotify_event ) + event->len;
}
}
- if (!move_event) {
+
+ if( !move_event )
+ {
// give it a pause if not endangering splitting a move
break;
}
}
// checks if there is an unary MOVE_FROM left in the buffer
- if (move_event) {
- logstring("Inotify", "icore, handling unary move from.");
- handle_event(L, NULL);
+ if( move_event )
+ {
+ logstring(
+ "Inotify",
+ "handling unary move from."
+ );
+ handle_event( L, NULL );
}
}
-/**
- * registers inotify functions.
- */
+
+/*
+| Registers the inotify functions.
+*/
extern void
-register_inotify(lua_State *L)
+register_inotify( lua_State *L )
{
- lua_pushstring(L, "inotify");
- luaL_register(L, "inotify", linotfylib);
+ luaL_register( L, LSYNCD_INOTIFYLIBNAME, linotfylib );
}
-/**
- * closes inotify
- */
+
+/*
+| Cleans up the inotify handling.
+*/
static void
-inotify_tidy(struct observance *obs)
+inotify_tidy( struct observance *obs )
{
- if (obs->fd != inotify_fd) {
- logstring("Error", "Internal, inotify_fd != ob->fd");
- exit(-1); // ERRNO
+ if( obs->fd != inotify_fd )
+ {
+ logstring(
+ "Error",
+ "internal failure: inotify_fd != ob->fd"
+ );
+ exit( -1 );
}
- close(inotify_fd);
- free(readbuf);
+
+ close( inotify_fd );
+ free( readbuf );
readbuf = NULL;
}
-/**
- * opens and initalizes inotify.
- */
+/*
+| Initalizes inotify handling
+*/
extern void
-open_inotify(lua_State *L)
+open_inotify( lua_State *L )
{
- if (readbuf) {
- logstring("Error",
- "internal fail, inotify readbuf!=NULL in open_inotify()")
- exit(-1); // ERRNO
- }
- readbuf = s_malloc(readbuf_size);
-
- inotify_fd = inotify_init();
- if (inotify_fd < 0) {
- printlogf(L, "Error",
- "Cannot access inotify monitor! (%d:%s)",
- errno, strerror(errno));
- exit(-1); // ERRNO
- }
- printlogf(L, "Inotify", "inotify fd = %d", inotify_fd);
-
- close_exec_fd(inotify_fd);
- non_block_fd(inotify_fd);
- observe_fd(inotify_fd, inotify_ready, NULL, inotify_tidy, NULL);
+ if( readbuf )
+ {
+ logstring(
+ "Error",
+ "internal failure, inotify readbuf != NULL in open_inotify()"
+ )
+ exit(-1);
+ }
+
+ readbuf = s_malloc( readbuf_size );
+
+ inotify_fd = inotify_init( );
+
+ if( inotify_fd < 0 )
+ {
+ printlogf(
+ L,
+ "Error",
+ "Cannot access inotify monitor! ( %d : %s )",
+ errno, strerror(errno)
+ );
+ exit( -1 );
+ }
+
+ printlogf(
+ L, "Inotify",
+ "inotify fd = %d",
+ inotify_fd
+ );
+
+ close_exec_fd( inotify_fd );
+ non_block_fd( inotify_fd );
+
+ observe_fd(
+ inotify_fd,
+ inotify_ready,
+ NULL,
+ inotify_tidy,
+ NULL
+ );
}
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/lsyncd.c
^
|
@@ -1,17 +1,19 @@
-/**
- * lsyncd.c Live (Mirror) Syncing Demon
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- *
- * This is the core. It contains as minimal as possible glues
- * to the operating system needed for lsyncd operation. All high-level
- * logic is coded (when feasable) into lsyncd.lua
- *
- * This code assumes you have a 100 character wide display to view it (when tabstop is 4)
- *
- * License: GPLv2 (see COPYING) or any later version
- * Authors: Axel Kittenberger <axkibe@gmail.com>
- *
- **/
+/*
+| lsyncd.c Live (Mirror) Syncing Demon
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+|
+| This is Lsyncd's core.
+|
+| It contains as minimal as possible glues to the operating system needed
+| for Lsyncd's operation. All high-level logic is coded (when feasable)
+| into lsyncd.lua
+|
+| This code assumes you have a 100 character wide display to view it (when tabstop is 4)
+|
+| License: GPLv2 (see COPYING) or any later version
+| Authors: Axel Kittenberger <axkibe@gmail.com>
+|
+*/
#include "lsyncd.h"
@@ -44,18 +46,18 @@
#include <lualib.h>
#include <lauxlib.h>
-/**
- * The Lua part of lsyncd if compiled into the binary.
- */
+/*
+| The Lua part of Lsyncd
+*/
extern const char runner_out[];
extern size_t runner_size;
extern const char defaults_out[];
extern size_t defaults_size;
-/**
- * Makes sure there is one monitor.
- */
+/*
+| Makes sure there is one file system monitor.
+*/
#ifndef LSYNCD_WITH_INOTIFY
#ifndef LSYNCD_WITH_FANOTIFY
#ifndef LSYNCD_WITH_FSEVENTS
@@ -64,9 +66,9 @@
#endif
#endif
-/**
- * All monitors supported by this Lsyncd.
- */
+/*
+| All monitors supported by this Lsyncd.
+*/
static char *monitors[] = {
#ifdef LSYNCD_WITH_INOTIFY
@@ -85,48 +87,49 @@
};
/**
- * configuration parameters
- */
+| Configuration parameters that matter to the core
+*/
struct settings settings = {
- .log_file = NULL,
- .log_syslog = false,
- .log_ident = NULL,
+ .log_file = NULL,
+ .log_syslog = false,
+ .log_ident = NULL,
.log_facility = LOG_USER,
- .log_level = LOG_NOTICE,
- .nodaemon = false,
+ .log_level = LOG_NOTICE,
+ .nodaemon = false,
};
-/**
- * True when lsyncd daemonized itself.
- */
+/*
+| True when Lsyncd daemonized itself.
+*/
static bool is_daemon = false;
-/**
- * The config file loaded by Lsyncd.
- * Global so it is retained during HUPs
- */
+/*
+| The config file loaded by Lsyncd.
+*/
char * lsyncd_config_file = NULL;
-/**
- * False after first time Lsyncd started up.
- *
- * Thus configuration error messages are written to stdout/stderr only on
- * first start.
- *
- * All other resets (HUP or inotify OVERFLOW) run with implictly --insist
- * turned on and thus Lsyncd not failing on a not responding target.
- */
+/*
+| False after first time Lsyncd started up.
+|
+| Configuration error messages are thus written to
+| stdout/stderr only on first start.
+|
+| All other resets (HUP or monitor OVERFLOW) run with 'insist'
+| implictly turned on and thus Lsyncd does not failing on a non
+| responding target.
+*/
static bool first_time = true;
-/**
- * Set to TERM or HUP in signal handler, when lsyncd should end or reset ASAP.
- */
+/*
+| Set by TERM or HUP signal handler
+| telling Lsyncd should end or reset ASAP.
+*/
volatile sig_atomic_t hup = 0;
volatile sig_atomic_t term = 0;
-/**
- * The kernels clock ticks per second.
- */
+/*
+| The kernel's clock ticks per second.
+*/
static long clocks_per_sec;
/**
@@ -149,188 +152,254 @@
}
}
-/**
- * Non glibc builds need a real tms structure for times() call
- */
+/*
+| Non glibc builds need a real tms structure for the times( ) call
+*/
#ifdef __GLIBC__
- static struct tms *dummy_tms = NULL;
+ static struct tms * dummy_tms = NULL;
#else
- static struct tms _dummy_tms;
- static struct tms *dummy_tms = &_dummy_tms;
+ static struct tms _dummy_tms;
+ static struct tms * dummy_tms = &_dummy_tms;
#endif
-/**
-| Returns the absolute path of path.
+/*
+| Returns the absolute path of a path.
+|
| This is a wrapper to various C-Library differences.
*/
char *
-get_realpath(const char * rpath) {
+get_realpath( const char * rpath )
+{
// uses c-library to get the absolute path
#ifdef __GLIBC__
// in case of GLIBC the task is easy.
- return realpath(rpath, NULL);
+ return realpath( rpath, NULL );
#else
# warning having to use old style realpath()
- // otherwise less so and requires PATH_MAX limit.
- char buf[PATH_MAX];
- char *asw = realpath(rpath, buf);
- if (!asw) return NULL;
- return s_strdup(asw);
+ // otherwise less so and requires PATH_MAX limit
+ char buf[ PATH_MAX] ;
+ char *asw = realpath( rpath, buf );
+ if( !asw )
+ { return NULL; }
+
+ return s_strdup( asw );
#endif
}
-/*****************************************************************************
- * Logging
- ****************************************************************************/
-/**
- * A logging category
- */
-struct logcat {
+
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+( Logging )
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+/*
+| A logging category
+*/
+struct logcat
+{
char *name;
int priority;
};
-/**
- * A table of all enabled logging categories.
- * Sorted by first letter to have to do less comparisons;
- */
-static struct logcat *logcats[26] = {0,};
-/**
- * Returns the positive priority if category is configured to be logged or -1.
- */
+/*
+| A table of all enabled logging categories.
+| Sorted by first letter for faster access.
+*/
+static struct logcat *
+logcats[ 26 ] = { 0, };
+
+
+/*
+| Returns a positive priority if category is configured to be logged or -1.
+*/
extern int
-check_logcat(const char *name)
+check_logcat( const char *name )
{
struct logcat *lc;
- if (name[0] < 'A' || name[0] > 'Z') {
- return 99;
- }
- lc = logcats[name[0]-'A'];
- if (!lc) return 99;
+ if( name[ 0 ] < 'A' || name[ 0 ] > 'Z')
+ { return 99; }
+
+ lc = logcats[ name[ 0 ] - 'A' ];
+
+ if( !lc )
+ { return 99; }
+
+ while( lc->name )
+ {
+ if( !strcmp( lc->name, name ) )
+ { return lc->priority; }
- while (lc->name) {
- if (!strcmp(lc->name, name)) {
- return lc->priority;
- }
lc++;
}
return 99;
}
-/**
- * Adds a logging category
- * @return true if OK.
- */
+
+/*
+| Adds a logging category
+|
+| Returns true if OK.
+*/
static bool
-add_logcat(const char *name, int priority)
+add_logcat( const char *name, int priority )
{
struct logcat *lc;
- if (!strcmp("all", name)) {
+
+ if( !strcmp( "all", name ) )
+ {
settings.log_level = 99;
return true;
}
- if (!strcmp("scarce", name)) {
+
+ if( !strcmp( "scarce", name ) )
+ {
settings.log_level = LOG_WARNING;
return true;
}
// categories must start with a capital letter.
- if (name[0] < 'A' || name[0] > 'Z') return false;
+ if( name[ 0 ] < 'A' || name[ 0 ] > 'Z' )
+ { return false; }
- if (!logcats[name[0]-'A']) {
+ if( !logcats[ name[ 0 ]- 'A' ] )
+ {
// an empty capital letter
lc = logcats[name[0]-'A'] = s_calloc(2, sizeof(struct logcat));
- } else {
- int ll = 0; // length of letter list
+ }
+ else
+ {
+ // length of letter list
+ int ll = 0;
+
// counts list length
- for(lc = logcats[name[0]-'A']; lc->name; lc++) {
- ll++;
- }
+ for( lc = logcats[name[0]-'A']; lc->name; lc++ )
+ { ll++; }
+
// enlarges list
- logcats[name[0]-'A'] =
- s_realloc(logcats[name[0]-'A'], (ll + 2) * sizeof(struct logcat));
- // go to list end
- for(lc = logcats[name[0]-'A']; lc->name; lc++) {
- if (!strcmp(name, lc->name)) {
+ logcats[ name[ 0 ] - 'A'] =
+ s_realloc(
+ logcats[ name[ 0 ]-'A' ],
+ ( ll + 2 ) * sizeof( struct logcat )
+ );
+
+ // goes to the list end
+ for( lc = logcats[ name[ 0 ] - 'A']; lc->name; lc++ )
+ {
+ if( !strcmp( name, lc->name ) )
+ {
// already there
return true;
}
}
}
- lc->name = s_strdup(name);
+
+ lc->name = s_strdup( name );
lc->priority = priority;
+
// terminates the list
- lc[1].name = NULL;
+ lc[ 1 ].name = NULL;
return true;
}
-/**
- * Logs a string.
- *
- * Do not call directly, but the macro logstring() in lsyncd.h
- *
- * @param priorty the priority of the log message
- * @param cat the category
- * @param message the log message
- */
+
+/*
+| Logs a string.
+|
+| Do not call this directly, but the macro logstring( )
+| defined in lsyncd.h
+*/
extern void
-logstring0(int priority, const char *cat, const char *message)
+logstring0(
+ int priority, // the priority of the log message
+ const char * cat, // the category
+ const char * message // the log message
+)
{
- if (first_time) {
- // lsyncd is in intial configuration phase.
+ if( first_time )
+ {
+ // lsyncd is in it's intial configuration phase.
// thus just print to normal stdout/stderr.
- if (priority >= LOG_ERR) {
- fprintf(stderr, "%s: %s\n", cat, message);
- } else {
- printf("%s: %s\n", cat, message);
+ if( priority >= LOG_ERR )
+ {
+ fprintf( stderr, "%s: %s\n", cat, message);
+ }
+ else
+ {
+ printf( "%s: %s\n", cat, message );
}
return;
}
// writes on console if not daemonized
- if (!is_daemon) {
- char ct[255];
+ if( !is_daemon )
+ {
+ char ct[ 255 ];
// gets current timestamp hour:minute:second
time_t mtime;
- time(&mtime);
- strftime(ct, sizeof(ct), "%T", localtime(&mtime));
+ time( &mtime );
+
+ strftime( ct, sizeof( ct ), "%T", localtime( &mtime ) );
+
FILE * flog = priority <= LOG_ERR ? stderr : stdout;
- fprintf(flog, "%s %s: %s\n", ct, cat, message);
+
+ fprintf(
+ flog,
+ "%s %s: %s\n",
+ ct, cat, message
+ );
}
// writes to file if configured so
- if (settings.log_file) {
- FILE * flog = fopen(settings.log_file, "a");
- // gets current timestamp day-time-year
+ if (settings.log_file)
+ {
+ FILE * flog = fopen( settings.log_file, "a" );
char * ct;
time_t mtime;
- time(&mtime);
- ct = ctime(&mtime);
+
+ // gets current timestamp day-time-year
+ time( &mtime );
+ ct = ctime( &mtime );
+
// cuts trailing linefeed
- ct[strlen(ct) - 1] = 0;
+ ct[ strlen( ct ) - 1] = 0;
- if (flog == NULL) {
- fprintf(stderr, "Cannot open logfile [%s]!\n",
- settings.log_file);
- exit(-1); // ERRNO
- }
- fprintf(flog, "%s %s: %s\n", ct, cat, message);
- fclose(flog);
+ if( flog == NULL )
+ {
+ fprintf(
+ stderr,
+ "Cannot open logfile [%s]!\n",
+ settings.log_file
+ );
+ exit( -1 );
+ }
+
+ fprintf(
+ flog,
+ "%s %s: %s\n",
+ ct, cat, message
+ );
+
+ fclose( flog );
}
// sends to syslog if configured so
- if (settings.log_syslog) syslog(priority, "%s, %s", cat, message);
+ if( settings.log_syslog )
+ {
+ syslog( priority, "%s, %s", cat, message );
+ }
+
return;
}
-/**
- * Lets the core print logmessages comfortably as formated string.
- * This uses the lua_State for it easy string buffers only.
- */
+
+/*
+| Lets the core print logmessages comfortably as formated string.
+| This uses the lua_State for it easy string buffers only.
+*/
extern void
printlogf0(lua_State *L,
int priority,
@@ -346,551 +415,754 @@
return;
}
-/*****************************************************************************
- * Simple memory management
- * TODO: call the garbace collector in case of out of memory.
- ****************************************************************************/
-/**
- * "secured" calloc.
- */
+
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+( Simple memory management )
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+// FIXME call the Lua garbace collector in case of out of memory
+
+/*
+| "Secured" calloc
+*/
extern void *
-s_calloc(size_t nmemb, size_t size)
+s_calloc( size_t nmemb, size_t size )
{
- void *r = calloc(nmemb, size);
- if (r == NULL) {
- logstring0(LOG_ERR, "Error", "Out of memory!");
- exit(-1); // ERRNO
+ void * r = calloc( nmemb, size );
+
+ if( r == NULL )
+ {
+ logstring0(
+ LOG_ERR,
+ "Error",
+ "Out of memory!"
+ );
+
+ exit( -1 );
}
+
return r;
}
-/**
- * "secured" malloc. the deamon shall kill itself
- * in case of out of memory.
- */
+
+/*
+| "Secured" malloc
+*/
extern void *
-s_malloc(size_t size)
+s_malloc( size_t size )
{
- void *r = malloc(size);
- if (r == NULL) {
- logstring0(LOG_ERR, "Error", "Out of memory!");
- exit(-1); // ERRNO
+ void * r = malloc( size );
+
+ if( r == NULL )
+ {
+ logstring0(
+ LOG_ERR,
+ "Error",
+ "Out of memory!"
+ );
+
+ exit( -1 );
}
+
return r;
}
-/**
- * "secured" realloc.
- */
+
+/*
+| "Secured" realloc
+*/
extern void *
-s_realloc(void *ptr, size_t size)
+s_realloc( void * ptr, size_t size )
{
- void *r = realloc(ptr, size);
- if (r == NULL) {
- logstring0(LOG_ERR, "Error", "Out of memory!");
- exit(-1);
+ void * r = realloc( ptr, size );
+
+ if( r == NULL )
+ {
+ logstring0(
+ LOG_ERR,
+ "Error",
+ "Out of memory!"
+ );
+
+ exit( -1 );
}
+
return r;
}
-/**
- * "secured" strdup.
- */
+
+/*
+| "Secured" strdup
+*/
extern char *
-s_strdup(const char *src)
+s_strdup( const char *src )
{
- char *s = strdup(src);
- if (s == NULL) {
- logstring0(LOG_ERR, "Error", "Out of memory!");
- exit(-1); // ERRNO
+ char *s = strdup( src );
+
+ if( s == NULL )
+ {
+ logstring0(
+ LOG_ERR,
+ "Error",
+ "Out of memory!"
+ );
+
+ exit( -1 );
}
+
return s;
}
-/*****************************************************************************
- * Pipes management
- ****************************************************************************/
-/**
- * A child process gets text piped longer than on
- * write() can manage.
- */
-struct pipemsg {
- char *text; // message to send
- int tlen; // length of text
- int pos; // position in message
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+( Pipes Management )
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+/*
+| A child process gets text piped through stdin
+*/
+struct pipemsg
+{
+ char * text; // message to send
+ int tlen; // length of text
+ int pos; // position in message
};
-/**
- * Called by the core whenever a pipe becomes
- * writeable again
- */
+/*
+| Called by the core whenever a pipe becomes
+| writeable again
+*/
static void
-pipe_writey(lua_State *L, struct observance *observance)
+pipe_writey(
+ lua_State * L,
+ struct observance * observance
+)
{
int fd = observance->fd;
- struct pipemsg *pm = (struct pipemsg *) observance->extra;
- int len = write(fd, pm->text + pm->pos, pm->tlen - pm->pos);
+
+ struct pipemsg *pm = (struct pipemsg * ) observance->extra;
+
+ int len = write(
+ fd,
+ pm->text + pm->pos,
+ pm->tlen - pm->pos
+ );
+
pm->pos += len;
- if (len < 0) {
- logstring("Normal", "broken pipe.");
- nonobserve_fd(fd);
- } else if (pm->pos >= pm->tlen) {
+
+ if( len < 0 )
+ {
+ logstring( "Normal", "broken pipe." );
+ nonobserve_fd( fd );
+ }
+ else if( pm->pos >= pm->tlen )
+ {
logstring("Exec", "finished pipe.");
nonobserve_fd(fd);
}
}
-/**
- * Called when cleaning up a pipe
- */
+
+/*
+| Called when cleaning up a pipe.
+*/
static void
-pipe_tidy(struct observance *observance)
+pipe_tidy( struct observance * observance )
{
- struct pipemsg *pm = (struct pipemsg *) observance->extra;
- close(observance->fd);
- free(pm->text);
- free(pm);
+ struct pipemsg *pm = ( struct pipemsg * ) observance->extra;
+
+ close( observance->fd );
+ free( pm->text );
+ free( pm );
}
-/*****************************************************************************
- * helper routines.
- ****************************************************************************/
-/**
- * Dummy variable whos address is used as the cores index in the lua registry
- * to the lua runners function table in the lua registry.
- */
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+( Helper Routines )
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+/*
+| Dummy variable of which it's address is used as
+| the cores index in the lua registry to
+| the lua runners function table in the lua registry.
+*/
static int runner;
-/**
- * Dummy variable whos address is used as the cores index n the lua registry
- * to the lua runners error handler.
- */
+/*
+| Dummy variable of which it's address is used as
+| the cores index n the lua registry to
+| the lua runners error handler.
+*/
static int callError;
-/**
- * Sets the close-on-exit flag for an fd
- */
+/*
+| Sets the close-on-exit flag of a file descriptor.
+*/
extern void
-close_exec_fd(int fd)
+close_exec_fd( int fd )
{
int flags;
- flags = fcntl(fd, F_GETFD);
- if (flags == -1) {
- logstring("Error", "cannot get descriptor flags!");
- exit(-1); // ERRNO
+
+ flags = fcntl( fd, F_GETFD );
+
+ if( flags == -1 )
+ {
+ logstring( "Error", "cannot get descriptor flags!" );
+ exit( -1 );
}
flags |= FD_CLOEXEC;
- if (fcntl(fd, F_SETFD, flags) == -1) {
- logstring("Error", "cannot set descripptor flags!");
- exit(-1); // ERRNO
+
+ if( fcntl( fd, F_SETFD, flags ) == -1 )
+ {
+ logstring( "Error", "cannot set descripptor flags!" );
+ exit( -1 );
}
}
-/**
- * Sets the non-blocking flag for an fd
- */
+
+/*
+| Sets the non-blocking flag of a file descriptor.
+*/
extern void
-non_block_fd(int fd)
+non_block_fd( int fd )
{
int flags;
- flags = fcntl(fd, F_GETFL);
- if (flags == -1) {
- logstring("Error", "cannot get status flags!");
- exit(-1); // ERRNO
+ flags = fcntl( fd, F_GETFL );
+
+ if( flags == -1 )
+ {
+ logstring( "Error", "cannot get status flags!" );
+ exit( -1 );
}
flags |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, flags) == -1) {
- logstring("Error", "cannot set status flags!");
- exit(-1); // ERRNO
+ if( fcntl( fd, F_SETFL, flags ) == -1 )
+ {
+ logstring( "Error", "cannot set status flags!" );
+ exit( -1 );
}
}
-/**
- * Writes a pid file.
- */
+/*
+| Writes a pid file.
+*/
static void
-write_pidfile(lua_State *L, const char *pidfile) {
- FILE* f = fopen(pidfile, "w");
- if (!f) {
- printlogf(L, "Error", "Cannot write pidfile; '%s'", pidfile);
- exit(-1); // ERRNO
- }
- fprintf(f, "%i\n", getpid());
- fclose(f);
+write_pidfile( lua_State *L, const char *pidfile )
+{
+ FILE* f = fopen( pidfile, "w" );
+
+ if( !f )
+ {
+ printlogf(
+ L, "Error",
+ "Cannot write pidfile; '%s'",
+ pidfile
+ )
+ ;
+ exit( -1 );
+ }
+
+ fprintf( f, "%i\n", getpid( ) );
+ fclose( f );
}
-/*****************************************************************************
- * Observances
- ****************************************************************************/
-/**
- * List of file descriptor watches.
- */
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+( Observances )
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+/*
+| List of file descriptor watches.
+*/
static struct observance * observances = NULL;
-static int observances_len = 0;
-static int observances_size = 0;
+static int observances_len = 0;
+static int observances_size = 0;
-/**
- * List of file descriptors to nonobserve.
- * While working for the oberver lists, it may
- * not be altered, thus nonobserve stores here the
- * actions that will be delayed.
- */
-static int *nonobservances = NULL;
-static int nonobservances_len = 0;
+
+/*
+| List of file descriptors to not observe.
+|
+| While working for the oberver lists, it may
+| not be altered, thus nonobserve stores the
+| delayed removals.
+*/
+static int * nonobservances = NULL;
+static int nonobservances_len = 0;
static int nonobservances_size = 0;
-/**
- * true while the observances list is being handled.
- */
+/*
+| True while the observances list is being handled.
+*/
static bool observance_action = false;
-/**
- * Core watches a filedescriptor to become ready,
- * one of read_ready or write_ready may be zero
- */
+
+/*
+| Core watches a filedescriptor to become ready,
+| one of read_ready or write_ready may be zero
+*/
extern void
-observe_fd(int fd,
- void (*ready) (lua_State *, struct observance *),
- void (*writey)(lua_State *, struct observance *),
- void (*tidy) (struct observance *),
- void *extra)
+observe_fd(
+ int fd,
+ void ( * ready ) (lua_State *, struct observance * ),
+ void ( * writey ) (lua_State *, struct observance * ),
+ void ( * tidy ) (struct observance * ),
+ void *extra
+)
{
int pos;
+
// looks if the fd is already there as pos or
// stores the position to insert the new fd in pos
- for(pos = 0; pos < observances_len; pos++) {
- if (fd <= observances[pos].fd) {
- break;
- }
+ for( pos = 0; pos < observances_len; pos++)
+ {
+ if( fd <= observances[ pos ].fd )
+ { break; }
}
- if (pos < observances_len && observances[pos].fd == fd) {
+
+ if( pos < observances_len && observances[ pos ].fd == fd )
+ {
// just updates an existing observance
- logstring("Masterloop", "updating fd observance");
- observances[pos].ready = ready;
- observances[pos].writey = writey;
- observances[pos].tidy = tidy;
- observances[pos].extra = extra;
+ logstring( "Masterloop", "updating fd observance" );
+ observances[ pos ].ready = ready;
+ observances[ pos ].writey = writey;
+ observances[ pos ].tidy = tidy;
+ observances[ pos ].extra = extra;
return;
}
- if (observance_action) {
- // TODO
- logstring("Error",
- "internal, New observances in ready/writey handlers not yet supported");
- exit(-1); // ERRNO
+ if( observance_action )
+ {
+ // FIXME
+ logstring(
+ "Error",
+ "New observances in ready/writey handlers not yet supported"
+ );
+
+ exit( -1 );
}
- if (!tidy) {
- logstring("Error",
- "internal, tidy() in observe_fd() must not be NULL.");
- exit(-1); // ERRNO
+ if( !tidy )
+ {
+ logstring(
+ "Error",
+ "internal, tidy() in observe_fd() must not be NULL."
+ );
+ exit( -1 );
}
- if (observances_len + 1 > observances_size) {
+
+ if( observances_len + 1 > observances_size )
+ {
observances_size = observances_len + 1;
- observances = s_realloc(observances,
- observances_size * sizeof(struct observance));
+ observances = s_realloc(
+ observances,
+ observances_size * sizeof( struct observance )
+ );
}
- memmove(observances + pos + 1, observances + pos,
- (observances_len - pos) * (sizeof(struct observance)));
+
+ memmove(
+ observances + pos + 1,
+ observances + pos,
+ (observances_len - pos) * sizeof(struct observance)
+ );
observances_len++;
- observances[pos].fd = fd;
- observances[pos].ready = ready;
- observances[pos].writey = writey;
- observances[pos].tidy = tidy;
- observances[pos].extra = extra;
+
+ observances[ pos ].fd = fd;
+ observances[ pos ].ready = ready;
+ observances[ pos ].writey = writey;
+ observances[ pos ].tidy = tidy;
+ observances[ pos ].extra = extra;
}
-/**
- * Makes the core to no longer watch a filedescriptor.
- */
+
+/*
+| Makes the core no longer watch a filedescriptor.
+*/
extern void
-nonobserve_fd(int fd)
+nonobserve_fd( int fd )
{
int pos;
- if (observance_action) {
+ if( observance_action )
+ {
// this function is called through a ready/writey handler
// while the core works through the observance list, thus
// it does not alter the list, but stores this actions
// on a stack
nonobservances_len++;
- if (nonobservances_len > nonobservances_size) {
+ if( nonobservances_len > nonobservances_size )
+ {
nonobservances_size = nonobservances_len;
- nonobservances = s_realloc(nonobservances, nonobservances_size * sizeof(int));
+ nonobservances = s_realloc(
+ nonobservances,
+ nonobservances_size * sizeof( int )
+ );
}
- nonobservances[nonobservances_len - 1] = fd;
+
+ nonobservances[ nonobservances_len - 1 ] = fd;
return;
}
// looks for the fd
- for(pos = 0; pos < observances_len; pos++) {
- if (observances[pos].fd == fd) {
- break;
- }
+ for( pos = 0; pos < observances_len; pos++ )
+ {
+ if( observances[ pos ].fd == fd )
+ { break; }
}
- if (pos >= observances_len) {
- logstring("Error",
- "internal fail, not observance file descriptor in nonobserve");
- exit(-1); //ERRNO
+
+ if( pos >= observances_len )
+ {
+ logstring(
+ "Error",
+ "internal fail, not observance file descriptor in nonobserve"
+ );
+
+ exit( -1 );
}
// tidies up the observance
- observances[pos].tidy(observances + pos);
+ observances[ pos ].tidy( observances + pos );
// and moves the list down
- memmove(observances + pos, observances + pos + 1,
- (observances_len - pos) * (sizeof(struct observance)));
+ memmove(
+ observances + pos,
+ observances + pos + 1,
+ (observances_len - pos) * sizeof( struct observance )
+ );
+
observances_len--;
}
-/**
- * A user observance became read-ready
- */
+
+/*
+| A user observance became read-ready.
+*/
static void
-user_obs_ready(lua_State *L, struct observance *obs)
+user_obs_ready(
+ lua_State * L,
+ struct observance * obs
+)
{
int fd = obs->fd;
+
// pushes the ready table on table
- lua_pushlightuserdata(L, (void *) user_obs_ready);
- lua_gettable(L, LUA_REGISTRYINDEX);
+ lua_pushlightuserdata( L, ( void * ) user_obs_ready );
+ lua_gettable( L, LUA_REGISTRYINDEX );
// pushes the error handler
- lua_pushlightuserdata(L, (void *) &callError);
- lua_gettable(L, LUA_REGISTRYINDEX);
+ lua_pushlightuserdata( L, (void *) &callError );
+ lua_gettable( L, LUA_REGISTRYINDEX );
- // pushed the user func
- lua_pushnumber(L, fd);
- lua_gettable(L, -3);
+ // pushes the user func
+ lua_pushnumber( L, fd );
+ lua_gettable( L, -3 );
// gives the ufunc the fd
- lua_pushnumber(L, fd);
+ lua_pushnumber( L, fd );
// calls the user function
- if (lua_pcall(L, 1, 0, -3)) exit(-1); // ERRNO
- lua_pop(L, 2);
+ if( lua_pcall( L, 1, 0, -3 ) )
+ { exit( -1 ); }
+
+ lua_pop( L, 2 );
}
-/**
- * A user observance became write-ready
- */
+
+/*
+| A user observance became write-ready
+*/
static void
-user_obs_writey(lua_State *L, struct observance *obs)
+user_obs_writey(
+ lua_State * L,
+ struct observance * obs
+)
{
int fd = obs->fd;
+
// pushes the writey table on table
- lua_pushlightuserdata(L, (void *) user_obs_writey);
- lua_gettable(L, LUA_REGISTRYINDEX);
+ lua_pushlightuserdata( L, (void *) user_obs_writey );
+ lua_gettable( L, LUA_REGISTRYINDEX );
// pushes the error handler
lua_pushlightuserdata(L, (void *) &callError);
- lua_gettable(L, LUA_REGISTRYINDEX);
+ lua_gettable( L, LUA_REGISTRYINDEX );
// pushes the user func
- lua_pushnumber(L, fd);
- lua_gettable(L, -3);
+ lua_pushnumber( L, fd );
+ lua_gettable( L, -3 );
// gives the user func the fd
- lua_pushnumber(L, fd);
+ lua_pushnumber( L, fd );
// calls the user function
- if (lua_pcall(L, 1, 0, -3)) exit(-1); // ERRNO
- lua_pop(L, 2);
+ if( lua_pcall( L, 1, 0, -3 ) )
+ {
+ exit(-1);
+ }
+
+ lua_pop( L, 2 );
}
-/**
- * Tidies up a user observance
- * TODO - give the user a chance to do something in that case!
- */
+/*
+| Tidies up a user observance
+| FIXME - give the user a chance to do something in that case!
+*/
static void
-user_obs_tidy(struct observance *obs)
+user_obs_tidy( struct observance *obs )
{
- close(obs->fd);
+ close( obs->fd );
}
-/*****************************************************************************
- * Library calls for lsyncd.lua
- *
- * These are as minimal as possible glues to the operating system needed for
- * lsyncd operation.
- ****************************************************************************/
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+( Library calls for the runner )
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-static void daemonize(lua_State *L);
-int l_stackdump(lua_State* L);
-/**
- * Logs a message.
- *
- * @param loglevel (Lua stack) loglevel of massage
- * @param string (Lua stack) the string to log
- */
+static void daemonize( lua_State *L );
+int l_stackdump( lua_State* L );
+
+
+/*
+| Logs a message.
+|
+| Params on Lua stack:
+|
+| 1: loglevel of massage
+| 2: the string to log
+*/
static int
-l_log(lua_State *L)
+l_log( lua_State *L )
{
const char * cat; // log category
const char * message; // log message
int priority; // log priority
- cat = luaL_checkstring(L, 1);
- priority = check_logcat(cat);
- /* skips filtered messages */
- if (priority > settings.log_level) return 0;
+ cat = luaL_checkstring( L, 1 );
+ priority = check_logcat( cat );
+
+ // skips filtered messages
+ if( priority > settings.log_level )
+ { return 0; }
+ // replaces non string values
{
- // replace non string values
int i;
int top = lua_gettop(L);
- for (i = 1; i <= top; i++) {
- int t = lua_type(L, i);
- switch (t) {
- case LUA_TTABLE:
- lua_pushfstring(L, "(Table: %p)", lua_topointer(L, i));
- lua_replace(L, i);
- break;
- case LUA_TBOOLEAN:
- if (lua_toboolean(L, i)) {
- lua_pushstring(L, "(true)");
- } else {
- lua_pushstring(L, "(false)");
- }
- lua_replace(L, i);
- break;
- case LUA_TUSERDATA:
- {
- clock_t *c = (clock_t *) luaL_checkudata(L, i, "Lsyncd.jiffies");
- double d = (*c);
- d /= clocks_per_sec;
- lua_pushfstring(L, "(Timestamp: %f)", d);
+ for( i = 1; i <= top; i++ )
+ {
+ int t = lua_type( L, i );
+
+ switch( t )
+ {
+ case LUA_TTABLE :
+ lua_pushfstring(
+ L,
+ "(Table: %p)",
+ lua_topointer( L, i )
+ );
+
+ lua_replace( L, i );
+ break;
+
+ case LUA_TBOOLEAN :
+ if( lua_toboolean( L, i ) )
+ { lua_pushstring( L, "(true)" ); }
+ else
+ { lua_pushstring( L, "(false)" ); }
+
lua_replace(L, i);
- }
- break;
- case LUA_TNIL:
- lua_pushstring(L, "(nil)");
- lua_replace(L, i);
- break;
+ break;
+
+ case LUA_TUSERDATA:
+ {
+ clock_t *c = ( clock_t * )
+ luaL_checkudata( L, i, "Lsyncd.jiffies" );
+
+ double d = *c;
+ d /= clocks_per_sec;
+ lua_pushfstring( L, "(Timestamp: %f)", d );
+ lua_replace( L, i );
+ }
+ break;
+
+ case LUA_TNIL:
+ lua_pushstring( L, "(nil)" );
+ lua_replace( L, i );
+ break;
}
}
}
// concates if there is more than one string parameter
- lua_concat(L, lua_gettop(L) - 1);
+ lua_concat( L, lua_gettop( L ) - 1 );
+
+ message = luaL_checkstring( L, 2 );
+ logstring0( priority, cat, message );
- message = luaL_checkstring(L, 2);
- logstring0(priority, cat, message);
return 0;
}
-/**
- * Returns (on Lua stack) the current kernels
- * clock state (jiffies)
- */
+
+/*
+| Returns (on Lua stack) the current kernels
+| clock state (jiffies)
+*/
extern int
l_now(lua_State *L)
{
- clock_t *j = lua_newuserdata(L, sizeof(clock_t));
- luaL_getmetatable(L, "Lsyncd.jiffies");
- lua_setmetatable(L, -2);
- *j = times(dummy_tms);
+ clock_t * j = lua_newuserdata( L, sizeof( clock_t ) );
+ luaL_getmetatable( L, "Lsyncd.jiffies" );
+ lua_setmetatable( L, -2 );
+ *j = times( dummy_tms );
return 1;
}
-/**
- * Executes a subprocess. Does not wait for it to return.
- *
- * @param (Lua stack) Path to binary to call
- * @params (Lua stack) list of string as arguments
- * or "<" in which case the next argument is a string that will be piped
- * on stdin. the arguments will follow that one.
- *
- * @return (Lua stack) the pid on success, 0 on failure.
- */
+/*
+| Executes a subprocess. Does not wait for it to return.
+|
+| Params on Lua stack:
+|
+| 1: Path to binary to call
+| 2: List of string as arguments
+| or "<" in which case the next argument is a string
+| that will be piped on stdin.
+| The arguments will follow that one.
+|
+| Returns (Lua stack) the pid on success, 0 on failure.
+*/
static int
-l_exec(lua_State *L)
+l_exec( lua_State *L )
{
- const char *binary = luaL_checkstring(L, 1); // the binary to call
- int argc = lua_gettop(L) - 1; // number of arguments
- pid_t pid; // the pid spawned
- int li = 1; // the arguments position in the lua arguments
-
- char const *pipe_text = NULL; // the pipe to text
- size_t pipe_len = 0; // the pipes length
- char const **argv; // the arguments
- int pipefd[2]; // pipe file descriptors
+ // the binary to call
+ const char *binary = luaL_checkstring(L, 1);
+
+ // number of arguments
+ int argc = lua_gettop( L ) - 1;
+
+ // the pid spawned
+ pid_t pid;
+
+ // the arguments position in the lua arguments
+ int li = 1;
+
+ // the pipe to text
+ char const * pipe_text = NULL;
+
+ // the pipes length
+ size_t pipe_len = 0;
+
+ // the arguments
+ char const ** argv;
+
+ // pipe file descriptors
+ int pipefd[ 2 ];
+
int i;
- // expands tables if there are any, removes nils
- for(i = 1; i <= lua_gettop(L); i++) {
- if (lua_isnil(L, i)) {
- lua_remove(L, i);
+ // expands tables
+ // and removes nils
+ for( i = 1; i <= lua_gettop( L ); i++ )
+ {
+ if( lua_isnil( L, i ) )
+ {
+ lua_remove( L, i );
i--;
argc--;
continue;
}
- if (lua_istable(L, i)) {
+ if( lua_istable( L, i ) )
+ {
int tlen;
int it;
- lua_checkstack(L, lua_gettop(L) + lua_objlen(L, i) + 1);
- // move table to top of stack
- lua_pushvalue(L, i);
- lua_remove(L, i);
+ lua_checkstack( L, lua_gettop( L ) + lua_objlen( L, i ) + 1 );
+
+ // moves table to top of stack
+ lua_pushvalue( L, i );
+ lua_remove( L, i );
argc--;
- tlen = lua_objlen(L, -1);
- for (it = 1; it <= tlen; it++) {
- lua_pushinteger(L, it);
- lua_gettable(L, -2);
- lua_insert(L,i);
+ tlen = lua_objlen( L, -1 );
+
+ for( it = 1; it <= tlen; it++ )
+ {
+ lua_pushinteger( L, it );
+ lua_gettable( L, -2 );
+ lua_insert( L, i );
i++;
argc++;
}
i--;
- lua_pop(L, 1);
+ lua_pop( L, 1 );
}
}
- // writes a log message, prepares the message only if actually needed.
- if (check_logcat("Exec") <= settings.log_level) {
- lua_checkstack(L, lua_gettop(L) + argc * 3 + 2);
- lua_pushvalue(L, 1);
- for(i = 1; i <= argc; i++) {
- lua_pushstring(L, " [");
- lua_pushvalue(L, i + 1);
- lua_pushstring(L, "]");
+ // writes a log message (if needed).
+ if( check_logcat( "Exec" ) <= settings.log_level )
+ {
+ lua_checkstack( L, lua_gettop( L ) + argc * 3 + 2 );
+ lua_pushvalue( L, 1 );
+
+ for( i = 1; i <= argc; i++ )
+ {
+ lua_pushstring( L, " [" );
+ lua_pushvalue( L, i + 1 );
+ lua_pushstring( L, "]" );
}
- lua_concat(L, 3 * argc + 1);
- logstring0(LOG_DEBUG, "Exec", luaL_checkstring(L, -1));
- lua_pop(L, 1);
+
+ lua_concat( L, 3 * argc + 1 );
+
+ logstring0(
+ LOG_DEBUG, "Exec",
+ luaL_checkstring(L, -1)
+ );
+
+ lua_pop( L, 1 );
}
- if (argc >= 2 && !strcmp(luaL_checkstring(L, 2), "<")) {
+ if( argc >= 2 && !strcmp( luaL_checkstring( L, 2 ), "<" ) )
+ {
// pipes something into stdin
- if (!lua_isstring(L, 3)) {
- logstring("Error", "in spawn(), expected a string after pipe '<'");
- exit(-1); // ERRNO
+ if( !lua_isstring( L, 3 ) )
+ {
+ logstring(
+ "Error",
+ "in spawn(), expected a string after pipe '<'"
+ );
+
+ exit( -1 );
}
- pipe_text = lua_tolstring(L, 3, &pipe_len);
- if (strlen(pipe_text) > 0) {
+
+ pipe_text = lua_tolstring( L, 3, &pipe_len );
+
+ if( strlen( pipe_text ) > 0 )
+ {
// creates the pipe
- if (pipe(pipefd) == -1) {
- logstring("Error", "cannot create a pipe!");
- exit(-1); // ERRNO
+ if( pipe( pipefd ) == -1 )
+ {
+ logstring( "Error", "cannot create a pipe!" );
+
+ exit( -1 );
}
+
// always closes the write end for child processes
- close_exec_fd(pipefd[1]);
+ close_exec_fd( pipefd[ 1 ] );
+
// sets the write end on non-blocking
- non_block_fd(pipefd[1]);
- } else {
+ non_block_fd( pipefd[ 1 ] );
+ }
+ else
+ {
pipe_text = NULL;
}
argc -= 2;
@@ -898,72 +1170,115 @@
}
// prepares the arguments
- argv = s_calloc(argc + 2, sizeof(char *));
- argv[0] = binary;
- for(i = 1; i <= argc; i++) {
- argv[i] = luaL_checkstring(L, i + li);
- }
- argv[i] = NULL;
- pid = fork();
+ argv = s_calloc( argc + 2, sizeof( char * ) );
+ argv[ 0 ] = binary;
+ for( i = 1; i <= argc; i++ )
+ { argv[i] = luaL_checkstring( L, i + li ); }
+ argv[ i ] = NULL;
+
+ // the fork!
+ pid = fork( );
- if (pid == 0) {
+ if( pid == 0 )
+ {
// replaces stdin for pipes
- if (pipe_text) dup2(pipefd[0], STDIN_FILENO);
+ if( pipe_text )
+ { dup2( pipefd[ 0 ], STDIN_FILENO ); }
// if lsyncd runs as a daemon and has a logfile it will redirect
// stdout/stderr of child processes to the logfile.
- if (is_daemon && settings.log_file) {
- if (!freopen(settings.log_file, "a", stdout)) {
- printlogf(L, "Error", "cannot redirect stdout to '%s'.", settings.log_file);
+ if( is_daemon && settings.log_file )
+ {
+ if( !freopen( settings.log_file, "a", stdout ) )
+ {
+ printlogf(
+ L, "Error",
+ "cannot redirect stdout to '%s'.",
+ settings.log_file
+ );
}
- if (!freopen(settings.log_file, "a", stderr)) {
- printlogf(L, "Error", "cannot redirect stderr to '%s'.", settings.log_file);
+ if( !freopen( settings.log_file, "a", stderr ) )
+ {
+ printlogf(
+ L, "Error",
+ "cannot redirect stderr to '%s'.",
+ settings.log_file
+ );
}
}
- execv(binary, (char **)argv);
+
+ execv( binary, ( char ** ) argv );
+
// in a sane world execv does not return!
- printlogf(L, "Error", "Failed executing [%s]!", binary);
- exit(-1); // ERRNO
+ printlogf(
+ L, "Error",
+ "Failed executing [ %s ]!",
+ binary
+ );
+
+ exit( -1 );
}
- if (pipe_text) {
+ if( pipe_text )
+ {
int len;
+
// first closes read-end of pipe, this is for child process only
- close(pipefd[0]);
+ close( pipefd[ 0 ] );
+
// starts filling the pipe
- len = write(pipefd[1], pipe_text, pipe_len);
- if (len < 0) {
- logstring("Normal", "immediatly broken pipe.");
- close(pipefd[1]);
- } else if (len == pipe_len) {
+ len = write( pipefd[ 1 ], pipe_text, pipe_len );
+
+ if( len < 0 )
+ {
+ logstring( "Normal", "immediatly broken pipe." );
+ close( pipefd[ 1 ] );
+ }
+ else if( len == pipe_len )
+ {
// usual and best case, the pipe accepted all input -> close
- close(pipefd[1]);
- logstring("Exec", "one-sweeped pipe");
- } else {
+ close( pipefd[ 1 ] );
+ logstring( "Exec", "one-sweeped pipe" );
+ }
+ else
+ {
struct pipemsg *pm;
- logstring("Exec", "adding pipe observance");
- pm = s_calloc(1, sizeof(struct pipemsg));
- pm->text = s_calloc(pipe_len + 1, sizeof(char*));
- memcpy(pm->text, pipe_text, pipe_len + 1);
+ logstring( "Exec", "adding pipe observance" );
+ pm = s_calloc( 1, sizeof( struct pipemsg ) );
+ pm->text = s_calloc( pipe_len + 1, sizeof( char * ) );
+ memcpy( pm->text, pipe_text, pipe_len + 1 );
pm->tlen = pipe_len;
pm->pos = len;
- observe_fd(pipefd[1], NULL, pipe_writey, pipe_tidy, pm);
+
+ observe_fd(
+ pipefd[ 1 ],
+ NULL,
+ pipe_writey,
+ pipe_tidy,
+ pm
+ );
}
}
- free(argv);
- lua_pushnumber(L, pid);
+
+ free( argv );
+ lua_pushnumber( L, pid );
+
return 1;
}
-/**
- * Converts a relative directory path to an absolute.
- *
- * @param dir: a relative path to directory
- * @return the absolute path of directory
- */
+
+/*
+| Converts a relative directory path to an absolute.
+|
+| Params on Lua stack:
+| 1: a relative path to directory
+|
+| Returns on Lua stack:
+| The absolute path of directory
+*/
static int
-l_realdir(lua_State *L)
+l_realdir( lua_State *L )
{
luaL_Buffer b;
const char *rdir = luaL_checkstring(L, 1);
@@ -1002,968 +1317,1432 @@
return 1;
}
-/**
- * Dumps the LUA stack. For debugging purposes.
- */
+/*
+| Dumps the Lua stack.
+| For debugging purposes.
+*/
int
-l_stackdump(lua_State* L)
+l_stackdump( lua_State * L )
{
int i;
- int top = lua_gettop(L);
- printlogf(L, "Debug", "total in stack %d",top);
- for (i = 1; i <= top; i++) {
- int t = lua_type(L, i);
- switch (t) {
- case LUA_TSTRING:
- printlogf(L, "Debug", "%d string: '%s'", i, lua_tostring(L, i));
- break;
- case LUA_TBOOLEAN:
- printlogf(L, "Debug", "%d boolean %s", i, lua_toboolean(L, i) ? "true" : "false");
- break;
- case LUA_TNUMBER:
- printlogf(L, "Debug", "%d number: %g", i, lua_tonumber(L, i));
- break;
- default:
- printlogf(L, "Debug", "%d %s", i, lua_typename(L, t));
- break;
+ int top = lua_gettop( L );
+
+ printlogf(
+ L, "Debug",
+ "total in stack %d",
+ top
+ );
+
+ for( i = 1; i <= top; i++ )
+ {
+ int t = lua_type( L, i );
+ switch( t )
+ {
+ case LUA_TSTRING:
+ printlogf(
+ L, "Debug",
+ "%d string: '%s'",
+ i, lua_tostring( L, i )
+ );
+ break;
+
+ case LUA_TBOOLEAN:
+ printlogf(
+ L, "Debug",
+ "%d boolean %s",
+ i, lua_toboolean( L, i ) ? "true" : "false"
+ );
+ break;
+
+ case LUA_TNUMBER:
+ printlogf(
+ L, "Debug",
+ "%d number: %g",
+ i, lua_tonumber( L, i )
+ );
+ break;
+
+ default:
+ printlogf(
+ L, "Debug",
+ "%d %s",
+ i, lua_typename( L, t )
+ );
+ break;
}
}
+
return 0;
}
-/**
- * Reads the directories entries.
- *
- * @param (Lua stack) absolute path to directory.
- * @return (Lua stack) a table of directory names.
- * names are keys, values are boolean
- * true on dirs.
- */
+/*
+| Reads the directories entries.
+|
+| Params on Lua stack:
+| 1: absolute path to directory
+|
+| Returns on Lua stack:
+| a table of directory names.
+| names are keys
+| values are boolean true on dirs.
+*/
static int
-l_readdir (lua_State *L)
+l_readdir ( lua_State *L )
{
- const char * dirname = luaL_checkstring(L, 1);
+ const char * dirname = luaL_checkstring( L, 1 );
DIR *d;
- d = opendir(dirname);
- if (d == NULL) {
- printlogf(L, "Error", "cannot open dir [%s].", dirname);
+ d = opendir( dirname );
+ if( d == NULL )
+ {
+ printlogf(
+ L, "Error", "cannot open dir [%s].",
+ dirname
+ );
+
return 0;
}
- lua_newtable(L);
- while (!hup && !term) {
- struct dirent *de = readdir(d);
+ lua_newtable( L );
+
+ while( !hup && !term )
+ {
+ struct dirent *de = readdir( d );
bool isdir;
- if (de == NULL) break; // finished
+
+ if( de == NULL )
+ {
+ // finished
+ break;
+ }
// ignores . and ..
- if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue;
+ if(
+ !strcmp( de->d_name, "." ) ||
+ !strcmp( de->d_name, ".." )
+ )
+ {
+ continue;
+ }
- if (de->d_type == DT_UNKNOWN) {
+ if( de->d_type == DT_UNKNOWN )
+ {
// must call stat on some systems :-/
- char *entry = s_malloc(strlen(dirname) + strlen(de->d_name) + 2);
+ // ( e.g. ReiserFS )
+ char *entry = s_malloc(
+ strlen( dirname ) +
+ strlen( de->d_name ) +
+ 2
+ );
struct stat st;
- strcpy(entry, dirname);
- strcat(entry, "/");
- strcat(entry, de->d_name);
- lstat(entry, &st);
- isdir = S_ISDIR(st.st_mode);
- free(entry);
- } else {
- // readdir can trusted
+
+ strcpy( entry, dirname );
+ strcat( entry, "/" );
+ strcat( entry, de->d_name );
+
+ lstat( entry, &st );
+
+ isdir = S_ISDIR( st.st_mode );
+
+ free( entry );
+ }
+ else
+ {
+ // otherwise readdir can be trusted
isdir = de->d_type == DT_DIR;
}
// adds this entry to the Lua table
- lua_pushstring(L, de->d_name);
- lua_pushboolean(L, isdir);
- lua_settable(L, -3);
+ lua_pushstring( L, de->d_name );
+ lua_pushboolean( L, isdir );
+ lua_settable( L, -3 );
}
- closedir(d);
+
+ closedir( d );
return 1;
}
-/**
- * Terminates lsyncd daemon.
- *
- * @param (Lua stack) exitcode for lsyncd.
- *
- * Does not return.
- */
+
+/*
+| Terminates Lsyncd.
+|
+| Params on Lua stack:
+| 1: exitcode of Lsyncd.
+|
+| Does not return.
+|
+*/
int
l_terminate(lua_State *L)
{
- int exitcode = luaL_checkinteger(L, 1);
- exit(exitcode);
+ int exitcode = luaL_checkinteger( L, 1 );
+
+ exit( exitcode );
+
return 0;
}
-/**
- * Configures core parameters.
- *
- * @param (Lua stack) a string for a core configuratoin
- * @param (Lua stack) --differes depending on string.
- */
+/*
+| Configures core parameters.
+|
+| Params on Lua stack:
+| 1: a string, configure option
+| 2: depends on Param 1
+*/
static int
-l_configure(lua_State *L)
+l_configure( lua_State *L )
{
- const char * command = luaL_checkstring(L, 1);
- if (!strcmp(command, "running")) {
+ const char * command = luaL_checkstring( L, 1 );
+ if( !strcmp( command, "running" ) )
+ {
// set by runner after first initialize
// from this on log to configurated log end instead of
// stdout/stderr
first_time = false;
- if (!settings.nodaemon && !settings.log_file) {
+ if( !settings.nodaemon && !settings.log_file )
+ {
settings.log_syslog = true;
- const char * log_ident = settings.log_ident ? settings.log_ident : "lsyncd";
- openlog(log_ident, 0, settings.log_facility);
+
+ const char * log_ident =
+ settings.log_ident ?
+ settings.log_ident :
+ "lsyncd";
+
+ openlog( log_ident, 0, settings.log_facility );
}
- if (!settings.nodaemon && !is_daemon) {
- logstring("Debug", "daemonizing now.");
- daemonize(L);
+ if( !settings.nodaemon && !is_daemon )
+ {
+ logstring( "Debug", "daemonizing now." );
+ daemonize( L );
}
- if (settings.pidfile) write_pidfile(L, settings.pidfile);
+ if( settings.pidfile )
+ {
+ write_pidfile( L, settings.pidfile );
+ }
- } else if (!strcmp(command, "nodaemon")) {
+ }
+ else if( !strcmp( command, "nodaemon" ) )
+ {
settings.nodaemon = true;
+ }
+ else if( !strcmp( command, "logfile" ) )
+ {
+ const char * file = luaL_checkstring( L, 2 );
+
+ if( settings.log_file )
+ { free( settings.log_file ); }
+
+ settings.log_file = s_strdup( file );
+ }
+ else if( !strcmp( command, "pidfile" ) )
+ {
+ const char * file = luaL_checkstring( L, 2 );
- } else if (!strcmp(command, "logfile")) {
- const char * file = luaL_checkstring(L, 2);
- if (settings.log_file) free(settings.log_file);
- settings.log_file = s_strdup(file);
-
- } else if (!strcmp(command, "pidfile")) {
- const char * file = luaL_checkstring(L, 2);
- if (settings.pidfile) free(settings.pidfile);
- settings.pidfile = s_strdup(file);
-
- } else if (!strcmp(command, "logfacility")) {
- if (lua_isstring(L, 2)) {
- const char * fname = luaL_checkstring(L, 2);
+ if( settings.pidfile )
+ { free( settings.pidfile ); }
+
+ settings.pidfile = s_strdup( file );
+ }
+ else if( !strcmp( command, "logfacility" ) )
+ {
+ if( lua_isstring( L, 2 ) )
+ {
+ const char * fname = luaL_checkstring( L, 2 );
int i;
- for(i = 0; facilitynames[i].c_name; i++) {
- if (!strcasecmp(fname, facilitynames[i].c_name)) break;
+ for( i = 0; facilitynames[ i ].c_name; i++ )
+ {
+ if( !strcasecmp( fname, facilitynames[ i ].c_name ) )
+ { break; }
}
- if (!facilitynames[i].c_name) {
- printlogf(L, "Error", "Logging facility '%s' unknown.", fname);
- exit(-1); //ERRNO
+
+ if( !facilitynames[ i ].c_name )
+ {
+ printlogf(
+ L, "Error",
+ "Logging facility '%s' unknown.",
+ fname
+ );
+
+ exit( -1 );
}
- settings.log_facility = facilitynames[i].c_val;
- } else if (lua_isnumber(L, 2)) {
+ settings.log_facility = facilitynames[ i ].c_val;
+ }
+ else if (lua_isnumber(L, 2))
+ {
settings.log_facility = luaL_checknumber(L, 2);
- } else {
- printlogf(L, "Error", "Logging facility must be a number or string");
- exit(-1); // ERRNO;
}
+ else
+ {
+ printlogf(
+ L, "Error",
+ "Logging facility must be a number or string"
+ );
- } else if (!strcmp(command, "logident")) {
- const char * ident = luaL_checkstring(L, 2);
- if (settings.log_ident) free(settings.log_ident);
- settings.log_ident = s_strdup(ident);
-
- } else {
- printlogf(L, "Error", "Internal error, unknown parameter in l_configure(%s)", command);
- exit(-1); //ERRNO
+ exit( -1 );
+ }
+ }
+ else if( !strcmp( command, "logident" ) )
+ {
+ const char * ident = luaL_checkstring( L, 2 );
+
+ if (settings.log_ident)
+ { free(settings.log_ident); }
+
+ settings.log_ident = s_strdup( ident );
+ }
+ else
+ {
+ printlogf(
+ L, "Error",
+ "Internal error, unknown parameter in l_configure( %s )",
+ command
+ );
+
+ exit( -1 );
}
return 0;
}
-/**
- * Allows the user to observe filedescriptors
- *
- * @param (Lua stack) filedescriptor.
- * @param (Lua stack) function to call on ready
- * @param (Lua stack) function to call on writey
- */
+/*
+| Allows user scripts to observe filedescriptors
+|
+| Params on Lua stack:
+| 1: file descriptor
+| 2: function to call when read becomes ready
+| 3: function to call when write becomes ready
+*/
static int
-l_observe_fd(lua_State *L)
+l_observe_fd( lua_State *L )
{
- int fd = luaL_checknumber(L, 1);
+ int fd = luaL_checknumber( L, 1 );
bool ready = false;
bool writey = false;
+
// Stores the user function in the lua registry.
// It uses the address of the cores ready/write functions
// for the user as key
- if (!lua_isnoneornil(L, 2)) {
- lua_pushlightuserdata(L, (void *) user_obs_ready);
- lua_gettable(L, LUA_REGISTRYINDEX);
- if lua_isnil(L, -1) {
- lua_pop(L, 1);
- lua_newtable(L);
- lua_pushlightuserdata(L, (void *) user_obs_ready);
- lua_pushvalue(L, -2);
- lua_settable(L, LUA_REGISTRYINDEX);
- }
- lua_pushnumber(L, fd);
- lua_pushvalue(L, 2);
- lua_settable(L, -3);
- lua_pop(L, 1);
+ if( !lua_isnoneornil( L, 2 ) )
+ {
+ lua_pushlightuserdata( L, (void *) user_obs_ready );
+
+ lua_gettable( L, LUA_REGISTRYINDEX );
+
+ if( lua_isnil( L, -1 ) )
+ {
+ lua_pop ( L, 1 );
+ lua_newtable ( L );
+ lua_pushlightuserdata ( L, (void *) user_obs_ready );
+ lua_pushvalue ( L, -2 );
+ lua_settable ( L, LUA_REGISTRYINDEX );
+ }
+
+ lua_pushnumber ( L, fd );
+ lua_pushvalue ( L, 2 );
+ lua_settable ( L, -3 );
+ lua_pop ( L, 1 );
+
ready = true;
}
- if (!lua_isnoneornil(L, 3)) {
- lua_pushlightuserdata(L, (void *) user_obs_writey);
- lua_gettable(L, LUA_REGISTRYINDEX);
- if lua_isnil(L, -1) {
- lua_pop(L, 1);
- lua_newtable(L);
- lua_pushlightuserdata(L, (void *) user_obs_writey);
- lua_pushvalue(L, -2);
- lua_settable(L, LUA_REGISTRYINDEX);
- }
- lua_pushnumber(L, fd);
- lua_pushvalue(L, 3);
- lua_settable(L, -3);
- lua_pop(L, 1);
+ if( !lua_isnoneornil( L, 3 ) )
+ {
+ lua_pushlightuserdata( L, (void *) user_obs_writey );
+
+ lua_gettable (L, LUA_REGISTRYINDEX );
+
+ if( lua_isnil(L, -1) )
+ {
+ lua_pop ( L, 1 );
+ lua_newtable ( L );
+ lua_pushlightuserdata ( L, (void *) user_obs_writey );
+ lua_pushvalue ( L, -2 );
+ lua_settable ( L, LUA_REGISTRYINDEX );
+ }
+
+ lua_pushnumber ( L, fd );
+ lua_pushvalue ( L, 3 );
+ lua_settable ( L, -3 );
+ lua_pop ( L, 1 );
+
writey = true;
}
- /* tells the core to watch the fd */
- observe_fd(fd,
- ready ? user_obs_ready : NULL,
- writey ? user_obs_writey : NULL,
- user_obs_tidy,
- NULL);
+
+ // tells the core to watch the fd
+ observe_fd(
+ fd,
+ ready ? user_obs_ready : NULL,
+ writey ? user_obs_writey : NULL,
+ user_obs_tidy,
+ NULL
+ );
+
return 0;
}
-/**
- * Removes a user observance
- * @param (Lua stack) filedescriptor.
- */
+/*
+| Removes a user observance
+|
+| Params on Lua stack:
+| 1: exitcode of Lsyncd.
+*/
extern int
-l_nonobserve_fd(lua_State *L)
+l_nonobserve_fd( lua_State *L )
{
- int fd = luaL_checknumber(L, 1);
+ int fd = luaL_checknumber( L, 1 );
// removes the read function
- lua_pushlightuserdata(L, (void *) user_obs_ready);
- lua_gettable(L, LUA_REGISTRYINDEX);
- if (!lua_isnil(L, -1)) {
- lua_pushnumber(L, fd);
- lua_pushnil(L);
- lua_settable(L, -2);
- }
- lua_pop(L, 1);
+ lua_pushlightuserdata( L, (void *) user_obs_ready );
+ lua_gettable( L, LUA_REGISTRYINDEX );
- lua_pushlightuserdata(L, (void *) user_obs_writey);
- lua_gettable(L, LUA_REGISTRYINDEX);
- if (!lua_isnil(L, -1)) {
- lua_pushnumber(L, fd);
- lua_pushnil(L);
- lua_settable(L, -2);
+ if( !lua_isnil( L, -1 ) )
+ {
+ lua_pushnumber ( L, fd );
+ lua_pushnil ( L );
+ lua_settable ( L, -2 );
+ }
+ lua_pop( L, 1 );
+
+ lua_pushlightuserdata( L, (void *) user_obs_writey );
+ lua_gettable( L, LUA_REGISTRYINDEX );
+ if ( !lua_isnil( L, -1 ) )
+ {
+ lua_pushnumber ( L, fd );
+ lua_pushnil ( L );
+ lua_settable ( L, -2 );
}
- lua_pop(L, 1);
+ lua_pop( L, 1 );
- nonobserve_fd(fd);
+ nonobserve_fd( fd );
return 0;
}
-static const luaL_reg lsyncdlib[] = {
- {"configure", l_configure },
- {"exec", l_exec },
- {"log", l_log },
- {"now", l_now },
- {"nonobserve_fd", l_nonobserve_fd },
- {"observe_fd", l_observe_fd },
- {"readdir", l_readdir },
- {"realdir", l_realdir },
- {"stackdump", l_stackdump },
- {"terminate", l_terminate },
- {NULL, NULL}
+/*
+| The Lsnycd's core library
+*/
+static const luaL_Reg lsyncdlib[] =
+{
+ { "configure", l_configure },
+ { "exec", l_exec },
+ { "log", l_log },
+ { "now", l_now },
+ { "nonobserve_fd", l_nonobserve_fd },
+ { "observe_fd", l_observe_fd },
+ { "readdir", l_readdir },
+ { "realdir", l_realdir },
+ { "stackdump", l_stackdump },
+ { "terminate", l_terminate },
+ { NULL, NULL }
};
-/**
- * Adds two jiffies or a number to a jiffy
- */
+/*
+| Adds a number in seconds to a jiffy timestamp.
+*/
static int
-l_jiffies_add(lua_State *L)
+l_jiffies_add( lua_State *L )
{
- clock_t *p1 = (clock_t *) lua_touserdata(L, 1);
- clock_t *p2 = (clock_t *) lua_touserdata(L, 2);
- if (p1 && p2) {
- logstring("Error", "Cannot add to timestamps!");
- exit(-1); // ERRNO
+ clock_t *p1 = ( clock_t * ) lua_touserdata( L, 1 );
+ clock_t *p2 = ( clock_t * ) lua_touserdata( L, 2 );
+
+ if( p1 && p2 )
+ {
+ logstring( "Error", "Cannot add two timestamps!" );
+ exit( -1 );
}
+
{
- clock_t a1 = p1 ? *p1 : luaL_checknumber(L, 1) * clocks_per_sec;
- clock_t a2 = p2 ? *p2 : luaL_checknumber(L, 2) * clocks_per_sec;
- clock_t *r = (clock_t *) lua_newuserdata(L, sizeof(clock_t));
- luaL_getmetatable(L, "Lsyncd.jiffies");
- lua_setmetatable(L, -2);
+ clock_t a1 =
+ p1 ? *p1 : luaL_checknumber( L, 1 ) * clocks_per_sec;
+
+ clock_t a2 =
+ p2 ? *p2 : luaL_checknumber( L, 2 ) * clocks_per_sec;
+
+ clock_t *r =
+ ( clock_t * ) lua_newuserdata( L, sizeof( clock_t ) );
+
+ luaL_getmetatable( L, "Lsyncd.jiffies" );
+ lua_setmetatable( L, -2 );
*r = a1 + a2;
return 1;
}
}
-/**
- * Adds two jiffies or a number to a jiffy
- */
+/*
+| Subracts two jiffy timestamps resulting in a number in seconds
+| or substracts a jiffy by a number in seconds resulting a jiffy timestamp.
+*/
static int
-l_jiffies_sub(lua_State *L)
+l_jiffies_sub( lua_State *L )
{
- clock_t *p1 = (clock_t *) lua_touserdata(L, 1);
- clock_t *p2 = (clock_t *) lua_touserdata(L, 2);
- if (p1 && p2) {
+ clock_t *p1 = ( clock_t * ) lua_touserdata( L, 1 );
+ clock_t *p2 = ( clock_t * ) lua_touserdata( L, 2 );
+
+ if( p1 && p2 )
+ {
// substracting two timestamps result in a timespan in seconds
clock_t a1 = *p1;
clock_t a2 = *p2;
lua_pushnumber(L, ((double) (a1 -a2)) / clocks_per_sec);
return 1;
}
+
// makes a timestamp earlier by NUMBER seconds
- clock_t a1 = p1 ? *p1 : luaL_checknumber(L, 1) * clocks_per_sec;
- clock_t a2 = p2 ? *p2 : luaL_checknumber(L, 2) * clocks_per_sec;
- clock_t *r = (clock_t *) lua_newuserdata(L, sizeof(clock_t));
- luaL_getmetatable(L, "Lsyncd.jiffies");
- lua_setmetatable(L, -2);
+ clock_t a1 = p1 ? *p1 : luaL_checknumber( L, 1 ) * clocks_per_sec;
+ clock_t a2 = p2 ? *p2 : luaL_checknumber( L, 2 ) * clocks_per_sec;
+
+ clock_t *r = (clock_t *) lua_newuserdata( L, sizeof( clock_t ) );
+ luaL_getmetatable( L, "Lsyncd.jiffies" );
+ lua_setmetatable( L, -2 );
+
*r = a1 - a2;
+
return 1;
}
-/**
- * Substracts two jiffies or a number to a jiffy
- */
+/*
+| Compares two jiffy timestamps
+*/
static int
-l_jiffies_eq(lua_State *L)
+l_jiffies_eq( lua_State *L )
{
- clock_t a1 = (*(clock_t *) luaL_checkudata(L, 1, "Lsyncd.jiffies"));
- clock_t a2 = (*(clock_t *) luaL_checkudata(L, 2, "Lsyncd.jiffies"));
- lua_pushboolean(L, a1 == a2);
+ clock_t a1 = ( *( clock_t * ) luaL_checkudata( L, 1, "Lsyncd.jiffies" ) );
+ clock_t a2 = ( *( clock_t * ) luaL_checkudata( L, 2, "Lsyncd.jiffies" ) );
+
+ lua_pushboolean( L, a1 == a2 );
+
return 1;
}
-/**
- * True if jiffy1 before jiffy2
- */
+/*
+* True if jiffy1 timestamp is eariler than jiffy2 timestamp
+*/
static int
-l_jiffies_lt(lua_State *L)
+l_jiffies_lt( lua_State *L )
{
- clock_t a1 = (*(clock_t *) luaL_checkudata(L, 1, "Lsyncd.jiffies"));
- clock_t a2 = (*(clock_t *) luaL_checkudata(L, 2, "Lsyncd.jiffies"));
- lua_pushboolean(L, time_before(a1, a2));
+ clock_t a1 = ( *( clock_t * ) luaL_checkudata( L, 1, "Lsyncd.jiffies" ) );
+ clock_t a2 = ( *( clock_t * ) luaL_checkudata( L, 2, "Lsyncd.jiffies" ) );
+
+ lua_pushboolean( L, time_before( a1, a2 ) );
+
return 1;
}
-/**
- * True if jiffy1 before or == jiffy2
- */
+/*
+| True if jiffy1 before or equals jiffy2
+*/
static int
l_jiffies_le(lua_State *L)
{
- clock_t a1 = (*(clock_t *) luaL_checkudata(L, 1, "Lsyncd.jiffies"));
- clock_t a2 = (*(clock_t *) luaL_checkudata(L, 2, "Lsyncd.jiffies"));
- lua_pushboolean(L, (a1 == a2) || time_before(a1, a2));
+ clock_t a1 = ( *( clock_t * ) luaL_checkudata( L, 1, "Lsyncd.jiffies" ) );
+ clock_t a2 = ( *( clock_t * ) luaL_checkudata( L, 2, "Lsyncd.jiffies" ) );
+
+ lua_pushboolean( L, ( a1 == a2 ) || time_before( a1, a2 ) );
return 1;
}
-/**
- * Registers the lsyncd lib
- */
+/*
+| Registers the Lsyncd's core library.
+*/
void
-register_lsyncd(lua_State *L)
+register_lsyncd( lua_State *L )
{
- luaL_register(L, "lsyncd", lsyncdlib);
- lua_setglobal(L, "lysncd");
+ luaL_register( L, LSYNCD_LIBNAME, lsyncdlib );
+ lua_setglobal( L, LSYNCD_LIBNAME );
- // creates the metatable for jiffies userdata
- luaL_newmetatable(L, "Lsyncd.jiffies");
- lua_pushstring(L, "__add");
- lua_pushcfunction(L, l_jiffies_add);
- lua_settable(L, -3);
-
- lua_pushstring(L, "__sub");
- lua_pushcfunction(L, l_jiffies_sub);
- lua_settable(L, -3);
-
- lua_pushstring(L, "__lt");
- lua_pushcfunction(L, l_jiffies_lt);
- lua_settable(L, -3);
-
- lua_pushstring(L, "__le");
- lua_pushcfunction(L, l_jiffies_le);
- lua_settable(L, -3);
-
- lua_pushstring(L, "__eq");
- lua_pushcfunction(L, l_jiffies_eq);
- lua_settable(L, -3);
- lua_pop(L, 1);
+ // creates the metatable for the jiffies ( timestamps ) userdata
+ luaL_newmetatable( L, "Lsyncd.jiffies" );
+ int mt = lua_gettop( L );
+
+ lua_pushcfunction( L, l_jiffies_add );
+ lua_setfield( L, mt, "__add" );
+
+ lua_pushcfunction( L, l_jiffies_sub );
+ lua_setfield( L, mt, "__sub" );
+
+ lua_pushcfunction( L, l_jiffies_lt );
+ lua_setfield( L, mt, "__lt" );
+
+ lua_pushcfunction( L, l_jiffies_le );
+ lua_setfield( L, mt, "__le" );
+
+ lua_pushcfunction( L, l_jiffies_eq );
+ lua_setfield( L, mt, "__eq" );
+
+ lua_pop( L, 1 ); // pop(mt)
- lua_getglobal(L, "lysncd");
#ifdef LSYNCD_WITH_INOTIFY
- // TODO why is the here?
- register_inotify(L);
- lua_settable(L, -3);
+
+ lua_getglobal( L, LSYNCD_LIBNAME );
+ register_inotify( L );
+ lua_setfield( L, -2, LSYNCD_INOTIFYLIBNAME );
+ lua_pop( L, 1 );
+
#endif
- lua_pop(L, 1);
- if (lua_gettop(L)) {
- logstring("Error", "internal, stack not empty in lsyncd_register()");
- exit(-1); // ERRNO
+
+ if( lua_gettop( L ) )
+ {
+ logstring(
+ "Error",
+ "internal, stack not empty in lsyncd_register( )"
+ );
+
+ exit( -1 );
}
}
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
+( Lsyncd Core )
+ *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-/*****************************************************************************
- * Lsyncd Core
-****************************************************************************/
-/**
- * Pushes a function from the runner on the stack.
- * Prior it pushed the callError handler.
- */
+/*
+| Pushes a function from the runner on the stack.
+| As well as the callError handler.
+*/
extern void
-load_runner_func(lua_State *L,
- const char *name)
+load_runner_func(
+ lua_State * L,
+ const char * name
+)
{
- printlogf(L, "Call", "%s()", name);
+ printlogf( L, "Call", "%s( )", name );
// pushes the error handler
- lua_pushlightuserdata(L, (void *) &callError);
- lua_gettable(L, LUA_REGISTRYINDEX);
+ lua_pushlightuserdata( L, (void *) &callError );
+ lua_gettable( L, LUA_REGISTRYINDEX );
// pushes the function
- lua_pushlightuserdata(L, (void *) &runner);
- lua_gettable(L, LUA_REGISTRYINDEX);
- lua_pushstring(L, name);
- lua_gettable(L, -2);
- lua_remove(L, -2);
+ lua_pushlightuserdata( L, (void *) &runner );
+ lua_gettable( L, LUA_REGISTRYINDEX );
+ lua_pushstring( L, name );
+ lua_gettable( L, -2 );
+ lua_remove( L, -2 );
}
-/**
- * Daemonizes.
- *
- * Lsyncds own implementation over daemon(0, 0) since
- * a) OSX keeps bugging about it being deprecated
- * b) for reason since blindly closing stdin/out/err is unsafe, since
- * they might not have existed and actually close the monitors fd!
- */
+/*
+| Daemonizes.
+|
+| Lsyncds own implementation over daemon(0, 0) since
+| a) OSX keeps bugging about it being deprecated
+| b) for a reason, since blindly closing stdin/out/err
+| is unsafe, since they might not have existed and
+| might actually close the monitors fd!
+*/
static void
-daemonize(lua_State *L)
+daemonize( lua_State *L )
{
pid_t pid, sid;
- pid = fork();
+ pid = fork( );
+
+ if( pid < 0 )
+ {
+ printlogf(
+ L, "Error",
+ "Failure in daemonize at fork: %s",
+ strerror( errno )
+ );
+
+ exit( -1 );
+ }
- if (pid < 0) {
- printlogf(L, "Error", "Failure in daemonize at fork: %s", strerror(errno));
- exit(-1); // ERRNO
+ if (pid > 0)
+ {
+ // parent process returns to shell
+ exit( 0 );
}
- if (pid > 0) exit(0); // return parent to shell
+ // detaches the new process from the parent process
+ sid = setsid( );
+ if( sid < 0 )
+ {
+ printlogf(
+ L, "Error",
+ "Failure in daemonize at setsid: %s",
+ strerror( errno )
+ );
- sid = setsid();
- if (sid < 0) {
- printlogf(L, "Error", "Failure in daemonize at setsid: %s", strerror(errno));
- exit(-1); // ERRNO
+ exit( -1 );
}
- // goto root dir
- if ((chdir("/")) < 0) {
- printlogf(L, "Error", "Failure in daemonize at chdir(\"/\"): %s", strerror(errno));
- exit(-1); // ERRNO
+ // goes to root dir
+ if( chdir( "/" ) < 0 )
+ {
+ printlogf(
+ L, "Error",
+ "Failure in daemonize at chdir( \"/\" ): %s",
+ strerror( errno )
+ );
+
+ exit( -1 );
}
- // does what clibs daemon(0, 0) cannot do,
- // checks if there were no stdstreams and it might close used fds!
- if (observances_len && observances->fd < 3) {
- printlogf(L, "Normal",
- "daemonize not closing stdin/out/err, since there seem to none.");
+ // does what clibs daemon( 0, 0 ) cannot do,
+ // checks if there were no stdstreams and it might close used fds
+ if( observances_len && observances->fd < 3 )
+ {
+ printlogf(
+ L, "Normal",
+ "daemonize not closing stdin/out/err, since there seem to none."
+ );
+
return;
}
// disconnects stdstreams
- if (!freopen("/dev/null", "r", stdin) ||
- !freopen("/dev/null", "w", stdout) ||
- !freopen("/dev/null", "w", stderr)
- ) {
- printlogf(L, "Error", "Failure in daemonize at freopen(/dev/null, std[in|out|err])");
+ if (
+ !freopen( "/dev/null", "r", stdin ) ||
+ !freopen( "/dev/null", "w", stdout ) ||
+ !freopen( "/dev/null", "w", stderr )
+ )
+ {
+ printlogf(
+ L, "Error",
+ "Failure in daemonize at freopen( /dev/null, std[in|out|err] )"
+ );
}
is_daemon = true;
}
-/**
- * Normal operation happens in here.
- */
+
+/*
+| Normal operation happens in here.
+*/
static void
masterloop(lua_State *L)
{
- while(true) {
+ while( true )
+ {
bool have_alarm;
bool force_alarm = false;
- clock_t now = times(dummy_tms);
+ clock_t now = times( dummy_tms );
clock_t alarm_time = 0;
// memory usage debugging
- // lua_gc(L, LUA_GCCOLLECT, 0);
- // printf("gccount: %d\n", lua_gc(L, LUA_GCCOUNT, 0) * 1024 + lua_gc(L, LUA_GCCOUNTB, 0));
-
- // queries runner about soonest alarm
- load_runner_func(L, "getAlarm");
- if (lua_pcall(L, 0, 1, -2)) exit(-1); // ERRNO
-
- if (lua_type(L, -1) == LUA_TBOOLEAN) {
- have_alarm = false;
- force_alarm = lua_toboolean(L, -1);
- } else {
+ // lua_gc( L, LUA_GCCOLLECT, 0 );
+ // printf(
+ // "gccount: %d\n",
+ // lua_gc( L, LUA_GCCOUNT, 0 ) * 1024 + lua_gc( L, LUA_GCCOUNTB, 0 ) );
+
+ //
+ // queries the runner about the soonest alarm
+ //
+ load_runner_func( L, "getAlarm" );
+ if( lua_pcall( L, 0, 1, -2 ) )
+ { exit( -1 ); }
+
+ if( lua_type( L, -1 ) == LUA_TBOOLEAN)
+ {
+ have_alarm = false;
+ force_alarm = lua_toboolean( L, -1 );
+ }
+ else
+ {
have_alarm = true;
- alarm_time = *((clock_t *) luaL_checkudata(L, -1, "Lsyncd.jiffies"));
+ alarm_time = *( ( clock_t * ) luaL_checkudata( L, -1, "Lsyncd.jiffies" ) );
}
- lua_pop(L, 2);
+ lua_pop( L, 2 );
- if (force_alarm || (have_alarm && time_before_eq(alarm_time, now))) {
+ if(
+ force_alarm ||
+ ( have_alarm && time_before_eq( alarm_time, now ) )
+ )
+ {
// 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 an observance
- // + an alarm on timeout
- // + the return of a child process
+ logstring( "Masterloop", "immediately handling delays." );
+ }
+ else
+ {
+ // uses select( ) to determine what happens next:
+ // a) a new event on an observance
+ // b) an alarm on timeout
+ // c) the return of a child process
struct timespec tv;
- if (have_alarm) {
+ if( have_alarm )
+ {
// TODO use trunc instead of long converstions
- double d = ((double)(alarm_time - now)) / clocks_per_sec;
+ double d = ( (double )( alarm_time - now ) ) / clocks_per_sec;
tv.tv_sec = d;
- tv.tv_nsec = ((d - (long) d)) * 1000000000.0;
- printlogf(L, "Masterloop",
- "going into select (timeout %f seconds)", d);
- } else {
- logstring("Masterloop", "going into select (no timeout).");
- }
- // time for Lsyncd to try to put itself to rest into a select(),
- // configures timeouts, filedescriptors and signals
- // that will wake it
+ tv.tv_nsec = ( (d - ( long ) d) ) * 1000000000.0;
+ printlogf(
+ L, "Masterloop",
+ "going into select ( timeout %f seconds )",
+ d
+ );
+ }
+ else
+ {
+ logstring(
+ "Masterloop",
+ "going into select ( no timeout )"
+ );
+ }
+
+ // time for Lsyncd to try to put itself to rest into the big select( )
+ // this configures:
+ // timeouts,
+ // filedescriptors and
+ // signals
+ // that will wake Lsyncd
{
fd_set rfds;
fd_set wfds;
sigset_t sigset;
int pi, pr;
- sigemptyset(&sigset);
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
+ sigemptyset( &sigset );
+ FD_ZERO( &rfds );
+ FD_ZERO( &wfds );
- for(pi = 0; pi < observances_len; pi++) {
+ for( pi = 0; pi < observances_len; pi++ )
+ {
struct observance *obs = observances + pi;
- if (obs->ready) FD_SET(obs->fd, &rfds);
- if (obs->writey) FD_SET(obs->fd, &wfds);
+ if ( obs->ready )
+ {
+ FD_SET( obs->fd, &rfds );
+ }
+
+ if ( obs->writey )
+ {
+ FD_SET( obs->fd, &wfds );
+ }
}
- if (!observances_len) {
- logstring("Error",
- "Internal fail, no observances, no monitor!");
- exit(-1);
+ if( !observances_len )
+ {
+ logstring(
+ "Error",
+ "Internal fail, no observances, no monitor!"
+ );
+
+ exit( -1 );
}
- // the great select, this is the very heart beat
+
+ // the great select, this is the very heart beat of Lsyncd
+ // that puts Lsyncd to sleep until anything worth noticing
+ // happens
+
pr = pselect(
- observances[observances_len - 1].fd + 1,
- &rfds, &wfds, NULL,
- have_alarm ? &tv : NULL, &sigset);
- if (pr >= 0) {
+ observances[ observances_len - 1 ].fd + 1,
+ &rfds,
+ &wfds,
+ NULL,
+ have_alarm ? &tv : NULL,
+ &sigset
+ );
+
+ // something happened!
+
+ if (pr >= 0)
+ {
// walks through the observances calling ready/writey
observance_action = true;
- for(pi = 0; pi < observances_len; pi++) {
+ for( pi = 0; pi < observances_len; pi++ )
+ {
struct observance *obs = observances + pi;
- if (hup || term) break;
- if (obs->ready && FD_ISSET(obs->fd, &rfds)) {
+ // Checks for signals
+ if( hup || term )
+ { break; }
+
+ // a file descriptor became read-ready
+ if( obs->ready && FD_ISSET( obs->fd, &rfds ) )
+ {
obs->ready(L, obs);
}
- if (hup || term) break;
-
- if (nonobservances_len > 0 &&
- nonobservances[nonobservances_len-1] == obs->fd) {
- // TODO breaks if more nonobserves
- // ready() nonobserved itself
- // --- what?
+ // Checks for signals, again, better safe than sorry
+ if (hup || term)
+ { break; }
+
+ // FIXME breaks on multiple nonobservances in one beat
+ if(
+ nonobservances_len > 0 &&
+ nonobservances[ nonobservances_len - 1 ] == obs->fd
+ )
+ {
continue;
}
- if (obs->writey && FD_ISSET(obs->fd, &wfds)) {
- obs->writey(L, obs);
+
+ // a file descriptor became write-ready
+ if( obs->writey && FD_ISSET( obs->fd, &wfds ) )
+ {
+ obs->writey( L, obs );
}
}
+
observance_action = false;
- // work through delayed nonobserve_fd() calls
- for (pi = 0; pi < nonobservances_len; pi++) {
+
+ // works through delayed nonobserve_fd() calls
+ for (pi = 0; pi < nonobservances_len; pi++)
+ {
nonobserve_fd(nonobservances[pi]);
}
+
nonobservances_len = 0;
}
}
}
// collects zombified child processes
- while(1) {
+ while( 1 )
+ {
int status;
- pid_t pid = waitpid(0, &status, WNOHANG);
- if (pid <= 0) break;
+ pid_t pid = waitpid( 0, &status, WNOHANG );
- load_runner_func(L, "collectProcess");
- lua_pushinteger(L, pid);
- lua_pushinteger(L, WEXITSTATUS(status));
- if (lua_pcall(L, 2, 0, -4)) {
- exit(-1); // ERRNO
+ if (pid <= 0)
+ {
+ // no more zombies
+ break;
}
- lua_pop(L, 1);
- }
- // reacts on HUP signal
- if (hup) {
- load_runner_func(L, "hup");
- if (lua_pcall(L, 0, 0, -2)) {
- exit(-1); // ERRNO
+ // calls the runner to handle the collection
+ load_runner_func( L, "collectProcess" );
+ lua_pushinteger( L, pid );
+ lua_pushinteger( L, WEXITSTATUS( status ) );
+
+ if ( lua_pcall( L, 2, 0, -4 ) )
+ { exit(-1); }
+
+ lua_pop( L, 1 );
+ }
+
+ // reacts on HUP signals
+ if( hup )
+ {
+ load_runner_func( L, "hup" );
+ if( lua_pcall( L, 0, 0, -2 ) )
+ {
+ exit( -1 );
}
- lua_pop(L, 1);
+ lua_pop( L, 1 );
hup = 0;
}
- // reacts on TERM signal
- if (term == 1) {
- load_runner_func(L, "term");
- if (lua_pcall(L, 0, 0, -2)) {
- exit(-1); // ERRNO
+ // reacts on TERM signals
+ if( term == 1 )
+ {
+ load_runner_func( L, "term" );
+ if( lua_pcall( L, 0, 0, -2 ) )
+ {
+ exit( -1 );
}
- lua_pop(L, 1);
+ lua_pop( L, 1 );
term = 2;
}
// lets the runner do stuff every cycle,
// like starting new processes, writing the statusfile etc.
- load_runner_func(L, "cycle");
- l_now(L);
- if (lua_pcall(L, 1, 1, -3)) exit(-1); // ERRNO
- if (!lua_toboolean(L, -1)) {
+ load_runner_func( L, "cycle" );
+ l_now( L );
+ if( lua_pcall( L, 1, 1, -3 ) )
+ { exit( -1 ); }
+
+ if( !lua_toboolean( L, -1 ) )
+ {
// cycle told core to break mainloop
- lua_pop(L, 2);
+ lua_pop( L, 2 );
return;
}
- lua_pop(L, 2);
+ lua_pop( L, 2 );
- if (lua_gettop(L)) {
- logstring("Error", "internal, stack is dirty.")
- l_stackdump(L);
- exit(-1); // ERRNO
+ if( lua_gettop( L ) )
+ {
+ logstring(
+ "Error",
+ "internal, stack is dirty."
+ );
+ l_stackdump( L );
+ exit( -1 );
}
}
}
-/**
- * The effective main for one run.
- * HUP signals may cause several runs of the one main.
- */
+/*
+| The effective main for one run.
+| HUP signals may cause several runs of the one main.
+*/
int
-main1(int argc, char *argv[])
+main1( int argc, char *argv[] )
{
// the Lua interpreter
- lua_State* L;
+ lua_State * L;
- // scripts
+ // the runner file
char * lsyncd_runner_file = NULL;
int argp = 1;
// load Lua
- L = lua_open();
- luaL_openlibs(L);
+ L = luaL_newstate( );
+ luaL_openlibs( L );
{
// checks the lua version
- const char *version;
+ const char * version;
int major, minor;
- lua_getglobal(L, "_VERSION");
- version = luaL_checkstring(L, -1);
- if (sscanf(version, "Lua %d.%d", &major, &minor) != 2) {
- fprintf(stderr, "cannot parse lua library version!\n");
- exit(-1); // ERRNO
- }
- if ((major < 5) || (major == 5 && minor < 1)) {
- fprintf(stderr, "lua library is too old. Need 5.1 at least");
- exit(-1); // ERRNO
+ lua_getglobal( L, "_VERSION" );
+ version = luaL_checkstring( L, -1 );
+
+ if(
+ sscanf(
+ version,
+ "Lua %d.%d",
+ &major, &minor
+ ) != 2
+ )
+ {
+ fprintf(
+ stderr,
+ "cannot parse lua library version!\n"
+ );
+ exit (-1 );
+ }
+
+ if(
+ major < 5 ||
+ (major == 5 && minor < 1)
+ ) {
+ fprintf(
+ stderr,
+ "Lua library is too old. Needs 5.1 at least"
+ );
+ exit( -1 );
}
- lua_pop(L, 1);
+
+ lua_pop( L, 1 );
}
{
- // prepares logging early
+ // logging is prepared quite early
int i = 1;
- add_logcat("Normal", LOG_NOTICE);
- add_logcat("Warn", LOG_WARNING);
- add_logcat("Error", LOG_ERR);
- while (i < argc) {
- if (strcmp(argv[i], "-log") && strcmp(argv[i], "--log")) {
- i++; continue;
+ add_logcat( "Normal", LOG_NOTICE );
+ add_logcat( "Warn", LOG_WARNING );
+ add_logcat( "Error", LOG_ERR );
+
+ while( i < argc )
+ {
+ if(
+ strcmp( argv[ i ], "-log" ) &&
+ strcmp( argv[ i ], "--log" )
+ )
+ {
+ // arg is neither -log or --log
+ i++;
+ continue;
}
- if (++i >= argc) break;
+ if( ++i >= argc )
+ {
+ // -(-)log was last argument
+ break;
+ }
- if (!add_logcat(argv[i], LOG_NOTICE)) {
- printlogf(L, "Error", "'%s' is not a valid logging category", argv[i]);
- exit(-1); // ERRNO
+ if( !add_logcat( argv[ i ], LOG_NOTICE ) )
+ {
+ printlogf(
+ L, "Error",
+ "'%s' is not a valid logging category",
+ argv[ i ]
+ );
+ exit( -1 );
}
}
}
- // registers lsycnd core
- register_lsyncd(L);
+ // registers Lsycnd's core library
+ register_lsyncd( L );
- if (check_logcat("Debug") <= settings.log_level) {
+
+ if( check_logcat( "Debug" ) <= settings.log_level )
+ {
// printlogf doesnt support %ld :-(
- printf("kernels clocks_per_sec=%ld\n", clocks_per_sec);
+ printf(
+ "kernels clocks_per_sec=%ld\n",
+ clocks_per_sec
+ );
}
- // checks if the user overrode default runner file
- if (argp < argc && !strcmp(argv[argp], "--runner")) {
- if (argp + 1 >= argc) {
- logstring("Error", "Lsyncd Lua-runner file missing after --runner.");
- logstring("Error", "Using a statically included runner as default.");
- exit(-1); //ERRNO
+ // checks if the user overrode the default runner file
+ if(
+ argp < argc &&
+ !strcmp( argv[ argp ], "--runner" )
+ )
+ {
+ if (argp + 1 >= argc)
+ {
+ logstring(
+ "Error",
+ "Lsyncd Lua-runner file missing after --runner "
+ );
+
+ exit( -1 );
}
- lsyncd_runner_file = argv[argp + 1];
+
+ lsyncd_runner_file = argv[ argp + 1 ];
argp += 2;
}
- if (lsyncd_runner_file) {
+ if( lsyncd_runner_file )
+ {
// checks if the runner file exists
struct stat st;
- if (stat(lsyncd_runner_file, &st)) {
- printlogf(L, "Error", "Cannot find Lsyncd Lua-runner at '%s'.", lsyncd_runner_file);
- printlogf(L, "Error", "Maybe specify another place?");
- printlogf(L, "Error", "%s --runner RUNNER_FILE CONFIG_FILE", argv[0]);
- exit(-1); // ERRNO
+
+ if( stat( lsyncd_runner_file, &st ) )
+ {
+ printlogf(
+ L, "Error",
+ "Cannot see a runner at '%s'.",
+ lsyncd_runner_file
+ );
+ exit( -1 );
}
// loads the runner file
- if (luaL_loadfile(L, lsyncd_runner_file)) {
- printlogf(L, "Error",
- "error loading '%s': %s", lsyncd_runner_file, lua_tostring(L, -1));
- exit(-1); // ERRNO
+ if( luaL_loadfile(L, lsyncd_runner_file ) )
+ {
+ printlogf(
+ L, "Error",
+ "error loading '%s': %s",
+ lsyncd_runner_file,
+ lua_tostring( L, -1 )
+ );
+
+ exit( -1 );
}
- } else {
+
+ }
+ else
+ {
// loads the runner from binary
- if (luaL_loadbuffer(L, runner_out, runner_size, "runner")) {
- printlogf(L, "Error", "loading precompiled runner: %s", lua_tostring(L, -1));
- exit(-1); // ERRNO
+ if( luaL_loadbuffer( L, runner_out, runner_size, "runner" ) )
+ {
+ printlogf(
+ L, "Error",
+ "error loading precompiled runner: %s",
+ lua_tostring( L, -1 )
+ );
+
+ exit( -1 );
}
}
+ // prepares the runner executing the script
{
- // place to store the lua runners functions
- // executes the runner defining all its functions
- if (lua_pcall(L, 0, LUA_MULTRET, 0)) {
- printlogf(L, "Error", "preparing runner: %s", lua_tostring(L, -1));
- exit(-1); // ERRNO
+ if( lua_pcall( L, 0, LUA_MULTRET, 0 ) )
+ {
+ printlogf(
+ L, "Error",
+ "preparing runner: %s",
+ lua_tostring( L, -1 )
+ );
+
+ exit( -1 );
}
- lua_pushlightuserdata(L, (void *)&runner);
- // switches the value (result of preparing) and the key &runner
- lua_insert(L, 1);
+
+ lua_pushlightuserdata( L, (void *) & runner );
+
+ // switches the value ( result of preparing ) and the key &runner
+ lua_insert( L, 1 );
+
// saves the table of the runners functions in the lua registry
- lua_settable(L, LUA_REGISTRYINDEX);
+ lua_settable( L, LUA_REGISTRYINDEX );
+
+ // saves the error function extras
+
+ // &callError is the key
+ lua_pushlightuserdata ( L, (void *) &callError );
+
+ // &runner[ callError ] the value
+ lua_pushlightuserdata ( L, (void *) &runner );
+ lua_gettable ( L, LUA_REGISTRYINDEX );
+ lua_pushstring ( L, "callError" );
+ lua_gettable ( L, -2 );
+ lua_remove ( L, -2 );
- // saves the error function extra
- lua_pushlightuserdata(L, (void *) &callError); // &callError is the key
- lua_pushlightuserdata(L, (void *) &runner); // &runner[callError] the value
- lua_gettable(L, LUA_REGISTRYINDEX);
- lua_pushstring(L, "callError");
- lua_gettable(L, -2);
- lua_remove(L, -2);
- lua_settable(L, LUA_REGISTRYINDEX);
+ lua_settable ( L, LUA_REGISTRYINDEX );
}
+ // asserts the Lsyncd's version matches
+ // between runner and core
{
- // asserts version match between runner and core
const char *lversion;
- lua_getglobal(L, "lsyncd_version");
- lversion = luaL_checkstring(L, -1);
- if (strcmp(lversion, PACKAGE_VERSION)) {
- printlogf(L, "Error",
+
+ lua_getglobal( L, "lsyncd_version" );
+ lversion = luaL_checkstring( L, -1 );
+
+ if( strcmp( lversion, PACKAGE_VERSION ) )
+ {
+ printlogf(
+ L, "Error",
"Version mismatch '%s' is '%s', but core is '%s'",
- lsyncd_runner_file ? lsyncd_runner_file : "internal runner",
- lversion, PACKAGE_VERSION);
- exit(-1); // ERRNO
+ lsyncd_runner_file ? lsyncd_runner_file : "( internal runner )",
+ lversion, PACKAGE_VERSION
+ );
+
+ exit( -1 );
}
- lua_pop(L, 1);
+
+ lua_pop( L, 1 );
}
+ // loads the defaults from binary
{
- // loads the defaults from binary
- if (luaL_loadbuffer(L, defaults_out, defaults_size, "defaults")) {
- printlogf(L, "Error", "loading defaults: %s", lua_tostring(L, -1));
- exit(-1); // ERRNO
+ if( luaL_loadbuffer( L, defaults_out, defaults_size, "defaults" ) )
+ {
+ printlogf(
+ L, "Error",
+ "loading defaults: %s",
+ lua_tostring( L, -1 )
+ );
+
+ exit( -1 );
}
// prepares the defaults
- if (lua_pcall(L, 0, 0, 0)) {
- printlogf(L, "Error", "preparing defaults: %s", lua_tostring(L, -1));
- exit(-1); // ERRNO
+ if (lua_pcall( L, 0, 0, 0 ) )
+ {
+ printlogf(
+ L, "Error",
+ "preparing defaults: %s",
+ lua_tostring( L, -1 )
+ );
+ exit( -1 );
}
}
+ // checks if there is a "-help" or "--help"
{
- // checks if there is a "-help" or "--help"
int i;
- for(i = argp; i < argc; i++) {
- if (!strcmp(argv[i],"-help") || !strcmp(argv[i],"--help")) {
+ for( i = argp; i < argc; i++ )
+ {
+ if (
+ !strcmp( argv[ i ], "-help" ) ||
+ !strcmp( argv[ i ], "--help" )
+ )
+ {
load_runner_func(L, "help");
- if (lua_pcall(L, 0, 0, -2)) {
- exit(-1); // ERRNO
- }
- lua_pop(L, 1);
- exit(-1); // ERRNO
+
+ if (lua_pcall(L, 0, 0, -2))
+ { exit( -1 ); }
+
+ lua_pop( L, 1 );
+ exit( 0 );
}
}
}
+ // starts the option parser in Lua script
{
- // starts the option parser in lua script
int idx = 1;
const char *s;
+
// creates a table with all remaining argv option arguments
- load_runner_func(L, "configure");
- lua_newtable(L);
- while(argp < argc) {
- lua_pushnumber(L, idx++);
- lua_pushstring(L, argv[argp++]);
- lua_settable(L, -3);
+ load_runner_func( L, "configure" );
+ lua_newtable( L );
+
+ while( argp < argc )
+ {
+ lua_pushnumber ( L, idx++ );
+ lua_pushstring ( L, argv[ argp++ ] );
+ lua_settable ( L, -3 );
}
+
// creates a table with the cores event monitor interfaces
idx = 0;
- lua_newtable(L);
- while (monitors[idx]) {
- lua_pushnumber(L, idx + 1);
- lua_pushstring(L, monitors[idx++]);
- lua_settable(L, -3);
- }
- if (lua_pcall(L, 2, 1, -3)) {
- exit(-1); // ERRNO
+ lua_newtable( L );
+
+ while( monitors[ idx ] )
+ {
+ lua_pushnumber ( L, idx + 1 );
+ lua_pushstring ( L, monitors[ idx++ ] );
+ lua_settable ( L, -3 );
}
- if (first_time) {
+
+ if( lua_pcall( L, 2, 1, -4 ) )
+ { exit( -1 ); }
+
+ if( first_time )
+ {
// If not first time, simply retains the config file given
s = lua_tostring(L, -1);
- if (s) lsyncd_config_file = s_strdup(s);
+ if( s )
+ {
+ lsyncd_config_file = s_strdup( s );
+ }
}
- lua_pop(L, 2);
+ lua_pop( L, 2 );
}
// checks existence of the config file
- if (lsyncd_config_file) {
+ if( lsyncd_config_file )
+ {
struct stat st;
// gets the absolute path to the config file
// so in case of HUPing the daemon, it finds it again
- char * apath = get_realpath(lsyncd_config_file);
- if (!apath) {
- printlogf(L, "Error", "Cannot find config file at '%s'.", lsyncd_config_file);
- exit(-1); // ERRNO
+ char * apath = get_realpath( lsyncd_config_file );
+ if( !apath )
+ {
+ printlogf(
+ L, "Error",
+ "Cannot find config file at '%s'.",
+ lsyncd_config_file
+ );
+
+ exit( -1 );
}
- free(lsyncd_config_file);
+
+ free( lsyncd_config_file );
lsyncd_config_file = apath;
- if (stat(lsyncd_config_file, &st)) {
- printlogf(L, "Error", "Cannot find config file at '%s'.", lsyncd_config_file);
- exit(-1); // ERRNO
+ if( stat( lsyncd_config_file, &st ) )
+ {
+ printlogf(
+ L, "Error",
+ "Cannot find config file at '%s'.",
+ lsyncd_config_file
+ );
+
+ exit( -1 );
}
// loads and executes the config file
- if (luaL_loadfile(L, lsyncd_config_file)) {
- printlogf(L, "Error",
- "error loading %s: %s", lsyncd_config_file, lua_tostring(L, -1));
- exit(-1); // ERRNO
- }
+ if( luaL_loadfile( L, lsyncd_config_file ) )
+ {
+ printlogf(
+ L, "Error",
+ "error loading %s: %s",
+ lsyncd_config_file,
+ lua_tostring( L, -1 )
+ );
+
+ exit( -1 );
+ }
+
+ if( lua_pcall( L, 0, LUA_MULTRET, 0) )
+ {
+ printlogf(
+ L, "Error",
+ "error preparing %s: %s",
+ lsyncd_config_file,
+ lua_tostring( L, -1 )
+ );
- if (lua_pcall(L, 0, LUA_MULTRET, 0)) {
- printlogf(L, "Error",
- "error preparing %s: %s", lsyncd_config_file, lua_tostring(L, -1));
- exit(-1); // ERRNO
+ exit( -1 );
}
}
#ifdef LSYNCD_WITH_INOTIFY
- open_inotify(L);
+
+ open_inotify( L );
+
#endif
+
#ifdef LSYNCD_WITH_FSEVENTS
- open_fsevents(L);
+
+ open_fsevents( L );
+
#endif
+ // adds signal handlers
+ // listens to SIGCHLD, but blocks it until pselect( )
+ // opens the signal handler up
{
- /* adds signal handlers *
- * listens to SIGCHLD, but blocks it until pselect()
- * opens up*/
sigset_t set;
- sigemptyset(&set);
- sigaddset(&set, SIGCHLD);
- signal(SIGCHLD, sig_child);
- sigprocmask(SIG_BLOCK, &set, NULL);
+ sigemptyset( &set );
+ sigaddset( &set, SIGCHLD );
+ signal( SIGCHLD, sig_child );
+ sigprocmask( SIG_BLOCK, &set, NULL );
- signal(SIGHUP, sig_handler);
- signal(SIGTERM, sig_handler);
+ signal( SIGHUP, sig_handler );
+ signal( SIGTERM, sig_handler );
}
+ // runs initializations from runner
+ // it will set the configuration and add watches
{
- /* runs initialitions from runner
- * lua code will set configuration and add watches */
- load_runner_func(L, "initialize");
- lua_pushboolean(L, first_time);
- if (lua_pcall(L, 1, 0, -3)) exit(-1); // ERRNO
- lua_pop(L, 1);
+ load_runner_func( L, "initialize" );
+ lua_pushboolean( L, first_time );
+
+ if( lua_pcall( L, 1, 0, -3 ) )
+ { exit( -1 ); }
+
+ lua_pop( L, 1 );
}
- masterloop(L);
+ //
+ // enters the master loop
+ //
+ masterloop( L );
+ //
// cleanup
+ //
+
+ // tidies up all observances
{
- // tidies up all observances
int i;
- for(i = 0; i < observances_len; i++) {
+ for( i = 0; i < observances_len; i++ )
+ {
struct observance *obs = observances + i;
- obs->tidy(obs);
+ obs->tidy( obs );
}
- observances_len = 0;
+
+ observances_len = 0;
nonobservances_len = 0;
}
+ // frees logging categories
{
- // frees logging categories
int ci;
struct logcat *lc;
- for(ci = 'A'; ci <= 'Z'; ci++) {
- for(lc = logcats[ci - 'A']; lc && lc->name; lc++) {
- free(lc->name);
+ for( ci = 'A'; ci <= 'Z'; ci++ )
+ {
+ for( lc = logcats[ ci - 'A' ]; lc && lc->name; lc++)
+ {
+ free( lc->name );
lc->name = NULL;
}
- if (logcats[ci - 'A']) {
- free(logcats[ci - 'A']);
- logcats[ci - 'A'] = NULL;
+
+ if( logcats[ci - 'A' ] )
+ {
+ free( logcats[ ci - 'A' ] );
+ logcats[ ci - 'A' ] = NULL;
}
}
}
- lua_close(L);
+ lua_close( L );
return 0;
}
-/**
- * Main
- */
+/*
+| Main
+*/
int
-main(int argc, char *argv[])
+main( int argc, char * argv[ ] )
{
// gets a kernel parameter
- clocks_per_sec = sysconf(_SC_CLK_TCK);
+ clocks_per_sec = sysconf( _SC_CLK_TCK );
- while(!term) main1(argc, argv);
- return 0;
+ while( !term ) {
+ main1( argc, argv );
+ }
+
+ // exits with 143 since it got a kill signal
+ return 143;
}
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/lsyncd.h
^
|
@@ -16,6 +16,8 @@
#define _XOPEN_SOURCE 700
#define _DARWIN_C_SOURCE 1
+#define LUA_COMPAT_ALL
+
// includes needed for headerfile
#include "config.h"
@@ -26,6 +28,9 @@
#define LUA_USE_APICHECK 1
#include <lua.h>
+#define LSYNCD_LIBNAME "lsyncd"
+#define LSYNCD_INOTIFYLIBNAME "inotify"
+
/**
* Lsyncd runtime configuration
*/
|
[-]
[+]
|
Changed |
lsyncd-2.1.4.tar.bz2/lsyncd.lua
^
|
@@ -5,6 +5,8 @@
-- It works closely together with the Lsyncd core in lsyncd.c. This means it
-- cannot be runned directly from the standard lua interpreter.
--
+-- This code assumes your editor is at least 100 chars wide.
+--
-- License: GPLv2 (see COPYING) or any later version
-- Authors: Axel Kittenberger <axkibe@gmail.com>
--
@@ -13,469 +15,673 @@
-- require('profiler')
-- profiler.start()
------
+--
-- A security measurement.
--- Core will exit if version ids mismatch.
+-- The core will exit if version ids mismatch.
--
if lsyncd_version then
- -- checks if the runner is being loaded twice
- lsyncd.log('Error', 'You cannot use the lsyncd runner as configuration file!')
- lsyncd.terminate(-1) -- ERRNO
+
+ -- ensures the runner is not being loaded twice
+ lsyncd.log(
+ 'Error',
+ 'You cannot use the lsyncd runner as configuration file!'
+ )
+
+ lsyncd.terminate( -1 )
end
-lsyncd_version = '2.0.7'
------
--- Hides the core interface from user scripts
+lsyncd_version = '2.1.4'
+
+--
+-- Hides the core interface from user scripts.
--
local _l = lsyncd
lsyncd = nil
local lsyncd = _l
_l = nil
------
+--
-- Shortcuts (which user is supposed to be able to use them as well)
--
log = lsyncd.log
terminate = lsyncd.terminate
now = lsyncd.now
readdir = lsyncd.readdir
--- just to safe from userscripts changing this.
+
+--
+-- Coping globals to ensure userscripts don't change this.
+--
local log = log
local terminate = terminate
local now = now
-------
+--
-- Predeclarations
--
local Monitors
------
+--
-- Global: total number of processess running
+--
local processCount = 0
+--
+-- Settings specified by command line.
+--
+local clSettings = { }
+
+--
+-- Settings specified by config scripts.
+--
+local uSettings = { }
+
+--
+-- A copy of the settings function to see if the
+-- user script replaced the settings() by a table
+-- ( pre Lsyncd 2.1 style )
+--
+local settingsSafe
+
--============================================================================
-- Lsyncd Prototypes
--============================================================================
------
--- The array objects are tables that error if accessed with a non-number.
--
-local Array = (function()
+-- Array tables error if accessed with a non-number.
+--
+local Array = ( function( )
+
-- Metatable
- local mt = {}
+ local mt = { }
-- on accessing a nil index.
- mt.__index = function(t, k)
+ mt.__index = function( t, k )
if type(k) ~= 'number' then
- error('Key "'..k..'" invalid for Array', 2)
+ error( 'Key "'..k..'" invalid for Array', 2 )
end
- return rawget(t, k)
+ return rawget( t, k )
end
-- on assigning a new index.
- mt.__newindex = function(t, k, v)
- if type(k) ~= 'number' then
- error('Key "'..k..'" invalid for Array', 2)
+ mt.__newindex = function( t, k, v )
+ if type( k ) ~= 'number' then
+ error( 'Key "'..k..'" invalid for Array', 2 )
end
- rawset(t, k, v)
+ rawset( t, k, v )
end
-- creates a new object
- local function new()
- local o = {}
- setmetatable(o, mt)
+ local function new( )
+ local o = { }
+ setmetatable( o, mt )
return o
end
- -- objects public interface
- return {new = new}
-end)()
+ --
+ -- Public interface
+ --
+ return { new = new }
+
+end )( )
------
--- The count array objects are tables that error if accessed with a non-number.
--- Additionally they maintain their length as 'size' attribute.
--- Lua's # operator does not work on tables which key values are not
+--
+-- Count array tables error if accessed with a non-number.
+--
+-- Additionally they maintain their length as 'size' attribute,
+-- since Lua's # operator does not work on tables whose key values are not
-- strictly linear.
--
-local CountArray = (function()
+local CountArray = ( function( )
+
+ --
-- Metatable
- local mt = {}
+ --
+ local mt = { }
- -----
- -- key to native table
- local k_nt = {}
+ --
+ -- Key to native table
+ --
+ local k_nt = { }
- -----
- -- on accessing a nil index.
- mt.__index = function(t, k)
- if type(k) ~= 'number' then
- error('Key "'..k..'" invalid for CountArray', 2)
+ --
+ -- On accessing a nil index.
+ --
+ mt.__index = function( t, k )
+ if type( k ) ~= 'number' then
+ error( 'Key "'..k..'" invalid for CountArray', 2 )
end
- return t[k_nt][k]
+ return t[ k_nt ][ k ]
end
- -----
- -- on assigning a new index.
- mt.__newindex = function(t, k, v)
+ --
+ -- On assigning a new index.
+ --
+ mt.__newindex = function( t, k, v )
+
if type(k) ~= 'number' then
- error('Key "'..k..'" invalid for CountArray', 2)
+ error( 'Key "'..k..'" invalid for CountArray', 2 )
end
+
-- value before
- local vb = t[k_nt][k]
+ local vb = t[ k_nt ][ k ]
if v and not vb then
t._size = t._size + 1
elseif not v and vb then
t._size = t._size - 1
end
- t[k_nt][k] = v
+ t[ k_nt ][ k ] = v
end
- -----
+ --
-- Walks through all entries in any order.
--
- local function walk(self)
- return pairs(self[k_nt])
+ local function walk( self )
+ return pairs( self[ k_nt ] )
end
- -----
- -- returns the count
--
- local function size(self)
+ -- Returns the count
+ --
+ local function size( self )
return self._size
end
- -----
- -- creates a new count array
--
- local function new()
+ -- Creates a new count array
+ --
+ local function new( )
+
-- k_nt is native table, private for this object.
- local o = {_size = 0, walk = walk, size = size, [k_nt] = {} }
+ local o = {
+ _size = 0,
+ walk = walk,
+ size = size,
+ [k_nt] = { }
+ }
+
setmetatable(o, mt)
return o
end
- -----
- -- public interface
+
--
- return {new = new}
-end)()
+ -- Public interface
+ --
+ return { new = new }
+end )( )
------
--- Queue
--- optimized for pushing on the right and poping on the left.
--
+-- A queue is optimized for pushing on the right and poping on the left.
--
-Queue = (function()
- -----
+Queue = ( function( )
+
+ --
-- Creates a new queue.
--
- local function new()
- return { first = 1, last = 0, size = 0};
+ local function new( )
+ return {
+ first = 1,
+ last = 0,
+ size = 0
+ };
end
- -----
+ --
-- Pushes a value on the queue.
-- Returns the last value
--
- local function push(list, value)
+ local function push( list, value )
+
if not value then
error('Queue pushing nil value', 2)
end
+
local last = list.last + 1
list.last = last
- list[last] = value
+ list[ last ] = value
list.size = list.size + 1
return last
end
- -----
- -- Removes item at pos from Queue.
--
- local function remove(list, pos)
- if list[pos] == nil then
+ -- Removes an item at pos from the Queue.
+ --
+ local function remove( list, pos )
+
+ if list[ pos ] == nil then
error('Removing nonexisting item in Queue', 2)
end
- list[pos] = nil
- -- if removing first element, move list on.
+ list[ pos ] = nil
+
+ -- if removing first or last element,
+ -- the queue limits are adjusted.
if pos == list.first then
+
local last = list.last
- while list[pos] == nil and pos <= list.last do
+
+ while list[ pos ] == nil and pos <= list.last do
pos = pos + 1
end
+
list.first = pos
+
elseif pos == list.last then
- while list[pos] == nil and pos >= list.first do
+
+ while list[ pos ] == nil and pos >= list.first do
pos = pos - 1
end
+
list.last = pos
+
end
- -- reset indizies if list is empty
+ -- reset the indizies if the queue is empty
if list.last < list.first then
list.first = 1
list.last = 0
end
+
list.size = list.size - 1
end
- -----
+ --
-- Queue iterator (stateless)
--
- local function iter(list, pos)
+ local function iter( list, pos )
+
pos = pos + 1
- while list[pos] == nil and pos <= list.last do
+
+ while list[ pos ] == nil and pos <= list.last do
pos = pos + 1
end
+
if pos > list.last then
return nil
end
- return pos, list[pos]
+
+ return pos, list[ pos ]
end
- -----
- -- Reverse queue iterator. (stateless)
--
- local function iterReverse(list, pos)
+ -- Reverse queue iterator (stateless)
+ --
+ local function iterReverse( list, pos )
+
pos = pos - 1
+
while list[pos] == nil and pos >= list.first do
pos = pos - 1
end
+
if pos < list.first then
return nil
end
- return pos, list[pos]
+
+ return pos, list[ pos ]
end
- -----
+ --
-- Iteraters through the queue
- -- returning all non-nil pos-value entries
+ -- returning all non-nil pos-value entries.
--
- local function qpairs(list)
+ local function qpairs( list )
return iter, list, list.first - 1
end
- -----
+ --
-- Iteraters backwards through the queue
- -- returning all non-nil pos-value entries
+ -- returning all non-nil pos-value entries.
--
- local function qpairsReverse(list)
+ local function qpairsReverse( list )
return iterReverse, list, list.last + 1
end
- return {new = new,
- push = push,
- remove = remove,
- qpairs = qpairs,
- qpairsReverse = qpairsReverse}
-end)()
+ return {
+ new = new,
+ push = push,
+ remove = remove,
+ qpairs = qpairs,
+ qpairsReverse = qpairsReverse
+ }
+end )( )
------
+--
-- Locks globals,
--- no more globals can be created
+-- No more globals can be created after this
--
-local function lockGlobals()
+local function lockGlobals( )
+
local t = _G
- local mt = getmetatable(t) or {}
- mt.__index = function(t, k)
- if (k~='_' and string.sub(k, 1, 2) ~= '__') then
- error('Access of non-existing global "'..k..'"', 2)
+ local mt = getmetatable( t ) or { }
+
+ -- TODO try to remove the underscore exceptions
+ mt.__index = function( t, k )
+ if k ~= '_' and string.sub(k, 1, 2) ~= '__' then
+ error( 'Access of non-existing global "'..k..'"', 2 )
else
- rawget(t, k)
+ rawget( t, k )
end
end
- mt.__newindex = function(t, k, v)
- if (k~='_' and string.sub(k, 1, 2) ~= '__') then
+
+ mt.__newindex = function( t, k, v )
+ if k ~= '_' and string.sub( k, 1, 2 ) ~= '__' then
error('Lsyncd does not allow GLOBALS to be created on the fly. '..
'Declare "'..k..'" local or declare global on load.', 2)
else
- rawset(t, k, v)
+ rawset( t, k, v )
end
end
- setmetatable(t, mt)
+
+ setmetatable( t, mt )
end
------
--- Holds information about a delayed event of one Sync.
--
-local Delay = (function()
- -----
+-- Holds the information about a delayed event for one Sync.
+--
+local Delay = ( function( )
+
+ --
-- Creates a new delay.
--
- -- @params see below
+ -- Params see below.
--
- local function new(etype, sync, alarm, path, path2)
+ local function new( etype, sync, alarm, path, path2 )
+
local o = {
- -----
+ --
-- Type of event.
-- Can be 'Create', 'Modify', 'Attrib', 'Delete' and 'Move'
+ --
etype = etype,
- ------
- -- Sync this delay belongs to
+ --
+ -- the Sync this delay belongs to
+ --
sync = sync,
- -----
+ --
-- Latest point in time this should be catered for.
-- This value is in kernel ticks, return of the C's
-- times(NULL) call.
alarm = alarm,
- -----
- -- path and filename or dirname of the delay relative
+ --
+ -- Path and filename or dirname of the delay relative
-- to the syncs root.
+ --
-- for the directories it contains a trailing slash
--
- path = path,
+ path = path,
- ------
- -- only not nil for 'Move's.
- -- path and file/dirname of a move destination.
+ --
+ -- Used only for Moves.
+ -- Path and file/dirname of a move destination.
+ --
path2 = path2,
- ------
+ --
-- Status of the event. Valid stati are:
+ --
-- 'wait' ... the event is ready to be handled.
+ --
-- 'active' ... there is process running catering for this event.
+ --
-- 'blocked' ... this event waits for another to be handled first.
+ --
-- 'done' ... event has been collected. This should never be
-- visible as all references should be droped on
- -- collection, nevertheless seperat status for
- -- insurrance.
+ -- collection, nevertheless the seperate status is
+ -- used as insurrance everything is running correctly.
status = 'wait',
- -----
+ --
-- Position in the queue
+ --
dpos = -1,
}
+
return o
end
- -- public interface
- return {new = new}
-end)()
------
--- combines delays
+ --
+ -- Public interface
+ --
+ return { new = new }
+
+end )( )
+
--
-local Combiner = (function()
+-- Combines delays
+--
+local Combiner = ( function( )
- ----
- -- new delay absorbed by old
--
- local function abso(d1, d2)
- log('Delay',d2.etype,':',d2.path,' absorbed by ',d1.etype,':',d1.path)
+ -- The new delay is absorbed by an older one.
+ --
+ local function abso( d1, d2 )
+
+ log(
+ 'Delay',
+ d2.etype, ':',d2.path,
+ ' absorbed by ',
+ d1.etype,':',d1.path
+ )
+
return 'absorb'
+
end
- ----
- -- new delay replaces the old one if it is a file
--
- local function refi(d1, d2)
- if d2.path:byte(-1) == 47 then
- log('Delay',d2.etype,':',d2.path,' blocked by ',d1.etype,':',d1.path)
+ -- The new delay replaces the old one if it's a file
+ --
+ local function refi( d1, d2 )
+
+ -- but a directory blocks
+ if d2.path:byte( -1 ) == 47 then
+
+ log(
+ 'Delay',
+ d2.etype,':',d2.path,
+ ' blocked by ',
+ d1.etype,':',d1.path
+ )
+
return 'stack'
+
end
- log('Delay',d2.etype,':',d2.path,' replaces ',d1.etype,':',d1.path)
+
+ log(
+ 'Delay',
+ d2.etype, ':', d2.path,
+ ' replaces ',
+ d1.etype, ':', d1.path
+ )
+
return 'replace'
+
end
- ----
- -- new delay replaces the old one
--
- local function repl(d1, d2)
- log('Delay',d2.etype,':',d2.path,' replaces ',d1.etype,':',d1.path)
+ -- The new delay replaces an older one.
+ --
+ local function repl( d1, d2 )
+
+ log(
+ 'Delay',
+ d2.etype, ':', d2.path,
+ ' replaces ',
+ d1.etype, ':', d1.path
+ )
+
return 'replace'
+
end
- ----
- -- delays nullificate each other
--
- local function null(d1, d2)
- log('Delay',d2.etype,':',d2.path,' nullifies ',d1.etype,':',d1.path)
+ -- Two delays nullificate each other.
+ --
+ local function null( d1, d2 )
+
+ log(
+ 'Delay',
+ d2.etype,':',d2.path,
+ ' nullifies ',
+ d1.etype,':',d1.path
+ )
+
return 'remove'
+
end
- -----
- -- Table how to combine events that dont involve a move.
+ --
+ -- Table on how to combine events that dont involve a move.
--
local combineNoMove = {
- Attrib = {Attrib=abso, Modify=repl, Create=repl, Delete=repl },
- Modify = {Attrib=abso, Modify=abso, Create=repl, Delete=repl },
- Create = {Attrib=abso, Modify=abso, Create=abso, Delete=repl },
- Delete = {Attrib=abso, Modify=abso, Create=refi, Delete=abso },
+
+ Attrib = {
+ Attrib = abso,
+ Modify = repl,
+ Create = repl,
+ Delete = repl
+ },
+
+ Modify = {
+ Attrib = abso,
+ Modify = abso,
+ Create = repl,
+ Delete = repl
+ },
+
+ Create = {
+ Attrib = abso,
+ Modify = abso,
+ Create = abso,
+ Delete = repl
+ },
+
+ Delete = {
+ Attrib = abso,
+ Modify = abso,
+ Create = refi,
+ Delete = abso
+ },
}
- ------
- -- combines two delays
--
- local function combine(d1, d2)
+ -- Combines two delays
+ --
+ local function combine( d1, d2 )
+
if d1.etype == 'Init' or d1.etype == 'Blanket' then
+
-- everything is blocked by init or blanket delays.
if d2.path2 then
- log('Delay',d2.etype,':',d2.path,'->',d2.path2,'blocked by',d1.etype,' event')
+ log(
+ 'Delay',
+ d2.etype,':',d2.path,'->',d2.path2,
+ ' blocked by ',
+ d1.etype,' event'
+ )
else
- log('Delay',d2.etype,':',d2.path,'blocked by',d1.etype,' event')
+ log(
+ 'Delay',
+ d2.etype,':',d2.path,
+ ' blocked by ',
+ d1.etype,' event'
+ )
end
+
return 'stack'
end
- -- Two normal events
+ -- two normal events
if d1.etype ~= 'Move' and d2.etype ~= 'Move' then
+
if d1.path == d2.path then
if d1.status == 'active' then
return 'stack'
end
- return combineNoMove[d1.etype][d2.etype](d1, d2)
+
+ return combineNoMove[ d1.etype ][ d2.etype ]( d1, d2 )
end
- -- blocks events if one is a parent directory of another
+ -- if one is a parent directory of another, events are blocking
if d1.path:byte(-1) == 47 and string.starts(d2.path, d1.path) or
d2.path:byte(-1) == 47 and string.starts(d1.path, d2.path)
then
return 'stack'
end
+
return nil
+
end
- -- Normal upon a Move
+ -- non-move event on a move.
if d1.etype == 'Move' and d2.etype ~= 'Move' then
- -- stacks the move if the from field could anyway be damaged
+ -- if the from field could be damaged the events are stacked
if d1.path == d2.path or
d2.path:byte(-1) == 47 and string.starts(d1.path, d2.path) or
d1.path:byte(-1) == 47 and string.starts(d2.path, d1.path)
then
- log('Delay',d2.etype,':',d2.path,' blocked by','Move :',d1.path,'->',d1.path2)
+ log(
+ 'Delay',
+ d2.etype, ':', d2.path,
+ ' blocked by ',
+ 'Move :', d1.path,'->', d1.path2
+ )
+
return 'stack'
end
- -- Event does something with the move destination
+ -- the event does something with the move destination
+
if d1.path2 == d2.path then
+
if d2.etype == 'Delete' or d2.etype == 'Create' then
+
if d1.status == 'active' then
return 'stack'
end
- log('Delay',d2.etype,':',d2.path,' turns ',
- 'Move :',d1.path,'->',d1.path2,' into ','Delete:',d1.path)
+
+ log(
+ 'Delay',
+ d2.etype, ':', d2.path,
+ ' turns ',
+ 'Move :', d1.path, '->', d1.path2,
+ ' into ',
+ 'Delete:', d1.path
+ )
d1.etype = 'Delete'
d1.path2 = nil
+
return 'stack'
end
- -- on 'Attrib' or 'Modify' simply wait for the move first
+
+ -- on 'Attrib' or 'Modify' simply stack on moves
+
return 'stack'
end
if d2.path :byte(-1) == 47 and string.starts(d1.path2, d2.path) or
d1.path2:byte(-1) == 47 and string.starts(d2.path, d1.path2)
then
- log('Delay',d2.etype,':',d2.path,' blocked by ','Move:',d1.path,'->',d1.path2)
+ log(
+ 'Delay'
+ ,d2.etype, ':', d2.path,
+ ' blocked by ',
+ 'Move:', d1.path, '->', d1.path2
+ )
+
return 'stack'
end
+
return nil
end
- -- Move upon a single event
+ -- a move upon a non-move event
if d1.etype ~= 'Move' and d2.etype == 'Move' then
if d1.path == d2.path or d1.path == d2.path2 or
d1.path :byte(-1) == 47 and string.starts(d2.path, d1.path) or
@@ -483,13 +689,21 @@
d2.path :byte(-1) == 47 and string.starts(d1.path, d2.path) or
d2.path2:byte(-1) == 47 and string.starts(d1.path, d2.path2)
then
- log('Delay','Move:',d2.path,'->',d2.path2,' splits on ',d1.etype,':',d1.path)
+ log(
+ 'Delay',
+ 'Move:', d2.path, '->', d2.path2,
+ ' splits on ',
+ d1.etype, ':', d1.path
+ )
return 'split'
end
+
return nil
end
- -- Move upon move
+ --
+ -- a move event upon a move event
+ --
if d1.etype == 'Move' and d2.etype == 'Move' then
-- TODO combine moves,
@@ -504,47 +718,62 @@
d2.path2:byte(-1) == 47 and string.starts(d1.path, d2.path2) or
d2.path2:byte(-1) == 47 and string.starts(d1.path2, d2.path2)
then
- log('Delay','Move:',d2.path,'->',d1.path2,
- ' splits on Move:',d1.path,'->',d1.path2)
+ log(
+ 'Delay',
+ 'Move:', d2.path, '->', d1.path2,
+ ' splits on Move:',
+ d1.path, '->', d1.path2
+ )
+
return 'split'
end
+
return nil
end
- error('reached impossible state')
+ error( 'reached impossible state' )
end
- -- public interface
- return {combine = combine}
-end)()
------
+ --
+ -- Public interface
+ --
+ return { combine = combine }
+
+end )( )
+
+--
-- Creates inlets for syncs: the user interface for events.
--
-local InletFactory = (function()
- -----
- -- table to receive the delay of an event
+local InletFactory = ( function( )
+
+ --
+ -- Table to receive the delay of an event
-- or the delay list of an event list.
--
-- Keys are events and values are delays.
- local e2d = {}
+ --
+ local e2d = { }
- -----
- -- table to ensure the uniqueness of every event
+ --
+ -- Table to ensure the uniqueness of every event
-- related to a delay.
--
-- Keys are delay and values are events.
- local e2d2 = {}
+ --
+ local e2d2 = { }
- -----
- -- allows the garbage collector to remove not refrenced
+ --
+ -- Allows the garbage collector to remove not refrenced
-- events.
- setmetatable(e2d, { __mode = 'k' })
- setmetatable(e2d2, { __mode = 'v' })
+ --
+ setmetatable( e2d, { __mode = 'k' } )
+ setmetatable( e2d2, { __mode = 'v' } )
- -----
- -- removes the trailing slash from a path
- local function cutSlash(path)
+ --
+ -- Removes the trailing slash from a path.
+ --
+ local function cutSlash( path )
if string.byte(path, -1) == 47 then
return string.sub(path, 1, -2)
else
@@ -552,425 +781,490 @@
end
end
- local function getPath(event)
+ --
+ -- Gets the path of an event.
+ --
+ local function getPath( event )
if event.move ~= 'To' then
- return e2d[event].path
+ return e2d[ event ].path
else
- return e2d[event].path2
+ return e2d[ event ].path2
end
end
- -----
+ --
-- Interface for user scripts to get event fields.
--
local eventFields = {
- -----
+
+ --
-- Returns a copy of the configuration as called by sync.
-- But including all inherited data and default values.
--
-- TODO give user a readonly version.
--
- config = function(event)
- return e2d[event].sync.config
+ config = function( event )
+ return e2d[ event ].sync.config
end,
-----
-- Returns the inlet belonging to an event.
--
- inlet = function(event)
- return e2d[event].sync.inlet
+ inlet = function( event )
+ return e2d[ event ].sync.inlet
end,
- -----
+ --
-- Returns the type of the event.
+ --
-- Can be: 'Attrib', 'Create', 'Delete', 'Modify' or 'Move',
--
- etype = function(event)
- return e2d[event].etype
+ etype = function( event )
+ return e2d[ event ].etype
end,
- -----
- -- Tells this isn't a list.
--
- isList = function()
+ -- Events are not lists.
+ --
+ isList = function( )
return false
end,
- -----
- -- Return the status of the event.
+ --
+ -- Returns the status of the event.
+ --
-- Can be:
-- 'wait', 'active', 'block'.
--
- status = function(event)
- return e2d[event].status
+ status = function( event )
+ return e2d[ event ].status
end,
- -----
- -- Returns true if event relates to a directory.
--
- isdir = function(event)
- return string.byte(getPath(event), -1) == 47
+ -- Returns true if event relates to a directory
+ --
+ isdir = function( event )
+ return string.byte( getPath( event ), -1 ) == 47
end,
- -----
+ --
-- Returns the name of the file/dir.
+ --
-- Includes a trailing slash for dirs.
--
- name = function(event)
- return string.match(getPath(event), '[^/]+/?$')
+ name = function( event )
+ return string.match( getPath( event ), '[^/]+/?$' )
end,
- -----
- -- Returns the name of the file/dir.
- -- Excludes a trailing slash for dirs.
--
- basename = function(event)
- return string.match(getPath(event), '([^/]+)/?$')
+ -- Returns the name of the file/dir
+ -- excluding a trailing slash for dirs.
+ --
+ basename = function( event )
+ return string.match( getPath( event ), '([^/]+)/?$')
end,
- -----
+ ---
-- Returns the file/dir relative to watch root
- -- Includes a trailing slash for dirs.
+ -- including a trailing slash for dirs.
--
- path = function(event)
- return getPath(event)
+ path = function( event )
+ return getPath( event )
end,
- -----
+ --
-- Returns the directory of the file/dir relative to watch root
-- Always includes a trailing slash.
--
- pathdir = function(event)
- return string.match(getPath(event), '^(.*/)[^/]+/?') or ''
+ pathdir = function( event )
+ return string.match( getPath( event ), '^(.*/)[^/]+/?' ) or ''
end,
- -----
+ --
-- Returns the file/dir relativ to watch root
- -- Excludes a trailing slash for dirs.
+ -- excluding a trailing slash for dirs.
--
- pathname = function(event)
- return cutSlash(getPath(event))
+ pathname = function( event )
+ return cutSlash( getPath( event ) )
end,
- ------
+ ---
-- Returns the absolute path of the watch root.
- -- All symlinks will have been resolved.
+ -- All symlinks are resolved.
--
- source = function(event)
- return e2d[event].sync.source
+ source = function( event )
+ return e2d[ event ].sync.source
end,
- ------
- -- Returns the absolute path of the file/dir.
- -- Includes a trailing slash for dirs.
--
- sourcePath = function(event)
- return e2d[event].sync.source .. getPath(event)
+ -- Returns the absolute path of the file/dir
+ -- including a trailing slash for dirs.
+ --
+ sourcePath = function( event )
+ return e2d[ event ].sync.source .. getPath( event )
end,
- ------
- -- Returns the absolute dir of the file/dir.
- -- Includes a trailing slash.
--
- sourcePathdir = function(event)
+ -- Returns the absolute dir of the file/dir
+ -- including a trailing slash.
+ --
+ sourcePathdir = function( event )
return e2d[event].sync.source ..
- (string.match(getPath(event), '^(.*/)[^/]+/?') or '')
+ ( string.match( getPath( event ), '^(.*/)[^/]+/?' ) or '' )
end,
------
- -- Returns the absolute path of the file/dir.
- -- Excludes a trailing slash for dirs.
+ -- Returns the absolute path of the file/dir
+ -- excluding a trailing slash for dirs.
--
- sourcePathname = function(event)
- return e2d[event].sync.source .. cutSlash(getPath(event))
+ sourcePathname = function( event )
+ return e2d[ event ].sync.source .. cutSlash( getPath( event ) )
end,
- ------
- -- Returns the target.
- -- Just for user comfort
--
- -- (except here, the lsyncd.runner does not care event about the
- -- existance of 'target', this is up to the scripts.)
+ -- Returns the configured target
--
- target = function(event)
- return e2d[event].sync.config.target
+ target = function( event )
+ return e2d[ event ].sync.config.target
end,
- ------
- -- Returns the relative dir/file appended to the target.
- -- Includes a trailing slash for dirs.
--
- targetPath = function(event)
- return e2d[event].sync.config.target .. getPath(event)
+ -- Returns the relative dir/file appended to the target
+ -- including a trailing slash for dirs.
+ --
+ targetPath = function( event )
+ return e2d[ event ].sync.config.target .. getPath( event )
end,
- ------
- -- Returns the dir of the dir/file appended to the target.
- -- Includes a trailing slash.
--
- targetPathdir = function(event)
- return e2d[event].sync.config.target ..
- (string.match(getPath(event), '^(.*/)[^/]+/?') or '')
+ -- Returns the dir of the dir/file appended to the target
+ -- including a trailing slash.
+ --
+ targetPathdir = function( event )
+ return e2d[ event ].sync.config.target ..
+ ( string.match( getPath( event ), '^(.*/)[^/]+/?' ) or '' )
end,
- ------
- -- Returns the relative dir/file appended to the target.
- -- Excludes a trailing slash for dirs.
--
- targetPathname = function(event)
- return e2d[event].sync.config.target ..
- cutSlash(getPath(event))
+ -- Returns the relative dir/file appended to the target
+ -- excluding a trailing slash for dirs.
+ --
+ targetPathname = function( event )
+ return e2d[ event ].sync.config.target ..
+ cutSlash( getPath( event ) )
end,
}
- -----
+ --
-- Retrievs event fields for the user script.
--
local eventMeta = {
- __index = function(event, field)
- local f = eventFields[field]
+
+ __index = function( event, field )
+ local f = eventFields[ field ]
if not f then
if field == 'move' then
-- possibly undefined
return nil
end
- error('event does not have field "'..field..'"', 2)
+ error( 'event does not have field "'..field..'"', 2 )
end
- return f(event)
+ return f( event )
end
+
}
- -----
- -- Interface for user scripts to get event fields.
+ --
+ -- Interface for user scripts to get list fields.
--
local eventListFuncs = {
- -----
+
+ --
-- Returns a list of paths of all events in list.
--
-- @param elist -- handle returned by getevents()
-- @param mutator -- if not nil called with (etype, path, path2)
-- returns one or two strings to add.
--
- getPaths = function(elist, mutator)
+ getPaths = function( elist, mutator )
+
local dlist = e2d[elist]
+
if not dlist then
- error('cannot find delay list from event list.')
+ error( 'cannot find delay list from event list.' )
end
- local result = {}
+
+ local result = { }
local resultn = 1
- for k, d in ipairs(dlist) do
+
+ for k, d in ipairs( dlist ) do
+
local s1, s2
+
if mutator then
- s1, s2 = mutator(d.etype, d.path, d.path2)
+ s1, s2 = mutator( d.etype, d.path, d.path2 )
else
s1, s2 = d.path, d.path2
end
- result[resultn] = s1
+
+ result[ resultn ] = s1
resultn = resultn + 1
+
if s2 then
- result[resultn] = s2
+ result[ resultn ] = s2
resultn = resultn + 1
end
end
+
return result
+
end
}
- -----
- -- Retrievs event list fields for the user script.
+ --
+ -- Retrievs event list fields for the user script
--
local eventListMeta = {
- __index = function(elist, func)
- if func == 'isList' then return true end
- if func == 'config' then return e2d[elist].sync.config end
+ __index = function( elist, func )
+
+ if func == 'isList' then
+ return true
+ end
+
+ if func == 'config' then
+ return e2d[ elist ].sync.config
+ end
+
+ local f = eventListFuncs[ func ]
- local f = eventListFuncs[func]
if not f then
- error('event list does not have function "'..func..'"', 2)
+ error(
+ 'event list does not have function "' .. func .. '"',
+ 2
+ )
end
- return function(...)
- return f(elist, ...)
+ return function( ... )
+ return f( elist, ... )
end
+
end
+
}
- -----
- -- table of all inlets with their syncs
--
- local inlets = {}
+ -- Table of all inlets with their syncs.
+ --
+ local inlets = { }
- -----
- -- allows the garbage collector to remove entries.
- -- TODO check memory use
- setmetatable(inlets, { __mode = 'v' })
+ --
+ -- Allows the garbage collector to remove entries.
+ --
+ setmetatable( inlets, { __mode = 'v' } )
- -----
+ --
-- Encapsulates a delay into an event for the user script.
--
- local function d2e(delay)
+ local function d2e( delay )
+
-- already created?
local eu = e2d2[delay]
if delay.etype ~= 'Move' then
- if eu then return eu end
- local event = {}
- setmetatable(event, eventMeta)
- e2d[event] = delay
- e2d2[delay] = event
+ if eu then
+ return eu
+ end
+
+ local event = { }
+ setmetatable( event, eventMeta )
+ e2d[ event ] = delay
+ e2d2[ delay ] = event
+
return event
+
else
-- moves have 2 events - origin and destination
- if eu then return eu[1], eu[2] end
+ if eu then
+ return eu[1], eu[2]
+ end
local event = { move = 'Fr' }
local event2 = { move = 'To' }
- setmetatable(event, eventMeta)
- setmetatable(event2, eventMeta)
- e2d[event] = delay
- e2d[event2] = delay
- e2d2[delay] = { event, event2 }
+
+ setmetatable( event, eventMeta )
+ setmetatable( event2, eventMeta )
+
+ e2d[ event ] = delay
+ e2d[ event2 ] = delay
+
+ e2d2[ delay ] = { event, event2 }
+
-- move events have a field 'move'
return event, event2
+
end
end
- -----
+ --
-- Encapsulates a delay list into an event list for the user script.
--
- local function dl2el(dlist)
- local eu = e2d2[dlist]
- if eu then return eu end
-
- local elist = {}
- setmetatable(elist, eventListMeta)
- e2d[elist] = dlist
- e2d2[dlist] = elist
+ local function dl2el( dlist )
+
+ local eu = e2d2[ dlist ]
+
+ if eu then
+ return eu
+ end
+
+ local elist = { }
+
+ setmetatable( elist, eventListMeta )
+
+ e2d [ elist ] = dlist
+ e2d2[ dlist ] = elist
+
return elist
+
end
- -----
+ --
-- The functions the inlet provides.
--
local inletFuncs = {
- -----
- -- adds an exclude.
+
+ --
+ -- Adds an exclude.
--
- addExclude = function(sync, pattern)
- sync:addExclude(pattern)
+ addExclude = function( sync, pattern )
+ sync:addExclude( pattern )
end,
- -----
- -- removes an exclude.
--
- rmExclude = function(sync, pattern)
- sync:rmExclude(pattern)
+ -- Removes an exclude.
+ --
+ rmExclude = function( sync, pattern )
+ sync:rmExclude( pattern )
end,
- -----
- -- gets the list of excludes in their original rsynlike patterns form.
--
- getExcludes = function(sync)
+ -- Gets the list of excludes in their original rsynlike patterns form.
+ --
+ getExcludes = function( sync )
+
-- creates a copy
- local e = {}
+ local e = { }
local en = 1;
- for k, _ in pairs(sync.excludes.list) do
- e[en] = k;
+
+ for k, _ in pairs( sync.excludes.list ) do
+ e[ en ] = k;
en = en + 1;
end
+
return e;
end,
- -----
+ --
-- Creates a blanketEvent that blocks everything
-- and is blocked by everything.
--
- createBlanketEvent = function(sync)
- return d2e(sync:addBlanketDelay())
+ createBlanketEvent = function( sync )
+ return d2e( sync:addBlanketDelay( ) )
end,
- -----
+ --
-- Discards a waiting event.
--
- discardEvent = function(sync, event)
- local delay = e2d[event]
+ discardEvent = function( sync, event )
+ local delay = e2d[ event ]
if delay.status ~= 'wait' then
- log('Error',
+ log(
+ 'Error',
'Ignored cancel of a non-waiting event of type ',
- event.etype)
+ event.etype
+ )
return
end
- sync:removeDelay(delay)
+ sync:removeDelay( delay )
end,
- -----
+ --
-- Gets the next not blocked event from queue.
--
- getEvent = function(sync)
- return d2e(sync:getNextDelay(now()))
+ getEvent = function( sync )
+ return d2e( sync:getNextDelay( now( ) ) )
end,
- -----
+ --
-- Gets all events that are not blocked by active events.
--
-- @param if not nil a function to test each delay
--
- getEvents = function(sync, test)
- local dlist = sync:getDelays(test)
- return dl2el(dlist)
+ getEvents = function( sync, test )
+ local dlist = sync:getDelays( test )
+ return dl2el( dlist )
end,
- -----
+ --
-- Returns the configuration table specified by sync{}
--
- getConfig = function(sync)
+ getConfig = function( sync )
-- TODO gives a readonly handler only.
return sync.config
end,
}
- -----
+ --
-- Forwards access to inlet functions.
--
local inletMeta = {
- __index = function(inlet, func)
- local f = inletFuncs[func]
- if not f then error('inlet does not have function "'..func..'"', 2) end
- return function(...) return f(inlets[inlet], ...) end
+ __index = function( inlet, func )
+ local f = inletFuncs[ func ]
+ if not f then
+ error(
+ 'inlet does not have function "'..func..'"',
+ 2
+ )
+ end
+
+ return function( ... )
+ return f( inlets[ inlet ], ... )
+ end
end,
}
- -----
- -- Creates a new inlet for Sync
- local function newInlet(sync)
- -- lua runner controlled variables
- local inlet = {}
+ --
+ -- Creates a new inlet for Sync.
+ --
+ local function newInlet( sync )
+
+ -- Lsyncd runner controlled variables
+ local inlet = { }
-- sets use access methods
- setmetatable(inlet, inletMeta)
- inlets[inlet] = sync
+ setmetatable( inlet, inletMeta )
+ inlets[ inlet ] = sync
return inlet
end
- -----
+ --
-- Returns the delay from a event.
--
- local function getDelayOrList(event)
- return e2d[event]
+ local function getDelayOrList( event )
+ return e2d[ event ]
end
- -----
+ --
-- Returns the sync from an event or list
--
- local function getSync(event)
- return e2d[event].sync
+ local function getSync( event )
+ return e2d[ event ].sync
end
- -----
- -- public interface.
- -- this one is split, one for user one for runner.
+ --
+ -- Public interface.
+ --
return {
getDelayOrList = getDelayOrList,
d2e = d2e,
@@ -978,64 +1272,85 @@
getSync = getSync,
newInlet = newInlet,
}
-end)()
+end )( )
------
+
+--
-- A set of exclude patterns
--
-local Excludes = (function()
+local Excludes = ( function( )
- -----
+ --
-- Turns a rsync like file pattern to a lua pattern.
+ -- ( at best it can )
--
- local function toLuaPattern(p)
+ local function toLuaPattern( p )
local o = p
- p = string.gsub(p, '%%', '%%%%')
- p = string.gsub(p, '%^', '%%^')
- p = string.gsub(p, '%$', '%%$')
- p = string.gsub(p, '%(', '%%(')
- p = string.gsub(p, '%)', '%%)')
- p = string.gsub(p, '%.', '%%.')
- p = string.gsub(p, '%[', '%%[')
- p = string.gsub(p, '%]', '%%]')
- p = string.gsub(p, '%+', '%%+')
- p = string.gsub(p, '%-', '%%-')
- p = string.gsub(p, '%?', '[^/]')
- p = string.gsub(p, '%*', '[^/]*')
+ p = string.gsub( p, '%%', '%%%%' )
+ p = string.gsub( p, '%^', '%%^' )
+ p = string.gsub( p, '%$', '%%$' )
+ p = string.gsub( p, '%(', '%%(' )
+ p = string.gsub( p, '%)', '%%)' )
+ p = string.gsub( p, '%.', '%%.' )
+ p = string.gsub( p, '%[', '%%[' )
+ p = string.gsub( p, '%]', '%%]' )
+ p = string.gsub( p, '%+', '%%+' )
+ p = string.gsub( p, '%-', '%%-' )
+ p = string.gsub( p, '%?', '[^/]' )
+ p = string.gsub( p, '%*', '[^/]*' )
-- this was a ** before
- p = string.gsub(p, '%[%^/%]%*%[%^/%]%*', '.*')
- p = string.gsub(p, '^/', '^/')
- if p:sub(1,2) ~= '^/' then -- does not begin with '^/'
- -- all matches should begin with '/'.
- p = '/'..p;
+ p = string.gsub( p, '%[%^/%]%*%[%^/%]%*', '.*' )
+ p = string.gsub( p, '^/', '^/' )
+
+ if p:sub( 1, 2 ) ~= '^/' then
+ -- if does not begin with '^/'
+ -- then all matches should begin with '/'.
+ p = '/' .. p;
end
- log('Exclude', 'toLuaPattern "',o,'" = "',p,'"')
+
+ log(
+ 'Exclude',
+ 'toLuaPattern "',
+ o, '" = "', p, '"'
+ )
+
return p
end
- -----
- -- Adds a pattern to exclude.
--
- local function add(self, pattern)
- if self.list[pattern] then
+ -- Adds a pattern to exclude
+ --
+ local function add( self, pattern )
+
+ if self.list[ pattern ] then
-- already in the list
return
end
- local lp = toLuaPattern(pattern)
- self.list[pattern] = lp
+
+ local lp = toLuaPattern( pattern )
+ self.list[ pattern ] = lp
+
end
- -----
+ --
-- Removes a pattern to exclude.
--
- local function remove(self, pattern)
- if not self.list[pattern] then
- -- already in the list
- log('Normal', 'Removing not excluded exclude "'..pattern..'"')
+ local function remove( self, pattern )
+
+ if not self.list[ pattern ] then
+ -- already in the list?
+
+ log(
+ 'Normal',
+ 'Removing not excluded exclude "' .. pattern .. '"'
+ )
+
return
end
+
self.list[pattern] = nil
+
end
@@ -1048,47 +1363,76 @@
end
end
- -----
- -- loads excludes from a file
--
- local function loadFile(self, file)
- f, err = io.open(file)
+ -- Loads the excludes from a file
+ --
+ local function loadFile( self, file )
+
+ f, err = io.open( file )
+
if not f then
- log('Error', 'Cannot open exclude file "',file,'": ', err)
- terminate(-1) -- ERRNO
+ log(
+ 'Error',
+ 'Cannot open exclude file "', file,'": ',
+ err
+ )
+
+ terminate( -1 )
end
+
for line in f:lines() do
+
-- lsyncd 2.0 does not support includes
+
if not string.match(line, '%s*+') then
- local p = string.match(line, '%s*-?%s*(.*)')
- if p then add(self, p) end
+ local p = string.match(
+ line, '%s*-?%s*(.*)'
+ )
+ if p then
+ add(self, p)
+ end
end
end
- f:close()
+
+ f:close( )
end
- -----
+ --
-- Tests if 'path' is excluded.
--
- local function test(self, path)
- for _, p in pairs(self.list) do
- if p:byte(-1) == 36 then
+ local function test( self, path )
+
+ for _, p in pairs( self.list ) do
+
+ if p:byte( -1 ) == 36 then
-- ends with $
- if path:match(p) then return true end
+
+ if path:match( p ) then
+ return true
+ end
+
else
+
-- ends either end with / or $
- if path:match(p..'/') or path:match(p..'$') then return true end
+ if path:match(p .. '/') or path:match(p .. '$') then
+ return true
+ end
+
end
end
+
return false
+
end
- -----
+
+ --
-- Cretes a new exclude set
--
- local function new()
+ local function new( )
+
return {
- list = {},
+ list = { },
-- functions
add = add,
@@ -1097,120 +1441,157 @@
remove = remove,
test = test,
}
+
end
- -----
+ --
-- Public interface
+ --
return { new = new }
-end)()
------
+end )( )
+
+--
-- Holds information about one observed directory inclusively subdirs.
--
-local Sync = (function()
- -----
+local Sync = ( function( )
+
+ --
-- Syncs that have no name specified by the user script
-- get an incremental default name 'Sync[X]'
--
local nextDefaultName = 1
- -----
+ --
-- Adds an exclude.
--
- local function addExclude(self, pattern)
- return self.excludes:add(pattern)
+ local function addExclude( self, pattern )
+
+ return self.excludes:add( pattern )
+
end
- -----
+ --
-- Removes an exclude.
--
- local function rmExclude(self, pattern)
- return self.excludes:remove(pattern)
+ local function rmExclude( self, pattern )
+
+ return self.excludes:remove( pattern )
+
end
- -----
+ --
-- Removes a delay.
--
- local function removeDelay(self, delay)
- if self.delays[delay.dpos] ~= delay then
- error('Queue is broken, delay not a dpos')
+ local function removeDelay( self, delay )
+ if self.delays[ delay.dpos ] ~= delay then
+ error( 'Queue is broken, delay not a dpos' )
end
- Queue.remove(self.delays, delay.dpos)
+
+ Queue.remove( self.delays, delay.dpos )
-- free all delays blocked by this one.
if delay.blocks then
- for i, vd in pairs(delay.blocks) do
+ for i, vd in pairs( delay.blocks ) do
vd.status = 'wait'
end
end
end
- -----
+ --
-- Returns true if this Sync concerns about 'path'
--
- local function concerns(self, path)
+ local function concerns( self, path )
+
-- not concerned if watch rootdir doesnt match
- if not path:starts(self.source) then
+ if not path:starts( self.source ) then
return false
end
-- a sub dir and not concerned about subdirs
if self.config.subdirs == false and
- path:sub(#self.source, -1):match('[^/]+/?')
+ path:sub( #self.source, -1 ):match( '[^/]+/?' )
then
return false
end
-- concerned if not excluded
- return not self.excludes:test(path:sub(#self.source))
+ return not self.excludes:test( path:sub( #self.source ) )
end
- -----
+ --
-- Collects a child process
--
- local function collect(self, pid, exitcode)
- local delay = self.processes[pid]
+ local function collect( self, pid, exitcode )
+
+ local delay = self.processes[ pid ]
+
if not delay then
-- not a child of this sync.
return
end
if delay.status then
- log('Delay', 'collected an event')
+
+ log( 'Delay', 'collected an event' )
+
if delay.status ~= 'active' then
error('collecting a non-active process')
end
+
local rc = self.config.collect(
- InletFactory.d2e(delay),
- exitcode)
+ InletFactory.d2e( delay ),
+ exitcode
+ )
+
if rc == 'die' then
- log('Error', 'Critical exitcode.');
- terminate(-1) --ERRNO
+ log( 'Error', 'Critical exitcode.' );
+ terminate( -1 )
end
+
if rc ~= 'again' then
-- if its active again the collecter restarted the event
- removeDelay(self, delay)
- log('Delay', 'Finish of ',delay.etype,' on ',self.source,delay.path,' = ',exitcode)
+ removeDelay( self, delay )
+ log(
+ 'Delay',
+ 'Finish of ',
+ delay.etype,
+ ' on ',
+ self.source,delay.path,
+ ' = ',
+ exitcode
+ )
else
-- sets the delay on wait again
delay.status = 'wait'
+
local alarm = self.config.delay
+
-- delays at least 1 second
if alarm < 1 then
alarm = 1
end
- delay.alarm = now() + alarm
+
+ delay.alarm = now( ) + alarm
end
else
- log('Delay', 'collected a list')
+ log(
+ 'Delay',
+ 'collected a list'
+ )
+
local rc = self.config.collect(
- InletFactory.dl2el(delay),
- exitcode)
+ InletFactory.dl2el( delay ),
+ exitcode
+ )
+
if rc == 'die' then
- log('Error', 'Critical exitcode.');
- terminate(-1) --ERRNO
+ log( 'Error', 'Critical exitcode.' );
+ terminate( -1 )
end
+
if rc == 'again' then
+
-- sets the delay on wait again
delay.status = 'wait'
local alarm = self.config.delay
@@ -1218,96 +1599,181 @@
if alarm < 1 then
alarm = 1
end
+
alarm = now() + alarm
- for _, d in ipairs(delay) do
+
+ for _, d in ipairs( delay ) do
d.alarm = alarm
d.status = 'wait'
end
end
- for _, d in ipairs(delay) do
+
+ for _, d in ipairs( delay ) do
if rc ~= 'again' then
- removeDelay(self, d)
+ removeDelay( self, d )
else
d.status = 'wait'
end
end
- log('Delay','Finished list = ',exitcode)
+
+ log( 'Delay','Finished list = ',exitcode )
end
- self.processes[pid] = nil
+
+ self.processes[ pid ] = nil
end
- -----
+ --
-- Stacks a newDelay on the oldDelay,
-- the oldDelay blocks the new Delay.
--
-- A delay can block 'n' other delays,
-- but is blocked at most by one, the latest delay.
--
- local function stack(oldDelay, newDelay)
+ local function stack( oldDelay, newDelay )
+
newDelay.status = 'block'
+
if not oldDelay.blocks then
- oldDelay.blocks = {}
+ oldDelay.blocks = { }
end
- table.insert(oldDelay.blocks, newDelay)
+
+ table.insert( oldDelay.blocks, newDelay )
end
- -----
+ --
-- Puts an action on the delay stack.
--
- local function delay(self, etype, time, path, path2)
- log('Function', 'delay(',self.config.name,', ',etype,', ',path,', ',path2,')')
+ local function delay( self, etype, time, path, path2 )
+
+ log(
+ 'Function',
+ 'delay( ',
+ self.config.name, ', ',
+ etype, ', ',
+ path, ', ',
+ path2,
+ ' )'
+ )
-- TODO
- local function recurse()
- if etype == 'Create' and path:byte(-1) == 47 then
- local entries = lsyncd.readdir(self.source .. path)
+ local function recurse( )
+
+ if etype == 'Create' and path:byte( -1 ) == 47 then
+ local entries = lsyncd.readdir( self.source .. path )
+
if entries then
+
for dirname, isdir in pairs(entries) do
+
local pd = path .. dirname
- if isdir then pd = pd..'/' end
- log('Delay', 'Create creates Create on ',pd)
- delay(self, 'Create', time, pd, nil)
+
+ if isdir then
+ pd = pd..'/'
+ end
+
+ log(
+ 'Delay',
+ 'Create creates Create on ',
+ pd
+ )
+ delay( self, 'Create', time, pd, nil )
+
end
+
end
+
end
+
end
-- exclusion tests
if not path2 then
-- simple test for single path events
if self.excludes:test(path) then
- log('Exclude', 'excluded ',etype,' on "',path,'"')
+ log(
+ 'Exclude',
+ 'excluded ',
+ etype,
+ ' on "',
+ path,
+ '"'
+ )
return
end
else
-- for double paths (move) it might result into a split
- local ex1 = self.excludes:test(path)
- local ex2 = self.excludes:test(path2)
+ local ex1 = self.excludes:test( path )
+ local ex2 = self.excludes:test( path2 )
+
if ex1 and ex2 then
- log('Exclude', 'excluded "',etype,' on "',path,'" -> "',path2,'"')
+
+ log(
+ 'Exclude',
+ 'excluded "',
+ etype,
+ ' on "',
+ path,
+ '" -> "',
+ path2,
+ '"'
+ )
+
return
+
elseif not ex1 and ex2 then
+
-- splits the move if only partly excluded
- log('Exclude', 'excluded destination transformed ',etype,' to Delete ',path)
- delay(self, 'Delete', time, path, nil)
+ log(
+ 'Exclude',
+ 'excluded destination transformed ',
+ etype,
+ ' to Delete ',
+ path
+ )
+
+ delay(
+ self,
+ 'Delete',
+ time,
+ path,
+ nil
+ )
+
return
+
elseif ex1 and not ex2 then
-- splits the move if only partly excluded
- log('Exclude', 'excluded origin transformed ',etype,' to Create.',path2)
- delay(self, 'Create', time, path2, nil)
+ log(
+ 'Exclude',
+ 'excluded origin transformed ',
+ etype,
+ ' to Create.',
+ path2
+ )
+
+ delay(
+ self,
+ 'Create',
+ time,
+ path2,
+ nil
+ )
+
return
end
end
if etype == 'Move' and not self.config.onMove then
+
-- if there is no move action defined,
-- split a move as delete/create
-- layer 1 scripts which want moves events have to
-- set onMove simply to 'true'
- log('Delay', 'splitting Move into Delete & Create')
- delay(self, 'Delete', time, path, nil)
- delay(self, 'Create', time, path2, nil)
+ log( 'Delay', 'splitting Move into Delete & Create' )
+ delay( self, 'Delete', time, path, nil )
+ delay( self, 'Create', time, path2, nil )
return
+
end
-- creates the new action
@@ -1315,33 +1781,52 @@
if time and self.config.delay then
alarm = time + self.config.delay
else
- alarm = now()
+ alarm = now( )
end
+
-- new delay
- local nd = Delay.new(etype, self, alarm, path, path2)
+ local nd = Delay.new(
+ etype,
+ self,
+ alarm,
+ path,
+ path2
+ )
+
if nd.etype == 'Init' or nd.etype == 'Blanket' then
- -- always stack blanket events on the last event
- log('Delay', 'Stacking ',nd.etype,' event.')
+
+ -- always stack init or blanket events on the last event
+ log(
+ 'Delay',
+ 'Stacking ',
+ nd.etype,
+ ' event.'
+ )
+
if self.delays.size > 0 then
- stack(self.delays[self.delays.last], nd)
+ stack( self.delays[ self.delays.last ], nd )
end
- nd.dpos = Queue.push(self.delays, nd)
- recurse()
+
+ nd.dpos = Queue.push( self.delays, nd )
+ recurse( )
+
return
+
end
-- detects blocks and combos by working from back until
-- front through the fifo
- for il, od in Queue.qpairsReverse(self.delays) do
+ for il, od in Queue.qpairsReverse( self.delays ) do
+
-- asks Combiner what to do
- local ac = Combiner.combine(od, nd)
+ local ac = Combiner.combine( od, nd )
if ac then
if ac == 'remove' then
- Queue.remove(self.delays, il)
+ Queue.remove( self.delays, il )
elseif ac == 'stack' then
- stack(od, nd)
- nd.dpos = Queue.push(self.delays, nd)
+ stack( od, nd )
+ nd.dpos = Queue.push( self.delays, nd )
elseif ac == 'absorb' then
-- nada
elseif ac == 'replace' then
@@ -1349,75 +1834,81 @@
od.path = nd.path
od.path2 = nd.path2
elseif ac == 'split' then
- delay(self, 'Delete', time, path, nil)
- delay(self, 'Create', time, path2, nil)
+ delay( self, 'Delete', time, path, nil )
+ delay( self, 'Create', time, path2, nil )
else
- error('unknown result of combine()')
+ error( 'unknown result of combine()' )
end
- recurse()
+ recurse( )
return
end
+
il = il - 1
end
+
if nd.path2 then
- log('Delay','New ',nd.etype,':',nd.path,'->',nd.path2)
+ log( 'Delay','New ',nd.etype,':',nd.path,'->',nd.path2 )
else
- log('Delay','New ',nd.etype,':',nd.path)
+ log( 'Delay','New ',nd.etype,':',nd.path )
end
+
-- no block or combo
- nd.dpos = Queue.push(self.delays, nd)
- recurse()
+ nd.dpos = Queue.push( self.delays, nd )
+ recurse( )
end
- -----
- -- Returns the nearest alarm for this Sync.
--
- local function getAlarm(self)
- if self.processes:size() >= self.config.maxProcesses then
+ -- Returns the soonest alarm for this Sync.
+ --
+ local function getAlarm( self )
+
+ if self.processes:size( ) >= self.config.maxProcesses then
return false
end
-- first checks if more processes could be spawned
- if self.processes:size() < self.config.maxProcesses then
+ if self.processes:size( ) < self.config.maxProcesses then
+
-- finds the nearest delay waiting to be spawned
- for _, d in Queue.qpairs(self.delays) do
+ for _, d in Queue.qpairs( self.delays ) do
if d.status == 'wait' then return d.alarm end
end
+
end
-- nothing to spawn
return false
end
- -----
+ --
-- Gets all delays that are not blocked by active delays.
--
-- @param test function to test each delay
--
- local function getDelays(self, test)
- local dlist = { sync = self}
+ local function getDelays( self, test )
+ local dlist = { sync = self}
local dlistn = 1
- local blocks = {}
+ local blocks = { }
- ----
+ --
-- inheritly transfers all blocks from delay
--
- local function getBlocks(delay)
- blocks[delay] = true
+ local function getBlocks( delay )
+ blocks[ delay ] = true
if delay.blocks then
- for i, d in ipairs(delay.blocks) do
- getBlocks(d)
+ for i, d in ipairs( delay.blocks ) do
+ getBlocks( d )
end
end
end
- for i, d in Queue.qpairs(self.delays) do
+ for i, d in Queue.qpairs( self.delays ) do
if d.status == 'active' or
- (test and not test(InletFactory.d2e(d)))
+ ( test and not test( InletFactory.d2e( d ) ) )
then
- getBlocks(d)
- elseif not blocks[d] then
- dlist[dlistn] = d
+ getBlocks( d )
+ elseif not blocks[ d ] then
+ dlist[ dlistn ] = d
dlistn = dlistn + 1
end
end
@@ -1425,21 +1916,34 @@
return dlist
end
- -----
+ --
-- Creates new actions
--
- local function invokeActions(self, timestamp)
- log('Function', 'invokeActions("',self.config.name,'",',timestamp,')')
- if self.processes:size() >= self.config.maxProcesses then
+ local function invokeActions( self, timestamp )
+
+ log(
+ 'Function',
+ 'invokeActions( "',
+ self.config.name, '", ',
+ timestamp,
+ ' )'
+ )
+
+ if self.processes:size( ) >= self.config.maxProcesses then
-- no new processes
return
end
- for _, d in Queue.qpairs(self.delays) do
+
+ for _, d in Queue.qpairs( self.delays ) do
+
-- if reached the global limit return
- if settings.maxProcesses and processCount >= settings.maxProcesses then
+ if uSettings.maxProcesses and
+ processCount >= uSettings.maxProcesses
+ then
log('Alarm', 'at global process limit.')
return
end
+
if self.delays.size < self.config.maxDelays then
-- time constrains are only concerned if not maxed
-- the delay FIFO already.
@@ -1448,14 +1952,17 @@
return
end
end
+
if d.status == 'wait' then
+
-- found a waiting delay
if d.etype ~= 'Init' then
- self.config.action(self.inlet)
+ self.config.action( self.inlet )
else
- self.config.init(InletFactory.d2e(d))
+ self.config.init( InletFactory.d2e( d ) )
end
- if self.processes:size() >= self.config.maxProcesses then
+
+ if self.processes:size( ) >= self.config.maxProcesses then
-- no further processes
return
end
@@ -1463,11 +1970,13 @@
end
end
- -----
+ --
-- Gets the next event to be processed.
--
- local function getNextDelay(self, timestamp)
- for i, d in Queue.qpairs(self.delays) do
+ local function getNextDelay( self, timestamp )
+
+ for i, d in Queue.qpairs( self.delays ) do
+
if self.delays.size < self.config.maxDelays then
-- time constrains are only concerned if not maxed
-- the delay FIFO already.
@@ -1476,75 +1985,92 @@
return nil
end
end
+
if d.status == 'wait' then
-- found a waiting delay
return d
end
end
+
end
------
-- Adds and returns a blanket delay thats blocks all.
-- Used as custom marker.
--
- local function addBlanketDelay(self)
- local newd = Delay.new('Blanket', self, true, '')
- newd.dpos = Queue.push(self.delays, newd)
+ local function addBlanketDelay( self )
+ local newd = Delay.new( 'Blanket', self, true, '' )
+ newd.dpos = Queue.push( self.delays, newd )
return newd
end
- ------
+ --
-- Adds and returns a blanket delay thats blocks all.
-- Used as startup marker to call init asap.
--
- local function addInitDelay(self)
- local newd = Delay.new('Init', self, true, '')
- newd.dpos = Queue.push(self.delays, newd)
+ local function addInitDelay( self )
+
+ local newd = Delay.new( 'Init', self, true, '' )
+
+ newd.dpos = Queue.push( self.delays, newd )
+
return newd
end
- -----
+ --
-- Writes a status report about delays in this sync.
--
- local function statusReport(self, f)
+ local function statusReport( self, f )
+
local spaces = ' '
- f:write(self.config.name,' source=',self.source,'\n')
- f:write('There are ',self.delays.size, ' delays\n')
- for i, vd in Queue.qpairs(self.delays) do
+
+ f:write( self.config.name, ' source=', self.source, '\n' )
+ f:write( 'There are ', self.delays.size, ' delays\n')
+
+ for i, vd in Queue.qpairs( self.delays ) do
local st = vd.status
- f:write(st, string.sub(spaces, 1, 7 - #st))
- f:write(vd.etype,' ')
- f:write(vd.path)
- if (vd.path2) then
- f:write(' -> ',vd.path2)
+ f:write( st, string.sub( spaces, 1, 7 - #st ) )
+ f:write( vd.etype, ' ' )
+ f:write( vd.path )
+
+ if vd.path2 then
+ f:write( ' -> ',vd.path2 )
end
+
f:write('\n')
+
end
- f:write('Excluding:\n')
+
+ f:write( 'Excluding:\n' )
+
local nothing = true
- for t, p in pairs(self.excludes.list) do
+
+ for t, p in pairs( self.excludes.list ) do
nothing = false
- f:write(t,'\n')
+ f:write( t,'\n' )
end
if nothing then
f:write(' nothing.\n')
end
- f:write('\n')
+
+ f:write( '\n' )
end
- -----
+ --
-- Creates a new Sync
--
- local function new(config)
+ local function new( config )
local s = {
-- fields
+
config = config,
- delays = Queue.new(),
+ delays = Queue.new( ),
source = config.source,
- processes = CountArray.new(),
- excludes = Excludes.new(),
+ processes = CountArray.new( ),
+ excludes = Excludes.new( ),
-- functions
+
addBlanketDelay = addBlanketDelay,
addExclude = addExclude,
addInitDelay = addInitDelay,
@@ -1559,209 +2085,358 @@
rmExclude = rmExclude,
statusReport = statusReport,
}
- s.inlet = InletFactory.newInlet(s)
+
+ s.inlet = InletFactory.newInlet( s )
-- provides a default name if needed
if not config.name then
- config.name = 'Sync'..nextDefaultName
+ config.name = 'Sync' .. nextDefaultName
end
- -- increments default nevertheless to cause less confusion
- -- so name will be the n-th call to sync{}
+
+ -- increments defaults if a config name was given or not
+ -- so Sync{n} will be the n-th call to sync{}
nextDefaultName = nextDefaultName + 1
-- loads exclusions
if config.exclude then
- local te = type(config.exclude)
+
+ local te = type( config.exclude )
+
if te == 'table' then
- s.excludes:addList(config.exclude)
+ s.excludes:addList( config.exclude )
elseif te == 'string' then
- s.excludes:add(config.exclude)
+ s.excludes:add( config.exclude )
else
- error('type for exclude must be table or string', 2)
+ error( 'type for exclude must be table or string', 2 )
end
end
+
if config.excludeFrom then
- s.excludes:loadFile(config.excludeFrom)
+ s.excludes:loadFile( config.excludeFrom )
end
return s
end
- -----
- -- public interface
--
- return {new = new}
-end)()
+ -- Public interface
+ --
+ return { new = new }
+end )( )
------
+
+--
-- Syncs - a singleton
--
--- It maintains all configured directories to be synced.
+-- Syncs maintains all configured syncs.
--
-local Syncs = (function()
- -----
+local Syncs = ( function( )
+
+ --
-- the list of all syncs
--
- local list = Array.new()
+ local syncsList = Array.new( )
- -----
+ --
-- The round robin pointer. In case of global limited maxProcesses
-- gives every sync equal chances to spawn the next process.
--
local round = 1
- -----
- -- The cycle() sheduler goes into the next round of roundrobin.
- local function nextRound()
+ --
+ -- The cycle( ) sheduler goes into the next round of roundrobin.
+ --
+ local function nextRound( )
+
round = round + 1;
- if round > #list then
+
+ if round > #syncsList then
round = 1
end
+
return round
end
- -----
+ --
-- Returns the round
- local function getRound()
+ --
+ local function getRound( )
return round
end
- -----
+ --
-- Returns sync at listpos i
- local function get(i)
- return list[i];
+ --
+ local function get( i )
+ return syncsList[ i ];
+ end
+
+ --
+ -- Helper function for inherit
+ -- defined below
+ --
+ local inheritKV
+
+ --
+ -- Recurvely inherits a source table to a destionation table
+ -- copying all keys from source.
+ --
+ -- table copy source ( cs )
+ -- table copy destination ( cd )
+ --
+ -- All entries with integer keys are inherited as additional
+ -- sources for non-verbatim tables
+ --
+ local function inherit( cd, cs )
+
+ --
+ -- First copies all entries with non-integer keys
+ -- tables are merged, already present keys are not
+ -- overwritten
+ --
+ -- For verbatim tables integer keys are treated like
+ -- non integer keys
+ --
+ for k, v in pairs( cs ) do
+ if
+ (
+ type( k ) ~= 'number' or
+ cs._verbatim == true
+ )
+ and
+ (
+ type( cs._merge ) ~= 'table' or
+ cs._merge[ k ] == true
+ )
+ then
+ inheritKV( cd, k, v )
+ end
+ end
+
+ --
+ -- recursevely inherits all integer keyed tables
+ -- ( for non-verbatim tables )
+ --
+ if cs._verbatim ~= true then
+
+ local n = nil
+ for k, v in ipairs( cs ) do
+ n = k
+ if type( v ) == 'table' then
+ inherit( cd, v )
+ else
+ cd[ #cd + 1 ] = v
+ end
+ end
+
+ end
end
- -----
- -- Inheritly copies all non integer keys from
- -- copy source (cs) to copy destination (cd).
--
- -- all entries with integer keys are treated as new sources to copy
+ -- Helper to inherit. Inherits one key.
--
- local function inherit(cd, cs)
- -- first copies from source all
- -- non-defined non-integer keyed values
- for k, v in pairs(cs) do
- if type(k) ~= 'number' and cd[k] == nil then
- cd[k] = v
- end
- end
- -- first recurses into all integer keyed tables
- for i, v in ipairs(cs) do
- if type(v) == 'table' then
- inherit(cd, v)
+ inheritKV = function( cd, k, v )
+
+ -- don't merge inheritance controls
+ if k == '_merge' or k == '_verbatim' then
+ return
+ end
+
+ local dtype = type( cd [ k ] )
+
+ if type( v ) == 'table' then
+
+ if dtype == 'nil' then
+ cd[ k ] = { }
+ inherit( cd[ k ], v )
+ elseif
+ dtype == 'table' and
+ v._merge ~= false
+ then
+ inherit( cd[ k ], v )
end
+
+ elseif dtype == 'nil' then
+ cd[ k ] = v
end
+
end
- -----
+
+ --
-- Adds a new sync (directory-tree to observe).
--
- local function add(config)
- -- Creates a new config table and inherit all keys/values
+ local function add( config )
+
+ -- workaround for backwards compatibility
+ -- FIXME: remove when dropping that
+ if settings ~= settingsSafe then
+ log(
+ 'Warn',
+ 'settings = { ... } is deprecated.\n'..
+ ' please use settings{ ... } (without the equal sign)'
+ )
+
+ for k, v in pairs( settings ) do
+ uSettings[ k ] = v
+ end
+
+ settings = settingsSafe
+ end
+
+ -- Creates a new config table which inherits all keys/values
-- from integer keyed tables
local uconfig = config
- config = {}
- inherit(config, uconfig)
- -- Lets settings or commandline override delay values.
- if settings then
- config.delay = settings.delay or config.delay
+ config = { }
+
+ inherit( config, uconfig )
+
+ --
+ -- last and least defaults are inherited
+ --
+ inherit( config, default )
+
+ local inheritSettings = {
+ 'delay',
+ 'maxDelays',
+ 'maxProcesses'
+ }
+
+ -- Lets settings override these values.
+ for _, v in ipairs( inheritSettings ) do
+ if uSettings[ v ] then
+ config[ v ] = uSettings[ v ]
+ end
+ end
+
+ -- Lets commandline override these values.
+ for _, v in ipairs( inheritSettings ) do
+ if clSettings[ v ] then
+ config[ v ] = clSettings[ v ]
+ end
end
- -- at very first lets the userscript 'prepare' function
- -- fill out more values.
- if type(config.prepare) == 'function' then
- -- explicitly gives a writeable copy of config.
- config.prepare(config)
+ --
+ -- lets the userscript 'prepare' function
+ -- check and complete the config
+ --
+ if type( config.prepare ) == 'function' then
+
+ -- prepare is given a writeable copy of config
+ config.prepare( config, 4 )
+
end
- if not config['source'] then
- local info = debug.getinfo(3, 'Sl')
- log('Error', info.short_src,':',info.currentline,': source missing from sync.')
- terminate(-1) -- ERRNO
+ if not config[ 'source' ] then
+ local info = debug.getinfo( 3, 'Sl' )
+ log(
+ 'Error',
+ info.short_src,':',
+ info.currentline,': source missing from sync.'
+ )
+ terminate( -1 )
end
+ --
-- absolute path of source
- local realsrc = lsyncd.realdir(config.source)
+ --
+ local realsrc = lsyncd.realdir( config.source )
+
if not realsrc then
- log('Error', 'Cannot access source directory: ',config.source)
- terminate(-1) -- ERRNO
+ log(
+ 'Error',
+ 'Cannot access source directory: ',
+ config.source
+ )
+ terminate( -1 )
end
+
config._source = config.source
config.source = realsrc
- if not config.action and not config.onAttrib and
- not config.onCreate and not config.onModify and
- not config.onDelete and not config.onMove
+ if
+ not config.action and
+ not config.onAttrib and
+ not config.onCreate and
+ not config.onModify and
+ not config.onDelete and
+ not config.onMove
then
- local info = debug.getinfo(3, 'Sl')
- log('Error', info.short_src, ':', info.currentline,
- ': no actions specified, use e.g. "config = default.rsync".')
- terminate(-1) -- ERRNO
- end
+ local info = debug.getinfo( 3, 'Sl' )
+ log(
+ 'Error',
+ info.short_src, ':',
+ info.currentline,
+ ': no actions specified.'
+ )
- -- loads a default value for an option if not existent
- if not settings then
- settings = {}
- end
- local defaultValues = {
- 'action',
- 'collect',
- 'init',
- 'maxDelays',
- 'maxProcesses',
- }
- for _, dn in pairs(defaultValues) do
- if config[dn] == nil then
- config[dn] = settings[dn] or default[dn]
- end
+ terminate( -1 )
end
-- the monitor to use
config.monitor =
- settings.monitor or config.monitor or Monitors.default()
- if config.monitor ~= 'inotify' and config.monitor ~= 'fsevents' then
- local info = debug.getinfo(3, 'Sl')
- log('Error',info.short_src,':',info.currentline,
- ': event monitor "',config.monitor,'" unknown.')
- terminate(-1) -- ERRNO
+ uSettings.monitor or
+ config.monitor or
+ Monitors.default( )
+
+ if
+ config.monitor ~= 'inotify' and
+ config.monitor ~= 'fsevents'
+ then
+ local info = debug.getinfo( 3, 'Sl' )
+
+ log(
+ 'Error',
+ info.short_src, ':',
+ info.currentline,
+ ': event monitor "',
+ config.monitor,
+ '" unknown.'
+ )
+
+ terminate( -1 )
end
--- creates the new sync
- local s = Sync.new(config)
- table.insert(list, s)
+ local s = Sync.new( config )
+
+ table.insert( syncsList, s )
+
return s
end
- -----
+ --
-- Allows a for-loop to walk through all syncs.
--
- local function iwalk()
- return ipairs(list)
+ local function iwalk( )
+ return ipairs( syncsList )
end
- -----
+ --
-- Returns the number of syncs.
--
- local size = function()
- return #list
+ local size = function( )
+ return #syncsList
end
- ------
+ --
-- Tests if any sync is interested in a path.
--
- local function concerns(path)
- for _, s in ipairs(list) do
- if s:concerns(path) then
+ local function concerns( path )
+ for _, s in ipairs( syncsList ) do
+ if s:concerns( path ) then
return true
end
end
+
return false
end
- -- public interface
+ --
+ -- Public interface
+ --
return {
add = add,
get = get,
@@ -1771,73 +2446,91 @@
nextRound = nextRound,
size = size
}
-end)()
+end )( )
------
--- Utility function, returns the relative part of absolute path if it
+--
+-- Utility function,
+-- Returns the relative part of absolute path if it
-- begins with root
--
-local function splitPath(path, root)
+local function splitPath( path, root )
+
local rlen = #root
- local sp = string.sub(path, 1, rlen)
+ local sp = string.sub( path, 1, rlen )
if sp == root then
- return string.sub(path, rlen, -1)
+ return string.sub( path, rlen, -1 )
else
return nil
end
end
------
--- Interface to inotify, watches recursively subdirs and
--- sends events.
--
--- All inotify specific implementation should be enclosed here.
+-- Interface to inotify.
--
-local Inotify = (function()
+-- watches recursively subdirs and sends events.
+--
+-- All inotify specific implementation is enclosed here.
+--
+local Inotify = ( function( )
- -----
- -- A list indexed by inotifies watch descriptor yielding the
- -- directories absolute paths.
--
- local wdpaths = CountArray.new()
+ -- A list indexed by inotify watch descriptors yielding
+ -- the directories absolute paths.
+ --
+ local wdpaths = CountArray.new( )
- -----
- -- The same vice versa, all watch descriptors by its
- -- absolute path.
--
- local pathwds = {}
+ -- The same vice versa,
+ -- all watch descriptors by their absolute paths.
+ --
+ local pathwds = { }
- -----
- -- A list indexed by sync's containing the root path this
- -- sync is interested in.
--
- local syncRoots = {}
+ -- A list indexed by syncs containing yielding
+ -- the root paths the syncs are interested in.
+ --
+ local syncRoots = { }
- -----
+ --
-- Stops watching a directory
--
- -- @param path absolute path to unwatch
- -- @param core if false not actually send the unwatch to the kernel
- -- (used in moves which reuse the watch)
- --
- local function removeWatch(path, core)
- local wd = pathwds[path]
- if not wd then return end
- if core then lsyncd.inotify.rmwatch(wd) end
- wdpaths[wd] = nil
- pathwds[path] = nil
+ -- path ... absolute path to unwatch
+ -- core ... if false not actually send the unwatch to the kernel
+ -- (used in moves which reuse the watch)
+ --
+ local function removeWatch( path, core )
+
+ local wd = pathwds[ path ]
+
+ if not wd then
+ return
+ end
+
+ if core then
+ lsyncd.inotify.rmwatch( wd )
+ end
+
+ wdpaths[ wd ] = nil
+ pathwds[ path ] = nil
end
- -----
+
+ --
-- Adds watches for a directory (optionally) including all subdirectories.
--
-- @param path absolute path of directory to observe
-- @param recurse true if recursing into subdirs
--
local function addWatch(path)
- log('Function','Inotify.addWatch(',path,')')
+
+ log(
+ 'Function',
+ 'Inotify.addWatch( ',
+ path,
+ ' )'
+ )
if not Syncs.concerns(path) then
log('Inotify', 'not concerning "',path,'"')
@@ -1845,93 +2538,139 @@
end
-- registers the watch
- local inotifyMode = (settings and settings.inotifyMode) or '';
- local wd = lsyncd.inotify.addwatch(path, inotifyMode);
+ local inotifyMode = ( uSettings and uSettings.inotifyMode ) or '';
+
+ local wd = lsyncd.inotify.addwatch( path, inotifyMode) ;
+
if wd < 0 then
- log('Inotify','Unable to add watch "',path,'"')
+ log( 'Inotify','Unable to add watch "', path, '"' )
return
end
do
-- If this watch descriptor is registered already
-- the kernel reuses it since old dir is gone.
- local op = wdpaths[wd]
+ local op = wdpaths[ wd ]
if op and op ~= path then
- pathwds[op] = nil
+ pathwds[ op ] = nil
end
end
- pathwds[path] = wd
- wdpaths[wd] = path
+
+ pathwds[ path ] = wd
+ wdpaths[ wd ] = path
-- registers and adds watches for all subdirectories
- local entries = lsyncd.readdir(path)
- if not entries then return end
- for dirname, isdir in pairs(entries) do
- if isdir then addWatch(path .. dirname .. '/') end
+ local entries = lsyncd.readdir( path )
+
+ if not entries then
+ return
+ end
+
+ for dirname, isdir in pairs( entries ) do
+ if isdir then
+ addWatch( path .. dirname .. '/' )
+ end
end
end
- -----
+ --
-- Adds a Sync to receive events.
--
-- sync: Object to receive events
-- rootdir: root dir to watch
--
- local function addSync(sync, rootdir)
- if syncRoots[sync] then error('duplicate sync in Inotify.addSync()') end
- syncRoots[sync] = rootdir
- addWatch(rootdir)
+ local function addSync( sync, rootdir )
+ if syncRoots[ sync ] then
+ error( 'duplicate sync in Inotify.addSync()' )
+ end
+ syncRoots[ sync ] = rootdir
+ addWatch( rootdir )
end
- -----
- -- Called when an event has occured.
--
- -- etype: 'Attrib', 'Modify', 'Create', 'Delete', 'Move'
- -- wd: watch descriptor, matches lsyncd.inotifyadd()
- -- isdir: true if filename is a directory
- -- time: time of event
- -- filename: string filename without path
- -- wd2: watch descriptor for target if it's a Move
- -- filename2: string filename without path of Move target
+ -- Called when an event has occured.
--
- local function event(etype, wd, isdir, time, filename, wd2, filename2)
+ local function event(
+ etype, -- 'Attrib', 'Modify', 'Create', 'Delete', 'Move'
+ wd, -- watch descriptor, matches lsyncd.inotifyadd()
+ isdir, -- true if filename is a directory
+ time, -- time of event
+ filename, -- string filename without path
+ wd2, -- watch descriptor for target if it's a Move
+ filename2 -- string filename without path of Move target
+ )
if isdir then
- filename = filename..'/'
- if filename2 then filename2 = filename2..'/' end
+ filename = filename .. '/'
+
+ if filename2 then
+ filename2 = filename2 .. '/'
+ end
end
if filename2 then
- log('Inotify','got event ',etype,' ',filename,'(',wd,') to ',filename2,'(',wd2,')')
+ log(
+ 'Inotify',
+ 'got event ',
+ etype,
+ ' ',
+ filename,
+ '(', wd, ') to ',
+ filename2,
+ '(', wd2 ,')'
+ )
else
- log('Inotify','got event ',etype,' ',filename,'(',wd,')')
+ log(
+ 'Inotify',
+ 'got event ',
+ etype,
+ ' ',
+ filename,
+ '(', wd, ')'
+ )
end
-- looks up the watch descriptor id
- local path = wdpaths[wd]
- if path then path = path..filename end
+ local path = wdpaths[ wd ]
+ if path then
+ path = path..filename
+ end
- local path2 = wd2 and wdpaths[wd2]
- if path2 and filename2 then path2 = path2..filename2 end
+ local path2 = wd2 and wdpaths[ wd2 ]
+
+ if path2 and filename2 then
+ path2 = path2..filename2
+ end
if not path and path2 and etype == 'Move' then
- log('Inotify', 'Move from deleted directory ',path2,' becomes Create.')
- path = path2
+ log(
+ 'Inotify',
+ 'Move from deleted directory ',
+ path2,
+ ' becomes Create.'
+ )
+ path = path2
path2 = nil
etype = 'Create'
end
if not path then
-- this is normal in case of deleted subdirs
- log('Inotify', 'event belongs to unknown watch descriptor.')
+ log(
+ 'Inotify',
+ 'event belongs to unknown watch descriptor.'
+ )
return
end
- for sync, root in pairs(syncRoots) do repeat
- local relative = splitPath(path, root)
+ for sync, root in pairs( syncRoots ) do repeat
+
+ local relative = splitPath( path, root )
local relative2 = nil
+
if path2 then
- relative2 = splitPath(path2, root)
+ relative2 = splitPath( path2, root )
end
+
if not relative and not relative2 then
-- sync is not interested in this dir
break -- continue
@@ -1939,103 +2678,144 @@
-- makes a copy of etype to possibly change it
local etyped = etype
+
if etyped == 'Move' then
if not relative2 then
- log('Normal', 'Transformed Move to Delete for ', sync.config.name)
+ log(
+ 'Normal',
+ 'Transformed Move to Delete for ',
+ sync.config.name
+ )
etyped = 'Delete'
elseif not relative then
relative = relative2
relative2 = nil
- log('Normal', 'Transformed Move to Create for ', sync.config.name)
+ log(
+ 'Normal',
+ 'Transformed Move to Create for ',
+ sync.config.name
+ )
etyped = 'Create'
end
end
if isdir then
if etyped == 'Create' then
- addWatch(path)
+ addWatch( path )
elseif etyped == 'Delete' then
- removeWatch(path, true)
+ removeWatch( path, true )
elseif etyped == 'Move' then
- removeWatch(path, false)
- addWatch(path2)
+ removeWatch( path, false )
+ addWatch( path2 )
end
end
- sync:delay(etyped, time, relative, relative2)
+ sync:delay( etyped, time, relative, relative2 )
+
until true end
end
- -----
- -- Writes a status report about inotifies to a filedescriptor
--
- local function statusReport(f)
- f:write('Inotify watching ',wdpaths:size(),' directories\n')
- for wd, path in wdpaths:walk() do
- f:write(' ',wd,': ',path,'\n')
+ -- Writes a status report about inotify to a file descriptor
+ --
+ local function statusReport( f )
+
+ f:write( 'Inotify watching ', wdpaths:size(), ' directories\n' )
+
+ for wd, path in wdpaths:walk( ) do
+ f:write( ' ', wd, ': ', path, '\n' )
end
end
- -- public interface
+
+ --
+ -- Public interface.
+ --
return {
addSync = addSync,
event = event,
statusReport = statusReport,
}
-end)()
-----
--- Interface to OSX /dev/fsevents, watches the whole filesystems
+end)( )
+
+--
+-- Interface to OSX /dev/fsevents
--
--- All fsevents specific implementation should be enclosed here.
+-- This watches all the filesystems at once,
+-- but needs root access.
--
-local Fsevents = (function()
+-- All fsevents specific implementation are enclosed here.
+--
+local Fsevents = ( function( )
- -----
- -- A list indexed by sync's containing the root path this
- -- sync is interested in.
+
+ --
+ -- A list indexed by syncs yielding
+ -- the root path the sync is interested in.
--
- local syncRoots = {}
+ local syncRoots = { }
+
- -----
- -- adds a Sync to receive events
+ --
+ -- Adds a Sync to receive events.
--
-- @param sync Object to receive events
-- @param dir dir to watch
--
- local function addSync(sync, dir)
- if syncRoots[sync] then error('duplicate sync in Fanotify.addSync()') end
- syncRoots[sync] = dir
+ local function addSync( sync, dir )
+
+ if syncRoots[ sync ] then
+ error( 'duplicate sync in Fanotify.addSync()' )
+ end
+
+ syncRoots[ sync ] = dir
+
end
- -----
- -- Called when any event has occured.
--
- -- etype: 'Attrib', 'Modify', 'Create', 'Delete', 'Move')
- -- isdir: true if filename is a directory
- -- time: time of event
- -- path: path of file
- -- path2: path of target in case of 'Move'
+ -- Called when an event has occured.
--
- local function event(etype, isdir, time, path, path2)
+ local function event(
+ etype, -- 'Attrib', 'Modify', 'Create', 'Delete', 'Move'
+ isdir, -- true if filename is a directory
+ time, -- time of event
+ path, -- path of file
+ path2 -- path of target in case of 'Move'
+ )
if isdir then
- path = path..'/'
- if path2 then path2 = path2..'/' end
+ path = path .. '/'
+
+ if path2 then
+ path2 = path2 .. '/'
+ end
end
- log('Fsevents',etype,',',isdir,',',time,',',path,',',path2)
+ log(
+ 'Fsevents',
+ etype, ',',
+ isdir, ',',
+ time, ',',
+ path, ',',
+ path2
+ )
for _, sync in Syncs.iwalk() do repeat
+
local root = sync.source
- if not path:starts(root) then
- if not path2 or not path2:starts(root) then
+
+ -- TODO combine ifs
+ if not path:starts( root ) then
+ if not path2 or not path2:starts( root ) then
break -- continue
end
end
- local relative = splitPath(path, root)
+
+ local relative = splitPath( path, root )
+
local relative2
if path2 then
- relative2 = splitPath(path2, root)
+ relative2 = splitPath( path2, root )
end
-- possibly change etype for this iteration only
@@ -2051,66 +2831,82 @@
etyped = 'Create'
end
end
- sync:delay(etyped, time, relative, relative2)
+
+ sync:delay( etyped, time, relative, relative2 )
+
until true end
+
end
- -----
- -- Writes a status report about inotifies to a filedescriptor
+
--
- local function statusReport(f)
+ -- Writes a status report about fsevents to a filedescriptor.
+ --
+ local function statusReport( f )
-- TODO
end
- -- public interface
+ --
+ -- Public interface
+ --
return {
- addSync = addSync,
- event = event,
+ addSync = addSync,
+ event = event,
statusReport = statusReport
}
-end)()
+end )( )
------
+
+--
-- Holds information about the event monitor capabilities
-- of the core.
--
-Monitors = (function()
+Monitors = ( function( )
- -----
+
+ --
-- The cores monitor list
--
- local list = {}
+ local list = { }
- -----
+
+ --
-- The default event monitor.
--
- local function default()
- return list[1]
+ local function default( )
+ return list[ 1 ]
end
- -----
- -- initializes with info received from core
+
+ --
+ -- Initializes with info received from core
--
- local function initialize(clist)
- for k, v in ipairs(clist) do
- list[k] = v
+ local function initialize( clist )
+ for k, v in ipairs( clist ) do
+ list[ k ] = v
end
end
- -- public interface
- return { default = default,
- list = list,
- initialize = initialize
+
+ --
+ -- Public interface
+ --
+ return {
+ default = default,
+ list = list,
+ initialize = initialize
}
-end)()
-------
--- Writes functions for the user for layer 3 configuration.
+end)( )
+
--
-local functionWriter = (function()
+-- Writes functions for the user for layer 3 configurations.
+--
+local functionWriter = ( function( )
- -----
- -- all variables for layer 3
+ --
+ -- All variables known to layer 3 configs.
+ --
transVars = {
{ '%^pathname', 'event.pathname', 1 },
{ '%^pathdir', 'event.pathdir', 1 },
@@ -2141,23 +2937,27 @@
{ '%^d%.targetPath', 'event2.targetPath', 2 },
}
- -----
- -- Splits a user string into its arguments
- --
- -- @param a string where parameters are seperated by spaces.
--
- -- @return a table of arguments
+ -- Splits a user string into its arguments.
+ -- Returns a table of arguments
--
- local function splitStr(str)
- local args = {}
+ local function splitStr(
+ str -- a string where parameters are seperated by spaces.
+ )
+ local args = { }
+
while str ~= '' do
+
-- break where argument stops
local bp = #str
+
-- in a quote
local inQuote = false
+
-- tests characters to be space and not within quotes
- for i=1,#str do
- local c = string.sub(str, i, i)
+ for i=1, #str do
+ local c = string.sub( str, i, i )
+
if c == '"' then
inQuote = not inQuote
elseif c == ' ' and not inQuote then
@@ -2165,47 +2965,60 @@
break
end
end
- local arg = string.sub(str, 1, bp)
- arg = string.gsub(arg, '"', '\\"')
- table.insert(args, arg)
- str = string.sub(str, bp + 1, -1)
- str = string.match(str, '^%s*(.-)%s*$')
- end
+
+ local arg = string.sub( str, 1, bp )
+ arg = string.gsub( arg, '"', '\\"' )
+ table.insert( args, arg )
+ str = string.sub( str, bp + 1, -1 )
+ str = string.match( str, '^%s*(.-)%s*$' )
+
+ end
+
return args
end
- -----
- -- Translates a call to a binary to a lua function.
+
--
- -- TODO this has a little too much coding blocks.
+ -- Translates a call to a binary to a lua function.
+ -- TODO this has a little too blocking.
--
- local function translateBinary(str)
+ local function translateBinary( str )
+
-- splits the string
- local args = splitStr(str)
+ local args = splitStr( str )
-- true if there is a second event
local haveEvent2 = false
- for ia, iv in ipairs(args) do
+ for ia, iv in ipairs( args ) do
+
-- a list of arguments this arg is being split into
- local a = {{true, iv}}
+ local a = { { true, iv } }
+
-- goes through all translates
- for _, v in ipairs(transVars) do
+ for _, v in ipairs( transVars ) do
local ai = 1
while ai <= #a do
- if a[ai][1] then
+ if a[ ai ][ 1 ] then
local pre, post =
- string.match(a[ai][2], '(.*)"..v[1].."(.*)')
+ string.match( a[ ai ][ 2 ], '(.*)"..v[1].."(.*)' )
+
if pre then
+
if v[3] > 1 then
haveEvent2 = true
end
+
if pre ~= '' then
- table.insert(a, ai, {true, pre})
+ table.insert( a, ai, { true, pre } )
ai = ai + 1
end
- a[ai] = {false, v[2]}
- if post ~= '' then table.insert(a, ai + 1, {true, post}) end
+
+ a[ ai ] = { false, v[ 2 ] }
+
+ if post ~= '' then
+ table.insert( a, ai + 1, { true, post } )
+ end
end
end
ai = ai + 1
@@ -2215,18 +3028,23 @@
-- concats the argument pieces into a string.
local as = ''
local first = true
- for _, v in ipairs(a) do
+
+ for _, v in ipairs( a ) do
+
if not first then
as = as..' .. '
end
- if v[1] then
- as = as..'"'..v[2]..'"'
+
+ if v[ 1 ] then
+ as = as .. '"' .. v[ 2 ] .. '"'
else
- as = as..v[2]
+ as = as .. v[ 2 ]
end
+
first = false
end
- args[ia] = as
+
+ args[ ia ] = as
end
local ft
@@ -2235,217 +3053,327 @@
else
ft = 'function(event, event2)\n'
end
- ft = ft..
- " log('Normal', 'Event ', event.etype, \n"..
- " ' spawns action \"".. str.."\"')\n"..
+
+ ft = ft ..
+ " log('Normal', 'Event ', event.etype, \n" ..
+ " ' spawns action \"".. str.."\"')\n" ..
" spawn(event"
- for _, v in ipairs(args) do
- ft = ft..',\n '..v
+
+ for _, v in ipairs( args ) do
+ ft = ft .. ',\n ' .. v
end
- ft = ft..')\nend'
+
+ ft = ft .. ')\nend'
return ft
+
end
- -----
+
+ --
-- Translates a call using a shell to a lua function
--
- local function translateShell(str)
+ local function translateShell( str )
+
local argn = 1
- local args = {}
+ local args = { }
local cmd = str
local lc = str
+
-- true if there is a second event
local haveEvent2 = false
- for _, v in ipairs(transVars) do
+ for _, v in ipairs( transVars ) do
+
local occur = false
- cmd = string.gsub(cmd, v[1],
- function()
+
+ cmd = string.gsub(
+ cmd,
+ v[ 1 ],
+ function( )
occur = true
- return '"$'..argn..'"'
- end)
- lc = string.gsub(lc, v[1], ']]..'..v[2]..'..[[')
+ return '"$' .. argn .. '"'
+ end
+ )
+
+ lc = string.gsub(
+ lc,
+ v[1],
+ ']]..' .. v[2] .. '..[['
+ )
+
if occur then
argn = argn + 1
- table.insert(args, v[2])
- if v[3] > 1 then
+ table.insert( args, v[ 2 ] )
+
+ if v[ 3 ] > 1 then
haveEvent2 = true
end
end
+
end
+
local ft
if not haveEvent2 then
ft = 'function(event)\n'
else
ft = 'function(event, event2)\n'
end
+
-- TODO do array joining instead
ft = ft..
" log('Normal', 'Event ',event.etype,\n"..
" [[ spawns shell \""..lc.."\"]])\n"..
" spawnShell(event, [["..cmd.."]]"
- for _, v in ipairs(args) do
+
+ for _, v in ipairs( args ) do
ft = ft..',\n '..v
end
- ft = ft..')\nend'
+
+ ft = ft .. ')\nend'
+
return ft
+
end
- -----
- -- writes a lua function for a layer 3 user script.
- local function translate(str)
+ --
+ -- Writes a lua function for a layer 3 user script.
+ --
+ local function translate( str )
-- trim spaces
- str = string.match(str, '^%s*(.-)%s*$')
+ str = string.match( str, '^%s*(.-)%s*$' )
local ft
- if string.byte(str, 1, 1) == 47 then
+ if string.byte( str, 1, 1 ) == 47 then
-- starts with /
- ft = translateBinary(str)
- elseif string.byte(str, 1, 1) == 94 then
+ ft = translateBinary( str )
+ elseif string.byte( str, 1, 1 ) == 94 then
-- starts with ^
- ft = translateShell(str:sub(2, -1))
+ ft = translateShell( str:sub( 2, -1 ) )
else
- ft = translateShell(str)
+ ft = translateShell( str )
end
- log('FWrite','translated "',str,'" to \n',ft)
+
+ log(
+ 'FWrite',
+ 'translated "',
+ str,
+ '" to \n',
+ ft
+ )
+
return ft
end
- -----
- -- public interface
+
--
- return {translate = translate}
-end)()
+ -- Public interface.
+ --
+ return { translate = translate }
+
+
+end )( )
+
-----
--- Writes a status report file at most every [statusintervall] seconds.
--
+-- Writes a status report file at most every [statusintervall] seconds.
--
-local StatusFile = (function()
+local StatusFile = ( function( )
- -----
+
+ --
-- Timestamp when the status file has been written.
+ --
local lastWritten = false
- -----
- -- Timestamp when a status file should be written
+
+ --
+ -- Timestamp when a status file should be written.
+ --
local alarm = false
- -----
- -- Returns when the status file should be written
+
+ --
+ -- Returns the alarm when the status file should be written-
--
local function getAlarm()
return alarm
end
- -----
+
+ --
-- Called to check if to write a status file.
--
- local function write(timestamp)
- log('Function', 'write(', timestamp, ')')
+ local function write( timestamp )
+
+ log(
+ 'Function',
+ 'write( ',
+ timestamp,
+ ' )'
+ )
+
+ --
+ -- takes care not write too often
+ --
+ if uSettings.statusInterval > 0 then
- -- some logic to not write too often
- if settings.statusInterval > 0 then
- -- already waiting
+ -- already waiting?
if alarm and timestamp < alarm then
- log('Statusfile', 'waiting(',timestamp,' < ',alarm,')')
+ log(
+ 'Statusfile',
+ 'waiting(',
+ timestamp,
+ ' < ',
+ alarm,
+ ')'
+ )
return
end
+
-- determines when a next write will be possible
if not alarm then
+
local nextWrite =
- lastWritten and timestamp + settings.statusInterval
+ lastWritten and timestamp +
+ uSettings.statusInterval
+
if nextWrite and timestamp < nextWrite then
- log('Statusfile', 'setting alarm: ', nextWrite)
+ log(
+ 'Statusfile',
+ 'setting alarm: ',
+ nextWrite
+ )
alarm = nextWrite
+
return
end
end
+
lastWritten = timestamp
alarm = false
end
- log('Statusfile', 'writing now')
- local f, err = io.open(settings.statusFile, 'w')
+ log( 'Statusfile', 'writing now' )
+
+ local f, err = io.open( uSettings.statusFile, 'w' )
+
if not f then
- log('Error', 'Cannot open status file "'..settings.statusFile.. '" :'..err)
+ log(
+ 'Error',
+ 'Cannot open status file "' ..
+ uSettings.statusFile ..
+ '" :' ..
+ err
+ )
return
end
- f:write('Lsyncd status report at ',os.date(),'\n\n')
- for i, s in Syncs.iwalk() do
- s:statusReport(f)
- f:write('\n')
+
+ f:write( 'Lsyncd status report at ', os.date( ), '\n\n' )
+
+ for i, s in Syncs.iwalk( ) do
+ s:statusReport( f )
+ f:write( '\n' )
end
- Inotify.statusReport(f)
- f:close()
+ Inotify.statusReport( f )
+ f:close( )
end
- -- public interface
- return {write = write, getAlarm = getAlarm}
-end)()
-------
--- Lets the userscript make its own alarms.
+ --
+ -- Public interface
+ --
+ return {
+ write = write,
+ getAlarm = getAlarm
+ }
+
+end )( )
+
+
+--
+-- Lets userscripts make their own alarms.
--
-local UserAlarms = (function()
- local alarms = {}
+local UserAlarms = ( function( )
- -----
+ local alarms = { }
+
+
+ --
-- Calls the user function at timestamp.
--
- local function alarm(timestamp, func, extra)
+ local function alarm( timestamp, func, extra )
+
local idx
- for k, v in ipairs(alarms) do
+ for k, v in ipairs( alarms ) do
if timestamp < v.timestamp then
idx = k
break
end
end
- local a = {timestamp = timestamp,
- func = func,
- extra = extra}
+
+ local a = {
+ timestamp = timestamp,
+ func = func,
+ extra = extra
+ }
+
if idx then
- table.insert(alarms, idx, a)
+ table.insert( alarms, idx, a )
else
- table.insert(alarms, a)
+ table.insert( alarms, a )
end
+
end
- ----
- -- Retrieves the nearest alarm.
+
--
- local function getAlarm()
+ -- Retrieves the soonest alarm.
+ --
+ local function getAlarm( )
+
if #alarms == 0 then
return false
else
return alarms[1].timestamp
end
+
end
- -----
+
+ --
-- Calls user alarms.
--
- local function invoke(timestamp)
- while #alarms > 0 and alarms[1].timestamp <= timestamp do
- alarms[1].func(alarms[1].timestamp, alarms[1].extra)
- table.remove(alarms, 1)
+ local function invoke( timestamp )
+ while
+ #alarms > 0 and
+ alarms[ 1 ].timestamp <= timestamp
+ do
+ alarms[ 1 ].func( alarms[ 1 ].timestamp, alarms[ 1 ].extra )
+ table.remove( alarms, 1 )
end
end
- -- public interface
- return { alarm = alarm,
- getAlarm = getAlarm,
- invoke = invoke }
-end)()
+
+ --
+ -- Public interface
+ --
+ return {
+ alarm = alarm,
+ getAlarm = getAlarm,
+ invoke = invoke
+ }
+
+
+end )( )
--============================================================================
--- lsyncd runner plugs. These functions will be called from core.
+-- Lsyncd runner's plugs. These functions are called from core.
--============================================================================
------
--- Current status of lsyncd.
+--
+-- Current status of Lsyncd.
--
-- 'init' ... on (re)init
-- 'run' ... normal operation
@@ -2453,96 +3381,149 @@
--
local lsyncdStatus = 'init'
-----
--- the cores interface to the runner
--
-local runner = {}
+-- The cores interface to the runner.
+--
+local runner = { }
------
--- Called from core whenever lua code failed.
+--
+-- Last time said to be waiting for more child processes
+--
+local lastReportedWaiting = false
+
+--
+-- Called from core whenever Lua code failed.
+--
-- Logs a backtrace
--
-function runner.callError(message)
- log('Error', 'IN LUA: ', message)
+function runner.callError( message )
+ log('Error', 'in Lua: ', message )
+
-- prints backtrace
local level = 2
while true do
- local info = debug.getinfo(level, 'Sl')
+
+ local info = debug.getinfo( level, 'Sl' )
+
if not info then
- terminate(-1) -- ERRNO
+ terminate( -1 )
end
- log('Error', 'Backtrace ',level - 1,' :',info.short_src,':',info.currentline)
+
+ log(
+ 'Error',
+ 'Backtrace ',
+ level - 1, ' :',
+ info.short_src, ':',
+ info.currentline
+ )
+
level = level + 1
end
end
------
--- Called from code whenever a child process finished and
--- zombie process was collected by core.
+
--
-function runner.collectProcess(pid, exitcode)
+-- Called from core whenever a child process has finished and
+-- the zombie process was collected by core.
+--
+function runner.collectProcess( pid, exitcode )
+
processCount = processCount - 1
- if processCount < 0 then error('negative number of processes!') end
+
+ if processCount < 0 then
+ error( 'negative number of processes!' )
+ end
for _, s in Syncs.iwalk() do
if s:collect(pid, exitcode) then return end
end
+
end
------
+--
-- Called from core everytime a masterloop cycle runs through.
+--
-- This happens in case of
-- * an expired alarm.
-- * a returned child process.
-- * received filesystem events.
-- * received a HUP or TERM signal.
--
--- @param timestamp the current kernel time (in jiffies)
---
-function runner.cycle(timestamp)
- -- goes through all syncs and spawns more actions
- -- if possible
+function runner.cycle(
+ timestamp -- the current kernel time (in jiffies)
+)
+
if lsyncdStatus == 'fade' then
+
if processCount > 0 then
- log('Normal', 'waiting for ',processCount,' more child processes.')
+
+ if
+ lastReportedWaiting == false or
+ timestamp >= lastReportedWaiting + 60
+ then
+ lastReportedWaiting = timestamp
+
+ log(
+ 'Normal',
+ 'waiting for ',
+ processCount,
+ ' more child processes.'
+ )
+ end
+
return true
else
+
return false
end
end
+
if lsyncdStatus ~= 'run' then
- error('runner.cycle() called while not running!')
+ error( 'runner.cycle() called while not running!' )
end
- --- only let Syncs invoke actions if not on global limit
- if not settings.maxProcesses or processCount < settings.maxProcesses then
- local start = Syncs.getRound()
+ --
+ -- goes through all syncs and spawns more actions
+ -- if possibly. But only let Syncs invoke actions if
+ -- not at global limit
+ --
+ if
+ not uSettings.maxProcesses or
+ processCount < uSettings.maxProcesses
+ then
+ local start = Syncs.getRound( )
+
local ir = start
+
repeat
- local s = Syncs.get(ir)
- s:invokeActions(timestamp)
+
+ local s = Syncs.get( ir )
+ s:invokeActions( timestamp )
ir = ir + 1
- if ir > Syncs.size() then
+
+ if ir > Syncs.size( ) then
+
ir = 1
end
until ir == start
- Syncs.nextRound()
+
+ Syncs.nextRound( )
end
- UserAlarms.invoke(timestamp)
+ UserAlarms.invoke( timestamp )
- if settings.statusFile then
- StatusFile.write(timestamp)
+ if uSettings.statusFile then
+ StatusFile.write( timestamp )
end
return true
end
------
--- Called by core before anything is '-help' or '--help' is in
+--
+-- Called by core if '-help' or '--help' is in
-- the arguments.
--
-function runner.help()
+function runner.help( )
io.stdout:write(
[[
@@ -2584,483 +3565,790 @@
-- -monitor NAME Uses operating systems event montior NAME
-- (inotify/fanotify/fsevents)
- os.exit(-1) -- ERRNO
+ os.exit( -1 )
end
------
--- settings specified by command line.
--
-local clSettings = {}
-
------
-- Called from core to parse the command line arguments
--- @returns a string as user script to load.
--- or simply 'true' if running with rsync bevaiour
--- terminates on invalid arguments
---
-function runner.configure(args, monitors)
- Monitors.initialize(monitors)
-
- -- a list of all valid --options
- -- first paramter is number of options
- -- if < 0 the function checks existance
- -- second paramter is function to call when in args
+--
+-- returns a string as user script to load.
+-- or simply 'true' if running with rsync bevaiour
+--
+-- terminates on invalid arguments.
+--
+function runner.configure( args, monitors )
+
+ Monitors.initialize( monitors )
+
+ --
+ -- a list of all valid options
+ --
+ -- first paramter is the number of parameters an option takes
+ -- if < 0 the called function has to check the presence of
+ -- optional arguments.
+ --
+ -- second paramter is the function to call
--
local options = {
+
-- log is handled by core already.
- delay =
- {1, function(secs)
- clSettings.delay = secs
- end},
- insist =
- {0, function()
- clSettings.insist = true
- end},
- log =
- {1, nil},
- logfile =
- {1, function(file)
- clSettings.logfile = file
- end},
+
+ delay =
+ {
+ 1,
+ function( secs )
+ clSettings.delay = secs
+ end
+ },
+
+ insist =
+ {
+ 0,
+ function( )
+ clSettings.insist = true
+ end
+ },
+
+ log =
+ {
+ 1,
+ nil
+ },
+
+ logfile =
+ {
+ 1,
+ function( file )
+ clSettings.logfile = file
+ end
+ },
+
monitor =
- {-1, function(monitor)
- if not monitor then
- io.stdout:write('This Lsyncd supports these monitors:\n')
- for _, v in ipairs(Monitors.list) do
- io.stdout:write(' ',v,'\n')
+ {
+ -1,
+ function( monitor )
+ if not monitor then
+ io.stdout:write( 'This Lsyncd supports these monitors:\n' )
+ for _, v in ipairs(Monitors.list) do
+ io.stdout:write(' ',v,'\n')
+ end
+
+ io.stdout:write('\n')
+
+ lsyncd.terminate(-1)
+ else
+ clSettings.monitor = monitor
end
- io.stdout:write('\n');
- lsyncd.terminate(-1); -- ERRNO
- else
- clSettings.monitor=monitor
end
- end},
+ },
+
nodaemon =
- {0, function()
- clSettings.nodaemon = true
- end},
- pidfile =
- {1, function(file)
- clSettings.pidfile=file
- end},
+ {
+ 0,
+ function( )
+ clSettings.nodaemon = true
+ end
+ },
+
+ pidfile =
+ {
+ 1,
+ function( file )
+ clSettings.pidfile=file
+ end
+ },
+
rsync =
- {2, function(src, trg)
- clSettings.syncs = clSettings.syncs or {}
- table.insert(clSettings.syncs, {'rsync', src, trg})
- end},
+ {
+ 2,
+ function( src, trg )
+ clSettings.syncs = clSettings.syncs or { }
+ table.insert(
+ clSettings.syncs,
+ { 'rsync', src, trg }
+ )
+ end
+ },
+
rsyncssh =
- {3, function(src, host, tdir)
- clSettings.syncs = clSettings.syncs or {}
- table.insert(clSettings.syncs, {'rsyncssh', src, host, tdir})
- end},
+ {
+ 3,
+ function( src, host, tdir )
+ clSettings.syncs = clSettings.syncs or { }
+ table.insert(
+ clSettings.syncs,
+ { 'rsyncssh', src, host, tdir }
+ )
+ end
+ },
+
direct =
- {2, function(src, trg)
- clSettings.syncs = clSettings.syncs or {}
- table.insert(clSettings.syncs, {'direct', src, trg})
- end},
- version =
- {0, function()
- io.stdout:write('Version: ',lsyncd_version,'\n')
- os.exit(0)
- end}
+ {
+ 2,
+ function( src, trg )
+ clSettings.syncs = clSettings.syncs or { }
+ table.insert(
+ clSettings.syncs,
+ { 'direct', src, trg }
+ )
+ end
+ },
+
+ version =
+ {
+ 0,
+ function( )
+ io.stdout:write( 'Version: ', lsyncd_version, '\n' )
+ os.exit( 0 )
+ end
+ }
}
- -- nonopts is filled with all args that were no part dash options
- local nonopts = {}
+
+ -- non-opts is filled with all args that were no part dash options
+
+ local nonopts = { }
+
local i = 1
while i <= #args do
- local a = args[i]
- if a:sub(1, 1) ~= '-' then
- table.insert(nonopts, args[i])
+
+ local a = args[ i ]
+
+ if a:sub( 1, 1 ) ~= '-' then
+ table.insert( nonopts, args[ i ] )
else
- if a:sub(1, 2) == '--' then
- a = a:sub(3)
+ if a:sub( 1, 2 ) == '--' then
+ a = a:sub( 3 )
else
- a = a:sub(2)
+ a = a:sub( 2 )
end
- local o = options[a]
+
+ local o = options[ a ]
+
if not o then
- log('Error','unknown option command line option ', args[i])
- os.exit(-1) -- ERRNO
+ log(
+ 'Error',
+ 'unknown option command line option ',
+ args[i]
+ )
+ os.exit( -1 )
end
- if o[1] >= 0 and i + o[1] > #args then
- log('Error',a,' needs ',o[1],' arguments')
- os.exit(-1) -- ERRNO
+
+ if o[ 1 ] >= 0 and i + o[ 1 ] > #args then
+ log( 'Error', a ,' needs ', o[ 1 ],' arguments' )
+ os.exit( -1 )
elseif o[1] < 0 then
- o[1] = -o[1]
+ o[ 1 ] = -o[ 1 ]
end
- if o[2] then
- if o[1] == 0 then
- o[2]()
- elseif o[1] == 1 then
- o[2](args[i + 1])
- elseif o[1] == 2 then
- o[2](args[i + 1], args[i + 2])
- elseif o[1] == 3 then
- o[2](args[i + 1], args[i + 2], args[i + 3])
+
+ if o[ 2 ] then
+ if o[ 1 ] == 0 then
+ o[ 2 ]( )
+ elseif o[ 1 ] == 1 then
+ o[ 2 ]( args[i + 1] )
+ elseif o[ 1 ] == 2 then
+ o[ 2 ]( args[i + 1], args[i + 2] )
+ elseif o[ 1 ] == 3 then
+ o[ 2 ]( args[i + 1], args[i + 2], args[i + 3] )
end
end
i = i + o[1]
end
i = i + 1
+
end
if clSettings.syncs then
+
if #nonopts ~= 0 then
- log('Error', 'There cannot be command line default syncs with a config file.')
- os.exit(-1) -- ERRNO
+ log(
+ 'Error',
+ 'There cannot be command line syncs and config file together.'
+ )
+ os.exit( -1 )
end
+
else
+
if #nonopts == 0 then
- runner.help(args[0])
+
+ runner.help( args[ 0 ] )
+
elseif #nonopts == 1 then
- return nonopts[1]
+
+ return nonopts[ 1 ]
+
else
- log('Error', 'There can only be one config file in command line.')
- os.exit(-1) -- ERRNO
+
+ -- TODO make this possible
+ log(
+ 'Error',
+ 'There can only be one config file in command line.'
+ )
+ os.exit( -1 )
+
end
+
end
end
-----
+--
-- Called from core on init or restart after user configuration.
--
--- @firstTime true the first time Lsyncd startup, false on resets
--- due to HUP signal or monitor queue OVERFLOW.
+-- firstTime:
+-- true when Lsyncd startups the first time,
+-- false on resets, due to HUP signal or monitor queue overflow.
--
-function runner.initialize(firstTime)
- -- creates settings if user didnt
- settings = settings or {}
+function runner.initialize( firstTime )
+
+ if settings ~= settingsSafe then
+ log(
+ 'Warn',
+ 'settings = { ... } is deprecated.\n'..
+ ' please use settings{ ... } (without the equal sign)'
+ )
+ for k, v in pairs( settings ) do
+ uSettings[ k ] = v
+ end
+
+ end
+
+ lastReportedWaiting = false
+
+ --
-- From this point on, no globals may be created anymore
- lockGlobals()
+ --
+ lockGlobals( )
- -- copies simple settings with numeric keys to 'key=true' settings.
- for k, v in ipairs(settings) do
- if settings[v] then
- log('Error', 'Double setting "'..v..'"')
- os.exit(-1) -- ERRNO
+ --
+ -- copies simple settings with numeric keys to 'key = true' settings.
+ --
+ -- FIXME this can be removed when
+ -- Lsyncd 2.0.x backwards compatibility is dropped
+ --
+ for k, v in ipairs( uSettings ) do
+
+ if uSettings[ v ] then
+ log(
+ 'Error',
+ 'Double setting "' .. v.. '"'
+ )
+ os.exit( -1 )
end
- settings[v]=true
+
+ uSettings[ v ]= true
+
end
+ --
-- all command line settings overwrite config file settings
- for k, v in pairs(clSettings) do
+ --
+ for k, v in pairs( clSettings ) do
if k ~= 'syncs' then
- settings[k]=v
+ uSettings[ k ] = v
end
end
- -- implicitly force insist to be true on Lsyncd resets.
+ --
+ -- implicitly forces 'insist' on Lsyncd resets.
+ --
if not firstTime then
- settings.insist = true
+ uSettings.insist = true
end
+ --
-- adds syncs specified by command line.
+ --
if clSettings.syncs then
- for _, s in ipairs(clSettings.syncs) do
- if s[1] == 'rsync' then
- sync{default.rsync, source=s[2], target=s[3]}
- elseif s[1] == 'rsyncssh' then
- sync{default.rsyncssh, source=s[2], host=s[3], targetdir=s[4]}
- elseif s[1] == 'direct' then
- sync{default.direct, source=s[2], target=s[3]}
+
+ for _, s in ipairs( clSettings.syncs ) do
+
+ if s[ 1 ] == 'rsync' then
+
+ sync{
+ default.rsync,
+ source = s[ 2 ],
+ target = s[ 3 ]
+ }
+
+ elseif s[ 1 ] == 'rsyncssh' then
+
+ sync{
+ default.rsyncssh,
+ source = s[ 2 ],
+ host = s[ 3 ],
+ targetdir=s[ 4 ]
+ }
+
+ elseif s[ 1 ] == 'direct' then
+ sync{
+ default.direct,
+ source=s[ 2 ],
+ target=s[ 3 ]
+ }
+
end
+
end
+
end
- if settings.nodaemon then
- lsyncd.configure('nodaemon')
+ if uSettings.nodaemon then
+ lsyncd.configure( 'nodaemon' )
end
- if settings.logfile then
- lsyncd.configure('logfile', settings.logfile)
+
+ if uSettings.logfile then
+ lsyncd.configure( 'logfile', uSettings.logfile )
end
- if settings.logident then
- lsyncd.configure('logident', settings.logident)
+
+ if uSettings.logident then
+ lsyncd.configure( 'logident', uSettings.logident )
end
- if settings.logfacility then
- lsyncd.configure('logfacility', settings.logfacility)
+
+ if uSettings.logfacility then
+ lsyncd.configure( 'logfacility', uSettings.logfacility )
end
- if settings.pidfile then
- lsyncd.configure('pidfile', settings.pidfile)
+
+ if uSettings.pidfile then
+ lsyncd.configure( 'pidfile', uSettings.pidfile )
end
- -----
- -- transfers some defaults to settings
- if settings.statusInterval == nil then
- settings.statusInterval = default.statusInterval
+ --
+ -- Transfers some defaults to uSettings
+ --
+ if uSettings.statusInterval == nil then
+ uSettings.statusInterval = default.statusInterval
end
-- makes sure the user gave Lsyncd anything to do
if Syncs.size() == 0 then
- log('Error', 'Nothing to watch!')
- os.exit(-1) -- ERRNO
+
+ log(
+ 'Error',
+ 'Nothing to watch!'
+ )
+
+ os.exit( -1 )
end
-- from now on use logging as configured instead of stdout/err.
lsyncdStatus = 'run';
- lsyncd.configure('running');
+
+ lsyncd.configure( 'running' );
local ufuncs = {
- 'onAttrib', 'onCreate', 'onDelete',
- 'onModify', 'onMove', 'onStartup',
+ 'onAttrib',
+ 'onCreate',
+ 'onDelete',
+ 'onModify',
+ 'onMove',
+ 'onStartup',
}
-- translates layer 3 scripts
for _, s in Syncs.iwalk() do
+
-- checks if any user functions is a layer 3 string.
local config = s.config
+
for _, fn in ipairs(ufuncs) do
+
if type(config[fn]) == 'string' then
+
local ft = functionWriter.translate(config[fn])
config[fn] = assert(loadstring('return '..ft))()
+
end
+
end
end
-- runs through the Syncs created by users
- for _, s in Syncs.iwalk() do
+ for _, s in Syncs.iwalk( ) do
+
if s.config.monitor == 'inotify' then
- Inotify.addSync(s, s.source)
+
+ Inotify.addSync( s, s.source )
+
elseif s.config.monitor == 'fsevents' then
- Fsevents.addSync(s, s.source)
+
+ Fsevents.addSync( s, s.source )
+
else
- error('sync '..s.config.name..' has no known event monitor interface.')
+
+ error(
+ 'sync ' ..
+ s.config.name ..
+ ' has no known event monitor interface.'
+ )
+
end
- -- if the sync has an init function, stacks an init delay
- -- that will cause the init function to be called.
+
+ -- if the sync has an init function, the init delay
+ -- is stacked which causes the init function to be called.
if s.config.init then
- s:addInitDelay()
+
+ s:addInitDelay( )
+
end
end
+
end
-----
--- Called by core to query soonest alarm.
+--
+-- Called by core to query the soonest alarm.
--
-- @return false ... no alarm, core can in untimed sleep, or
-- true ... immediate action
-- times ... the alarm time (only read if number is 1)
--
-function runner.getAlarm()
+function runner.getAlarm( )
+
if lsyncdStatus ~= 'run' then
return false
end
+
local alarm = false
- ----
- -- checks if current nearest alarm or a is earlier
+
--
- local function checkAlarm(a)
+ -- Checks if 'a' is sooner than the 'alarm' up-value.
+ --
+ local function checkAlarm( a )
+
if a == nil then
error('got nil alarm')
end
+
if alarm == true or not a then
- -- already immediate or no new alarm
+ -- 'alarm' is already immediate or
+ -- a not a new alarm
return
end
- -- returns the ealier time
+
+ -- sets 'alarm' to a if a is sooner
if not alarm or a < alarm then
alarm = a
end
+
end
- -- checks all syncs for their earliest alarm
+ --
+ -- checks all syncs for their earliest alarm,
-- but only if the global process limit is not yet reached.
- if not settings.maxProcesses or processCount < settings.maxProcesses then
- for _, s in Syncs.iwalk() do
- checkAlarm(s:getAlarm())
+ --
+ if
+ not uSettings.maxProcesses or
+ processCount < uSettings.maxProcesses
+ then
+ for _, s in Syncs.iwalk( ) do
+ checkAlarm( s:getAlarm ( ))
end
else
- log('Alarm', 'at global process limit.')
+ log(
+ 'Alarm',
+ 'at global process limit.'
+ )
end
-- checks if a statusfile write has been delayed
- checkAlarm(StatusFile.getAlarm())
+ checkAlarm( StatusFile.getAlarm( ) )
+
-- checks for an userAlarm
- checkAlarm(UserAlarms.getAlarm())
+ checkAlarm( UserAlarms.getAlarm( ) )
+
+ log(
+ 'Alarm',
+ 'runner.getAlarm returns: ',
+ alarm
+ )
- log('Alarm', 'runner.getAlarm returns: ',alarm)
return alarm
+
end
------
--- Called when an inotify event arrived.
--- Simply forwards it directly to the object.
+--
+-- Called when an file system monitor events arrive
--
runner.inotifyEvent = Inotify.event
runner.fsEventsEvent = Fsevents.event
------
--- Collector for every child process that finished in startup phase
---
--- Parameters are pid and exitcode of child process
--
--- Can return either a new pid if one other child process
--- has been spawned as replacement (e.g. retry) or 0 if
--- finished/ok.
+-- Collector for every child process that finished in startup phase
--
-function runner.collector(pid, exitcode)
+function runner.collector(
+ pid, -- pid of the child process
+ exitcode -- exitcode of the child process
+)
if exitcode ~= 0 then
log('Error', 'Startup process',pid,' failed')
- terminate(-1) -- ERRNO
+ terminate( -1 )
end
+
return 0
end
------
+--
-- Called by core when an overflow happened.
--
-function runner.overflow()
- log('Normal', '--- OVERFLOW in event queue ---')
+function runner.overflow( )
+
+ log(
+ 'Normal',
+ '--- OVERFLOW in event queue ---'
+ )
+
lsyncdStatus = 'fade'
+
end
------
+--
-- Called by core on a hup signal.
--
-function runner.hup()
- log('Normal', '--- HUP signal, resetting ---')
+function runner.hup( )
+
+ log(
+ 'Normal',
+ '--- HUP signal, resetting ---'
+ )
+
lsyncdStatus = 'fade'
+
end
------
+--
-- Called by core on a term signal.
--
-function runner.term()
- log('Normal', '--- TERM signal, fading ---')
+function runner.term( )
+
+ log(
+ 'Normal',
+ '--- TERM signal, fading ---'
+ )
+
lsyncdStatus = 'fade'
+
end
--============================================================================
--- Lsyncd user interface
+-- Lsyncd runner's user interface
--============================================================================
------
+--
-- Main utility to create new observations.
--- @returns an Inlet to that sync.
--
-function sync(opts)
+-- Returns an Inlet to that sync.
+--
+function sync( opts )
+
if lsyncdStatus ~= 'init' then
- error('Sync can only be created during initialization.', 2)
+ error(
+ 'Sync can only be created during initialization.',
+ 2
+ )
end
- return Syncs.add(opts).inlet
+
+ return Syncs.add( opts ).inlet
+
end
------
+--
-- Spawns a new child process.
--
--- @param agent the reason why a process is spawned.
--- normally this is a delay/event of a sync.
--- it will mark the related files as blocked.
--- @param binary binary to call
--- @param ... arguments
---
-function spawn(agent, binary, ...)
- if agent == nil or type(agent) ~= 'table' then
- error('spawning with an invalid agent', 2)
+function spawn(
+ agent, -- the reason why a process is spawned.
+ -- a delay or delay list for a sync
+ -- it will mark the related files as blocked.
+ binary, -- binary to call
+ ... -- arguments
+)
+ if
+ agent == nil or
+ type( agent ) ~= 'table'
+ then
+ error(
+ 'spawning with an invalid agent',
+ 2
+ )
end
if lsyncdStatus == 'fade' then
- log('Normal', 'ignored process spawning while fading')
+ log(
+ 'Normal',
+ 'ignored process spawning while fading'
+ )
return
end
- if type(binary) ~= 'string' then
- error('calling spawn(agent, binary, ...), binary is not a string', 2)
+ if type( binary ) ~= 'string' then
+ error(
+ 'calling spawn(agent, binary, ...): binary is not a string',
+ 2
+ )
end
- local dol = InletFactory.getDelayOrList(agent)
- if not dol then error('spawning with an unknown agent', 2) end
+ local dol = InletFactory.getDelayOrList( agent )
- -- checks if spawn is called on already active event
+ if not dol then
+ error(
+ 'spawning with an unknown agent',
+ 2
+ )
+ end
+
+ --
+ -- checks if a spawn is called on an already active event
+ --
if dol.status then
+
+ -- is an event
+
if dol.status ~= 'wait' then
error('spawn() called on an non-waiting event', 2)
end
- else -- is a list
+
+ else
+ -- is a list
+
for _, d in ipairs(dol) do
if d.status ~= 'wait' and d.status ~= 'block' then
error('spawn() called on an non-waiting event list', 2)
end
end
+
end
- local pid = lsyncd.exec(binary, ...)
+ --
+ -- tries to spawn the process
+ --
+ local pid = lsyncd.exec( binary, ... )
if pid and pid > 0 then
+
processCount = processCount + 1
- if settings.maxProcesses and processCount > settings.maxProcesses then
- error('Spawned too much processes!')
+ if
+ uSettings.maxProcesses and
+ processCount > uSettings.maxProcesses
+ then
+ error( 'Spawned too much processes!' )
end
- local sync = InletFactory.getSync(agent)
+
+ local sync = InletFactory.getSync( agent )
+
-- delay or list
if dol.status then
+
-- is a delay
dol.status = 'active'
- sync.processes[pid] = dol
+ sync.processes[ pid ] = dol
+
else
+
-- is a list
- for _, d in ipairs(dol) do
+ for _, d in ipairs( dol ) do
d.status = 'active'
end
- sync.processes[pid] = dol
+ sync.processes[ pid ] = dol
+
end
+
end
end
------
+--
-- Spawns a child process using the default shell.
--
-function spawnShell(agent, command, ...)
- return spawn(agent, '/bin/sh', '-c', command, '/bin/sh', ...)
+function spawnShell(
+ agent, -- the delay(list) to spawn the command for
+ command, -- the shell command
+ ... -- additonal arguments
+)
+ return spawn(
+ agent,
+ '/bin/sh',
+ '-c',
+ command,
+ '/bin/sh',
+ ...
+ )
end
-----
-- Observes a filedescriptor
--
-function observefd(fd, ready, writey)
- return lsyncd.observe_fd(fd, ready, writey)
+function observefd(
+ fd, -- file descriptor
+ ready, -- called when fd is ready to be read
+ writey -- called when fd is ready to be written
+)
+ return lsyncd.observe_fd(
+ fd,
+ ready,
+ writey
+ )
end
------
--- Nonobserves a filedescriptor
--
-function nonobservefd(fd)
- return lsyncd.nonobserve_fd(fd)
+-- Stops observeing a filedescriptor
+--
+function nonobservefd(
+ fd -- file descriptor
+)
+ return lsyncd.nonobserve_fd( fd )
end
------
+--
-- Calls func at timestamp.
+--
-- Use now() to receive current timestamp
--- add seconds with '+' to it)
+-- add seconds with '+' to it
--
alarm = UserAlarms.alarm
------
+--
-- Comfort routine also for user.
-- Returns true if 'String' starts with 'Start'
--
-function string.starts(String,Start)
- return string.sub(String,1,#Start)==Start
+function string.starts( String, Start )
+
+ return string.sub( String, 1, #Start )==Start
+
end
------
+--
-- Comfort routine also for user.
-- Returns true if 'String' ends with 'End'
--
-function string.ends(String,End)
- return End=='' or string.sub(String,-#End)==End
+function string.ends( String, End )
+
+ return End == '' or string.sub( String, -#End ) == End
+
end
------
--- provides a default empty settings table.
--
-settings = {}
+-- The Lsyncd 2.1 settings call
+--
+function settings( a1 )
+ -- if a1 is a string this is a get operation
+ if type( a1 ) == 'string' then
+ return uSettings[ a1 ]
+ end
------
+ -- if its a table it sets all the value of the bale
+ for k, v in pairs( a1 ) do
+ if type( k ) ~= 'number' then
+ uSettings[ k ] = v
+ else
+ uSettings[ v ] = true
+ end
+ end
+end
+settingsSafe = settings
+
+--
-- Returns the core the runners function interface.
--
return runner
|
[-]
[+]
|
Added |
lsyncd-2.1.4.tar.bz2/m4
^
|
+(directory)
|
[-]
[+]
|
Added |
lsyncd-2.1.4.tar.bz2/m4/ax_subst_l.m4
^
|
@@ -0,0 +1,15 @@
+
+# ax_subst_l.m4 - Substitute every var in the given comma seperated list -*-Autoconf-*-
+#
+# Copyright (C) 2012 Dennis Schridde
+#
+# This file is free software; the authors give
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 1
+
+# Substitute every var in the given comma seperated list
+AC_DEFUN([AX_SUBST_L],[
+ m4_foreach([__var__], [$@], [AC_SUBST(__var__)])
+])
|
[-]
[+]
|
Changed |
lsyncd.conf
^
|
@@ -1,4 +1,4 @@
-settings = {
+settings {
statusFile = "/var/log/lsyncd/lsyncd.status",
nodaemon = false,
statusInterval = 5,
|