finished restructering the core

This commit is contained in:
Axel Kittenberger 2018-04-13 22:55:04 +02:00
parent cc567b3ecf
commit 9b9ac5d675
17 changed files with 129 additions and 104 deletions

View File

@ -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

20
core/feature.h Normal file
View File

@ -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 <axkibe@gmail.com>
*/
#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

View File

@ -8,20 +8,23 @@
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "config.h"
#include "lsyncd.h"
#include "feature.h"
#include <sys/inotify.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define LUA_USE_APICHECK 1
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "mci.h"
#include "mem.h"
#include "log.h"
#include "inotify.h"

View File

@ -8,7 +8,7 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "config.h"
#include "feature.h"
#define SYSLOG_NAMES 1
#include <stdbool.h>
@ -26,7 +26,6 @@
#include "log.h"
#include "mem.h"
#include "time.h"
#include "lsyncd.h"
// FIXME

View File

@ -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);

View File

@ -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 <axkibe@gmail.com>
*
*/
#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 <stdbool.h>
#include <stdlib.h>
#define LUA_USE_APICHECK 1
#include <lua.h>
#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

View File

@ -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 <axkibe@gmail.com>
*/
#include "feature.h"
#include "lsyncd.h"
// FIXME remove unneeded headers
#include <sys/select.h>
#include <sys/stat.h>

19
core/main.h Normal file
View File

@ -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 <axkibe@gmail.com>
*
*/
#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

View File

@ -9,13 +9,14 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "lsyncd.h"
#include "feature.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <signal.h> // FIXME abstract this away
#include <syslog.h> // FIXME abstract this away
#include <string.h>
@ -25,7 +26,6 @@
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <unistd.h>
#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

View File

@ -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

View File

@ -11,11 +11,18 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include <stdlib.h>
#include <syslog.h>
#include <string.h>
#include "feature.h"
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#define LUA_USE_APICHECK 1
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "lsyncd.h"
#include "mem.h"
#include "log.h"

View File

@ -6,8 +6,10 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "lsyncd.h"
#include "feature.h"
#include <stdbool.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@ -107,7 +109,6 @@ observe_fd(
{
// FIXME
logstring( "Error", "New observances in ready/writey handlers not yet supported" );
exit( -1 );
}

View File

@ -6,11 +6,18 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "lsyncd.h"
#include "feature.h"
#include <unistd.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#define LUA_USE_APICHECK 1
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "log.h"
#include "mem.h"
#include "pipe.h"

View File

@ -6,8 +6,9 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "lsyncd.h"
#include "feature.h"
#include <stddef.h>
#include <signal.h>

View File

@ -9,9 +9,11 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "lsyncd.h"
#include "feature.h"
#include <sys/times.h>
#include <stdbool.h>
#include <stdlib.h>
#define LUA_USE_APICHECK 1
#include <lua.h>

View File

@ -9,7 +9,7 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "config.h"
#include "feature.h"
#include <stdbool.h>
#include <stdlib.h>
@ -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

View File

@ -6,12 +6,18 @@
| License: GPLv2 (see COPYING) or any later version
| Authors: Axel Kittenberger <axkibe@gmail.com>
*/
#include "lsyncd.h"
#include "feature.h"
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define LUA_USE_APICHECK 1
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "log.h"