From 9b9ac5d675b9ddcfa1223b09f586444f93948a4f Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Fri, 13 Apr 2018 22:55:04 +0200 Subject: [PATCH] finished restructering the core --- CMakeLists.txt | 2 +- core/feature.h | 20 ++++++++++++ core/inotify.c | 13 +++++--- core/log.c | 3 +- core/log.h | 12 ++++++++ core/lsyncd.h | 68 ----------------------------------------- core/{core.c => main.c} | 7 +++-- core/main.h | 19 ++++++++++++ core/mci.c | 21 ++++++++----- core/mci.h | 11 ++++--- core/mem.c | 15 ++++++--- core/observe.c | 5 +-- core/pipe.c | 9 +++++- core/signal.c | 3 +- core/time.c | 4 ++- core/userobs.c | 11 +++++-- core/util.c | 10 ++++-- 17 files changed, 129 insertions(+), 104 deletions(-) create mode 100644 core/feature.h delete mode 100644 core/lsyncd.h rename core/{core.c => main.c} (98%) create mode 100644 core/main.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 151887a..ffa4cbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,10 @@ include_directories ( ${LUA_INCLUDE_DIR} ) # Setting Lsyncd sources. # Order here doesn't matter much. set( LSYNCD_SRC - core/core.c core/log.c core/observe.c core/pipe.c + core/main.c core/mci.c core/mem.c core/signal.c diff --git a/core/feature.h b/core/feature.h new file mode 100644 index 0000000..5f72065 --- /dev/null +++ b/core/feature.h @@ -0,0 +1,20 @@ +/* +| feature.h from Lsyncd -- the Live (Mirror) Syncing Demon +| +| Some Definitions to enable proper clib header features +| Also loads the cmake config file +| +| License: GPLv2 (see COPYING) or any later version +| Authors: Axel Kittenberger +*/ +#ifndef FEATURE_H +#define FEATURE_H + +#include "config.h" + +// some older machines need this to see pselect +#define _DEFAULT_SOURCE 1 +#define _XOPEN_SOURCE 700 +#define _DARWIN_C_SOURCE 1 + +#endif diff --git a/core/inotify.c b/core/inotify.c index 9335c47..7216b16 100644 --- a/core/inotify.c +++ b/core/inotify.c @@ -8,20 +8,23 @@ | Authors: Axel Kittenberger */ -#include "config.h" -#include "lsyncd.h" +#include "feature.h" #include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include #define LUA_USE_APICHECK 1 #include #include #include +#include "mci.h" #include "mem.h" #include "log.h" #include "inotify.h" diff --git a/core/log.c b/core/log.c index b412c2a..846069d 100644 --- a/core/log.c +++ b/core/log.c @@ -8,7 +8,7 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ -#include "config.h" +#include "feature.h" #define SYSLOG_NAMES 1 #include @@ -26,7 +26,6 @@ #include "log.h" #include "mem.h" #include "time.h" -#include "lsyncd.h" // FIXME diff --git a/core/log.h b/core/log.h index af37afd..be3713b 100644 --- a/core/log.h +++ b/core/log.h @@ -9,6 +9,18 @@ #ifndef LSYNCD_LOG_H #define LSYNCD_LOG_H + +// Logging configuration +// This used to be general setting, but with the Lsyncd 3 razor, only logging +// stuff is left, likely to be reworked +extern struct settings { + char * log_file; // If not NULL Lsyncd logs into this file. + bool log_syslog; // If true Lsyncd sends log messages to syslog + char * log_ident; // If not NULL the syslog identity (otherwise "Lsyncd") + int log_facility; // The syslog facility + int log_level; // -1 logs everything, 0 normal mode, LOG_ERROR errors only. +} settings; + // Returns a logging facility number by name. extern int log_getFacility( lua_State * L, char const * fname); diff --git a/core/lsyncd.h b/core/lsyncd.h deleted file mode 100644 index 6262e24..0000000 --- a/core/lsyncd.h +++ /dev/null @@ -1,68 +0,0 @@ -/** -* lsyncd.h Live (Mirror) Syncing Demon -* -* Interface between the core modules. -* -* License: GPLv2 (see COPYING) or any later version -* Authors: Axel Kittenberger -* -*/ -#ifndef LSYNCD_H -#define LSYNCD_H - -// some older machines need this to see pselect -#define _DEFAULT_SOURCE 1 -#define _XOPEN_SOURCE 700 -#define _DARWIN_C_SOURCE 1 - -#define LUA_COMPAT_ALL -#define LUA_COMPAT_5_1 - -// includes needed for headerfile -#include "config.h" - -#include -#include - -#define LUA_USE_APICHECK 1 -#include - -#define LSYNCD_CORE_LIBNAME "core" -#define LSYNCD_INOTIFY_LIBNAME "inotify" - -/* -| Workaround to register a library for different lua versions. -*/ -#if LUA_VERSION_NUM > 502 - #define lua_compat_register( L, name, lib ) \ - { \ - lua_newtable((L)); \ - luaL_setfuncs((L), (lib), 0); \ - } -#else - #define lua_compat_register( L, name, lib ) \ - {luaL_register( (L), (name), (lib) );} -#endif - - -/* -* Lsyncd runtime configuration -*/ -extern struct settings { - char * log_file; // If not NULL Lsyncd logs into this file. - bool log_syslog; // If true Lsyncd sends log messages to syslog - char * log_ident; // If not NULL the syslog identity (otherwise "Lsyncd") - int log_facility; // The syslog facility - int log_level; // -1 logs everything, 0 normal mode, LOG_ERROR errors only. -} settings; - - -// Pushes a runner function and the runner error handler onto Lua stack -extern void load_mci(lua_State *L, const char *name); - - -// Dummy variable which address is used as -// index in the lua registry to store/get the error handler. -extern int callError; - -#endif diff --git a/core/core.c b/core/main.c similarity index 98% rename from core/core.c rename to core/main.c index ea68513..8c60886 100644 --- a/core/core.c +++ b/core/main.c @@ -1,11 +1,14 @@ /* -| core.c from Lsyncd -- the Live (Mirror) Syncing Demon +| main.c from Lsyncd -- the Live (Mirror) Syncing Demon +| +| Entry and main loop | | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ +#include "feature.h" -#include "lsyncd.h" +// FIXME remove unneeded headers #include #include diff --git a/core/main.h b/core/main.h new file mode 100644 index 0000000..4389fe7 --- /dev/null +++ b/core/main.h @@ -0,0 +1,19 @@ +/* +| main.h from Lsyncd -- the Live (Mirror) Syncing Demon +| +| Entry and main loop +| +| License: GPLv2 (see COPYING) or any later version +| Authors: Axel Kittenberger +* +*/ +#ifndef MAIN_H +#define MAIN_H + + +// Dummy variable which address is used as +// index in the lua registry to store/get the error handler. +extern int callError; + + +#endif diff --git a/core/mci.c b/core/mci.c index ef62671..a4a033d 100644 --- a/core/mci.c +++ b/core/mci.c @@ -9,13 +9,14 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ - -#include "lsyncd.h" +#include "feature.h" #include #include #include #include +#include +#include #include // FIXME abstract this away #include // FIXME abstract this away #include @@ -25,7 +26,6 @@ #include #include #include -#include #include "log.h" #include "mci.h" @@ -41,6 +41,11 @@ # include "inotify.h" #endif + +#define CORE_LIBNAME "core" +#define INOTIFY_LIBNAME "inotify" + + /* | The Lua part of Lsyncd */ @@ -150,13 +155,13 @@ l_exec( lua_State *L ) { int tlen; int it; - lua_checkstack( L, lua_gettop( L ) + lua_objlen( L, i ) + 1 ); + lua_checkstack( L, lua_gettop( L ) + lua_rawlen( L, i ) + 1 ); // moves table to top of stack lua_pushvalue( L, i ); lua_remove( L, i ); argc--; - tlen = lua_objlen( L, -1 ); + tlen = lua_rawlen( L, -1 ); for( it = 1; it <= tlen; it++ ) { @@ -664,15 +669,15 @@ register_core( lua_State *L ) { lua_newtable( L ); luaL_setfuncs( L, corelib, 0 ); - lua_setglobal( L, LSYNCD_CORE_LIBNAME ); + lua_setglobal( L, CORE_LIBNAME ); register_jiffies( L ); #ifdef WITH_INOTIFY - lua_getglobal( L, LSYNCD_CORE_LIBNAME ); + lua_getglobal( L, CORE_LIBNAME ); register_inotify( L ); - lua_setfield( L, -2, LSYNCD_INOTIFY_LIBNAME ); + lua_setfield( L, -2, INOTIFY_LIBNAME ); lua_pop( L, 1 ); #endif diff --git a/core/mci.h b/core/mci.h index 7196fc8..0d7ef22 100644 --- a/core/mci.h +++ b/core/mci.h @@ -11,12 +11,15 @@ // FIXME doc -int l_stackdump( lua_State* L ); +extern int l_stackdump( lua_State* L ); -void register_core( lua_State *L ); +extern void register_core( lua_State *L ); -void mci_load_mantle( lua_State *L ); +// Pushes a runner function and the runner error handler onto Lua stack +extern void load_mci(lua_State *L, const char *name); -void mci_load_default( lua_State *L ); +extern void mci_load_mantle( lua_State *L ); + +extern void mci_load_default( lua_State *L ); #endif diff --git a/core/mem.c b/core/mem.c index e43ac8a..9fdcfd8 100644 --- a/core/mem.c +++ b/core/mem.c @@ -11,11 +11,18 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ -#include -#include -#include +#include "feature.h" + +#include +#include +#include +#include + +#define LUA_USE_APICHECK 1 +#include +#include +#include -#include "lsyncd.h" #include "mem.h" #include "log.h" diff --git a/core/observe.c b/core/observe.c index b8c20e2..4466912 100644 --- a/core/observe.c +++ b/core/observe.c @@ -6,8 +6,10 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ -#include "lsyncd.h" +#include "feature.h" +#include +#include #include #include @@ -107,7 +109,6 @@ observe_fd( { // FIXME logstring( "Error", "New observances in ready/writey handlers not yet supported" ); - exit( -1 ); } diff --git a/core/pipe.c b/core/pipe.c index 4f6fb24..8be2b33 100644 --- a/core/pipe.c +++ b/core/pipe.c @@ -6,11 +6,18 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ -#include "lsyncd.h" +#include "feature.h" #include +#include +#include #include +#define LUA_USE_APICHECK 1 +#include +#include +#include + #include "log.h" #include "mem.h" #include "pipe.h" diff --git a/core/signal.c b/core/signal.c index c9fc52b..528a800 100644 --- a/core/signal.c +++ b/core/signal.c @@ -6,8 +6,9 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ -#include "lsyncd.h" +#include "feature.h" +#include #include diff --git a/core/time.c b/core/time.c index e976e4c..b38dd86 100644 --- a/core/time.c +++ b/core/time.c @@ -9,9 +9,11 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ -#include "lsyncd.h" +#include "feature.h" #include +#include +#include #define LUA_USE_APICHECK 1 #include diff --git a/core/userobs.c b/core/userobs.c index 7898064..4295629 100644 --- a/core/userobs.c +++ b/core/userobs.c @@ -9,7 +9,7 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ -#include "config.h" +#include "feature.h" #include #include @@ -22,7 +22,12 @@ #include "observe.h" #include "userobs.h" -#include "lsyncd.h" + +/* +| Used to load error handler +*/ +extern int callError; + /* | A user observance became read-ready. @@ -71,7 +76,7 @@ user_obs_writey( lua_gettable( L, LUA_REGISTRYINDEX ); // pushes the error handler - lua_pushlightuserdata(L, (void *) &callError); + lua_pushlightuserdata( L, (void *) &callError); lua_gettable( L, LUA_REGISTRYINDEX ); // pushes the user func diff --git a/core/util.c b/core/util.c index 48070eb..d3cf6d8 100644 --- a/core/util.c +++ b/core/util.c @@ -6,12 +6,18 @@ | License: GPLv2 (see COPYING) or any later version | Authors: Axel Kittenberger */ -#include "lsyncd.h" +#include "feature.h" +#include #include +#include #include #include -#include + +#define LUA_USE_APICHECK 1 +#include +#include +#include #include "log.h"