diff --git a/default-direct.lua b/default-direct.lua index c06aad1..0c9e8aa 100644 --- a/default-direct.lua +++ b/default-direct.lua @@ -1,5 +1,5 @@ ---================================================================================================== --- default-rsyncssh.lua +--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-- default-direct.lua -- -- Keeps two directories with /bin/cp, /bin/rm and /bin/mv in sync. -- Startup still uses rsync tough. @@ -7,15 +7,15 @@ -- A (Layer 1) configuration. -- -- Note: --- this is infact just configuration using Layer 1 configuration, +-- 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 call it differently. +-- config file of yours and name it differently. -- -- License: GPLv2 (see COPYING) or any later version -- Authors: Axel Kittenberger -- ---================================================================================================== +--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if not default then error('default not loaded'); end if not default.rsync then error('default-direct (currently) needs default.rsync loaded'); end diff --git a/default-rsync.lua b/default-rsync.lua index a11b5cd..85f2e0f 100644 --- a/default-rsync.lua +++ b/default-rsync.lua @@ -1,19 +1,19 @@ ---================================================================================================== +--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- default-rsync.lua -- -- Syncs with rsync ("classic" Lsyncd) -- A (Layer 1) configuration. -- -- Note: --- this is infact just configuration using Layer 1 configuration, +-- 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 call it differently. +-- config file of yours and name it differently. -- -- License: GPLv2 (see COPYING) or any later version -- Authors: Axel Kittenberger -- ---================================================================================================== +--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if not default then error('default not loaded'); end if default.rsync then error('default-rsync already loaded'); end diff --git a/default-rsyncssh.lua b/default-rsyncssh.lua index 3d1c83b..c32f0fe 100644 --- a/default-rsyncssh.lua +++ b/default-rsyncssh.lua @@ -1,19 +1,19 @@ ---================================================================================================== +--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- default-rsyncssh.lua -- -- Improved rsync - sync with rsync, but moves and deletes executed over ssh. -- A (Layer 1) configuration. -- -- Note: --- this is infact just configuration using Layer 1 configuration, +-- 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 call it differently. +-- config file of yours and name it differently. -- -- License: GPLv2 (see COPYING) or any later version -- Authors: Axel Kittenberger -- ---================================================================================================== +--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if not default then error('default not loaded'); end if default.rsyncssh then error('default-rsyncssh already loaded'); end diff --git a/lsyncd.c b/lsyncd.c index 663d8fc..3bed58d 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -1,18 +1,17 @@ /** * lsyncd.c Live (Mirror) Syncing Demon - * - * License: GPLv2 (see COPYING) or any later version - * - * Authors: Axel Kittenberger - * - * ----------------------------------------------------------------------- + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 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. - */ + * 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 + * + **/ #include "lsyncd.h" diff --git a/lsyncd.h b/lsyncd.h index bb976d5..b94317d 100644 --- a/lsyncd.h +++ b/lsyncd.h @@ -1,22 +1,22 @@ -/** +/** * lsyncd.h Live (Mirror) Syncing Demon * - * License: GPLv2 (see COPYING) or any later version + * Interface between the core modules. * + * License: GPLv2 (see COPYING) or any later version * Authors: Axel Kittenberger * - * Interface between the core modules. - */ + **/ #ifndef LSYNCD_H #define LSYNCD_H -/* some older machines need this to see pselect */ +// some older machines need this to see pselect #define _BSD_SOURCE 1 #define _XOPEN_SOURCE 700 #define _DARWIN_C_SOURCE 1 -/* includes needed for headerfile */ +// includes needed for headerfile #include "config.h" #include @@ -26,94 +26,80 @@ #define LUA_USE_APICHECK 1 #include -/*----------------------------------------------------------------------------- +/** * Lsyncd runtime configuration */ extern struct settings { - /* If not NULL Lsyncd logs into this file. */ - char * log_file; - - /* If true Lsyncd sends log messages to syslog */ - bool log_syslog; - - /* If not NULL the syslog identity (otherwise "Lsyncd") */ - char * log_ident; - - /* The syslog facility */ - int log_facility; - - /* -1 logs everything, 0 normal mode, LOG_ERROR errors only.*/ - int log_level; - - /* True if Lsyncd shall not daemonize. */ - bool nodaemon; - - /* If not NULL Lsyncd writes its pid into this file. */ - char * pidfile; + 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. + bool nodaemon; // True if Lsyncd shall not daemonize. + char * pidfile; // If not NULL Lsyncd writes its pid into this file. } settings; -/*----------------------------------------------------------------------------- - * time comparisons - wrap around safe +/** + * time comparisons - wrap around safe */ #define time_after(a,b) ((long)(b) - (long)(a) < 0) #define time_before(a,b) time_after(b,a) #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) #define time_before_eq(a,b) time_after_eq(b,a) -/* 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); -/* pushes a runner function and the runner error handler onto Lua stack */ +// pushes a runner function and the runner error handler onto Lua stack extern void load_runner_func(lua_State *L, const char *name); -/* set to 1 on hup signal or term signal */ +// set to 1 on hup signal or term signal extern volatile sig_atomic_t hup; extern volatile sig_atomic_t term; -/*----------------------------------------------------------------------------- - * wrappers for heap management, they exit if out-of-memory. +/** + * wrappers for heap management, they exit if out-of-memory. */ - extern void * s_calloc(size_t nmemb, size_t size); extern void * s_malloc(size_t size); extern void * s_realloc(void *ptr, size_t size); extern char * s_strdup(const char *src); -/*----------------------------------------------------------------------------- +/** * Logging */ -/* Returns the positive priority if name is configured to be logged, or -1 */ +// Returns the positive priority if name is configured to be logged, or -1 extern int check_logcat(const char *name); -/* logs a string */ +// logs a string #define logstring(cat, message) \ {int p; if ((p = check_logcat(cat)) <= settings.log_level) \ {logstring0(p, cat, message);}} extern void logstring0(int priority, const char *cat, const char *message); -/* logs a formated string */ +// logs a formated string #define printlogf(L, cat, ...) \ {int p; if ((p = check_logcat(cat)) <= settings.log_level) \ {printlogf0(L, p, cat, __VA_ARGS__);}} extern void -printlogf0(lua_State *L, - int priority, +printlogf0(lua_State *L, + int priority, const char *cat, - const char *fmt, + const char *fmt, ...) __attribute__((format(printf, 4, 5))); -/*----------------------------------------------------------------------------- +/** * File-descriptor helpers */ - -/* Sets the non-blocking flag for a file descriptor. */ + +// Sets the non-blocking flag for a file descriptor. extern void non_block_fd(int fd); -/* Sets the close-on-exit flag for a file descriptor. */ +// Sets the close-on-exit flag for a file descriptor. extern void close_exec_fd(int fd); @@ -122,35 +108,35 @@ extern void close_exec_fd(int fd); * read-ready or write-ready. */ struct observance { - /* The file descriptor to observe. */ + // The file descriptor to observe. int fd; - /* Function to call when read becomes ready. */ + // Function to call when read becomes ready. void (*ready)(lua_State *, struct observance *); - - /* Function to call when write becomes ready. */ + + // Function to call when write becomes ready. void (*writey)(lua_State *, struct observance *); - - /* Function to call to clean up */ + + // Function to call to clean up void (*tidy)(struct observance *); - /* Extra tokens to pass to the functions- */ + // Extra tokens to pass to the functions. void *extra; }; -/* makes the core observe a file descriptor */ +// makes the core observe a file descriptor extern void observe_fd( - int fd, - void (*ready) (lua_State *, struct observance *), - void (*writey)(lua_State *, struct observance *), - void (*tidy) (struct observance *), + int fd, + void (*ready) (lua_State *, struct observance *), + void (*writey)(lua_State *, struct observance *), + void (*tidy) (struct observance *), void *extra ); -/* stops the core to observe a file descriptor */ +// stops the core to observe a file descriptor extern void nonobserve_fd(int fd); -/*----------------------------------------------------------------------------- +/** * inotify */ #ifdef LSYNCD_WITH_INOTIFY @@ -158,7 +144,7 @@ extern void register_inotify(lua_State *L); extern void open_inotify(lua_State *L); #endif -/*----------------------------------------------------------------------------- +/** * fanotify */ #ifdef LSYNCD_WITH_FANOTIFY @@ -166,12 +152,11 @@ extern void register_fanotify(lua_State *L); extern void open_fanotify(lua_State *L); #endif -/*----------------------------------------------------------------------------- +/** * /dev/fsevents */ #ifdef LSYNCD_WITH_FSEVENTS extern void open_fsevents(lua_State *L); #endif - #endif diff --git a/lsyncd.lua b/lsyncd.lua index dc8632e..d22ac1b 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -1,14 +1,15 @@ ---============================================================================ +--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- lsyncd.lua Live (Mirror) Syncing Demon -- --- License: GPLv2 (see COPYING) or any later version --- --- Authors: Axel Kittenberger --- -- This is the "runner" part of Lsyncd. It containts all its high-level logic. -- It works closely together with the Lsyncd core in lsyncd.c. This means it -- cannot be runned directly from the standard lua interpreter. ---============================================================================ +-- +-- License: GPLv2 (see COPYING) or any later version +-- Authors: Axel Kittenberger +-- +--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + -- require('profiler') -- profiler.start()