mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-13 22:48:29 +00:00
This commit is contained in:
parent
34753fa43c
commit
5cff9a8583
15
Makefile.am
15
Makefile.am
@ -3,3 +3,18 @@ CFLAGS = -Wall $(LIBLUA_CFLAGS)
|
|||||||
bin_PROGRAMS = lsyncd
|
bin_PROGRAMS = lsyncd
|
||||||
lsyncd_SOURCES = lsyncd.c
|
lsyncd_SOURCES = lsyncd.c
|
||||||
lsyncd_LDADD = $(LIBLUA_LIBS)
|
lsyncd_LDADD = $(LIBLUA_LIBS)
|
||||||
|
|
||||||
|
if RUNNER
|
||||||
|
else
|
||||||
|
lsyncd: luac.o $(lsyncd_LDADD)
|
||||||
|
|
||||||
|
architecture: | lsyncd.o
|
||||||
|
objdump -f $< | grep architecture | sed -e "s/,.*$$//" -e "s/[^ ]* \(.*\)/\1/" > $@ || rm architecture
|
||||||
|
|
||||||
|
luac.o: luac.out architecture
|
||||||
|
objcopy --input-target=binary --output-target=`gcc -dumpmachine` --binary-architecture=`cat architecture` $< $@
|
||||||
|
|
||||||
|
luac.out: lsyncd.lua
|
||||||
|
luac $<
|
||||||
|
endif
|
||||||
|
|
||||||
|
11
configure.ac
11
configure.ac
@ -12,8 +12,17 @@ AC_PROG_MAKE_SET
|
|||||||
# Checks for libraries.
|
# Checks for libraries.
|
||||||
PKG_CHECK_MODULES(LIBLUA, lua5.1)
|
PKG_CHECK_MODULES(LIBLUA, lua5.1)
|
||||||
# Checks for header files.
|
# Checks for header files.
|
||||||
|
AC_CHECK_HEADERS([sys/inotify.h])
|
||||||
|
|
||||||
|
AC_ARG_WITH([runner],
|
||||||
|
[ --with-runner=<file> Specify place where lsyncds part written in Lua will be placed.
|
||||||
|
If missing it will be compiled into the binary)])
|
||||||
|
if test "x${with_runner}" != x; then
|
||||||
|
AC_DEFINE_UNQUOTED(LSYNCD_DEFAULT_RUNNER_FILE, "${with_runner}", "descr")
|
||||||
|
fi
|
||||||
|
AM_CONDITIONAL([RUNNER], [test x${with_runner} != x])
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
# Checks for library functions.
|
# Checks for library functions.
|
||||||
AC_CHECK_HEADERS([sys/inotify.h])
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
30
lsyncd.c
30
lsyncd.c
@ -71,7 +71,10 @@ enum event_type {
|
|||||||
/**
|
/**
|
||||||
* The Lua part of lsyncd.
|
* The Lua part of lsyncd.
|
||||||
*/
|
*/
|
||||||
#define LSYNCD_DEFAULT_RUNNER_FILE "lsyncd.lua"
|
//#define LSYNCD_DEFAULT_RUNNER_FILE "lsyncd.lua"
|
||||||
|
extern char _binary_luac_out_start;
|
||||||
|
extern char _binary_luac_out_end;
|
||||||
|
|
||||||
static char * lsyncd_runner_file = NULL;
|
static char * lsyncd_runner_file = NULL;
|
||||||
static char * lsyncd_config_file = NULL;
|
static char * lsyncd_config_file = NULL;
|
||||||
|
|
||||||
@ -1017,6 +1020,7 @@ main(int argc, char *argv[])
|
|||||||
lua_pushinteger(L, ERROR); lua_setglobal(L, "ERROR");
|
lua_pushinteger(L, ERROR); lua_setglobal(L, "ERROR");
|
||||||
|
|
||||||
/* TODO parse runner */
|
/* TODO parse runner */
|
||||||
|
#ifdef LSYNCD_DEFAULT_RUNNER_FILE
|
||||||
if (!strcmp(argv[argp], "--runner")) {
|
if (!strcmp(argv[argp], "--runner")) {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf(stderr, "Lsyncd Lua-runner file missing after --runner.\n");
|
fprintf(stderr, "Lsyncd Lua-runner file missing after --runner.\n");
|
||||||
@ -1033,28 +1037,46 @@ main(int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
lsyncd_runner_file = LSYNCD_DEFAULT_RUNNER_FILE;
|
lsyncd_runner_file = LSYNCD_DEFAULT_RUNNER_FILE;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (!strcmp(argv[argp], "--runner")) {
|
||||||
|
fprintf(stderr, "This lsyncd binary has its lua runner staticly compiled.\n");
|
||||||
|
fprintf(stderr, "Configure and compile with --with-runner=FILE to use the lsyncd.lua file.\n");
|
||||||
|
return -1; // ERRNO
|
||||||
|
}
|
||||||
|
#endif
|
||||||
lsyncd_config_file = argv[argp++];
|
lsyncd_config_file = argv[argp++];
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
#ifdef LSYNCD_DEFAULT_RUNNER_FILE
|
||||||
if (stat(lsyncd_runner_file, &st)) {
|
if (stat(lsyncd_runner_file, &st)) {
|
||||||
fprintf(stderr, "Cannot find Lsyncd Lua-runner at %s.\n", lsyncd_runner_file);
|
fprintf(stderr, "Cannot find Lsyncd Lua-runner at '%s'.\n", lsyncd_runner_file);
|
||||||
fprintf(stderr, "Maybe specify another place? %s --runner RUNNER_FILE CONFIG_FILE\n", argv[0]);
|
fprintf(stderr, "Maybe specify another place? %s --runner RUNNER_FILE CONFIG_FILE\n", argv[0]);
|
||||||
return -1; // ERRNO
|
return -1; // ERRNO
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (stat(lsyncd_config_file, &st)) {
|
if (stat(lsyncd_config_file, &st)) {
|
||||||
fprintf(stderr, "Cannot find config file at %s.\n", lsyncd_config_file);
|
fprintf(stderr, "Cannot find config file at '%s'.\n", lsyncd_config_file);
|
||||||
return -1; // ERRNO
|
return -1; // ERRNO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LSYNCD_DEFAULT_RUNNER_FILE
|
||||||
if (luaL_loadfile(L, lsyncd_runner_file)) {
|
if (luaL_loadfile(L, lsyncd_runner_file)) {
|
||||||
fprintf(stderr, "error loading '%s': %s\n",
|
fprintf(stderr, "error loading '%s': %s\n",
|
||||||
lsyncd_runner_file, lua_tostring(L, -1));
|
lsyncd_runner_file, lua_tostring(L, -1));
|
||||||
return -1; // ERRNO
|
return -1; // ERRNO
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (luaL_loadbuffer(L, &_binary_luac_out_start,
|
||||||
|
&_binary_luac_out_end - &_binary_luac_out_start, "lsyncd.lua")) {
|
||||||
|
fprintf(stderr, "error loading precompiled lsyncd.lua runner: %s\n",
|
||||||
|
lua_tostring(L, -1));
|
||||||
|
return -1; // ERRNO
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (lua_pcall(L, 0, LUA_MULTRET, 0)) {
|
if (lua_pcall(L, 0, LUA_MULTRET, 0)) {
|
||||||
fprintf(stderr, "error preparing '%s': %s\n",
|
fprintf(stderr, "error preparing '%s': %s\n",
|
||||||
lsyncd_runner_file, lua_tostring(L, -1));
|
lsyncd_runner_file, lua_tostring(L, -1));
|
||||||
return -1; // ERRNO
|
return -1; // ERRNO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user