mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-02-02 03:48:24 +00:00
improved comments
This commit is contained in:
parent
af237aa691
commit
80baea16e0
@ -1,5 +1,5 @@
|
|||||||
--==================================================================================================
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
-- default-rsyncssh.lua
|
-- default-direct.lua
|
||||||
--
|
--
|
||||||
-- Keeps two directories with /bin/cp, /bin/rm and /bin/mv in sync.
|
-- Keeps two directories with /bin/cp, /bin/rm and /bin/mv in sync.
|
||||||
-- Startup still uses rsync tough.
|
-- Startup still uses rsync tough.
|
||||||
@ -7,15 +7,15 @@
|
|||||||
-- A (Layer 1) configuration.
|
-- A (Layer 1) configuration.
|
||||||
--
|
--
|
||||||
-- Note:
|
-- 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.
|
-- like any other. It only gets compiled into the binary by default.
|
||||||
-- You can simply use a modified one, by copying everything into a
|
-- 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
|
-- License: GPLv2 (see COPYING) or any later version
|
||||||
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||||
--
|
--
|
||||||
--==================================================================================================
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
if not default then error('default not loaded'); end
|
if not default then error('default not loaded'); end
|
||||||
if not default.rsync then error('default-direct (currently) needs default.rsync loaded'); end
|
if not default.rsync then error('default-direct (currently) needs default.rsync loaded'); end
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
--==================================================================================================
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
-- default-rsync.lua
|
-- default-rsync.lua
|
||||||
--
|
--
|
||||||
-- Syncs with rsync ("classic" Lsyncd)
|
-- Syncs with rsync ("classic" Lsyncd)
|
||||||
-- A (Layer 1) configuration.
|
-- A (Layer 1) configuration.
|
||||||
--
|
--
|
||||||
-- Note:
|
-- 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.
|
-- like any other. It only gets compiled into the binary by default.
|
||||||
-- You can simply use a modified one, by copying everything into a
|
-- 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
|
-- License: GPLv2 (see COPYING) or any later version
|
||||||
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||||
--
|
--
|
||||||
--==================================================================================================
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
if not default then error('default not loaded'); end
|
if not default then error('default not loaded'); end
|
||||||
if default.rsync then error('default-rsync already loaded'); end
|
if default.rsync then error('default-rsync already loaded'); end
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
--==================================================================================================
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
-- default-rsyncssh.lua
|
-- default-rsyncssh.lua
|
||||||
--
|
--
|
||||||
-- Improved rsync - sync with rsync, but moves and deletes executed over ssh.
|
-- Improved rsync - sync with rsync, but moves and deletes executed over ssh.
|
||||||
-- A (Layer 1) configuration.
|
-- A (Layer 1) configuration.
|
||||||
--
|
--
|
||||||
-- Note:
|
-- 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.
|
-- like any other. It only gets compiled into the binary by default.
|
||||||
-- You can simply use a modified one, by copying everything into a
|
-- 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
|
-- License: GPLv2 (see COPYING) or any later version
|
||||||
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||||
--
|
--
|
||||||
--==================================================================================================
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
if not default then error('default not loaded'); end
|
if not default then error('default not loaded'); end
|
||||||
if default.rsyncssh then error('default-rsyncssh already loaded'); end
|
if default.rsyncssh then error('default-rsyncssh already loaded'); end
|
||||||
|
15
lsyncd.c
15
lsyncd.c
@ -1,18 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* lsyncd.c Live (Mirror) Syncing Demon
|
* lsyncd.c Live (Mirror) Syncing Demon
|
||||||
*
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* License: GPLv2 (see COPYING) or any later version
|
|
||||||
*
|
|
||||||
* Authors: Axel Kittenberger <axkibe@gmail.com>
|
|
||||||
*
|
|
||||||
* -----------------------------------------------------------------------
|
|
||||||
*
|
*
|
||||||
* This is the core. It contains as minimal as possible glues
|
* This is the core. It contains as minimal as possible glues
|
||||||
* to the operating system needed for lsyncd operation. All high-level
|
* to the operating system needed for lsyncd operation. All high-level
|
||||||
* logic is coded (when feasable) into lsyncd.lua
|
* 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 <axkibe@gmail.com>
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
#include "lsyncd.h"
|
#include "lsyncd.h"
|
||||||
|
|
||||||
|
111
lsyncd.h
111
lsyncd.h
@ -1,22 +1,22 @@
|
|||||||
/**
|
/**
|
||||||
* lsyncd.h Live (Mirror) Syncing Demon
|
* 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 <axkibe@gmail.com>
|
* Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||||
*
|
*
|
||||||
* Interface between the core modules.
|
**/
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LSYNCD_H
|
#ifndef LSYNCD_H
|
||||||
#define 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 _BSD_SOURCE 1
|
||||||
#define _XOPEN_SOURCE 700
|
#define _XOPEN_SOURCE 700
|
||||||
#define _DARWIN_C_SOURCE 1
|
#define _DARWIN_C_SOURCE 1
|
||||||
|
|
||||||
/* includes needed for headerfile */
|
// includes needed for headerfile
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -26,94 +26,80 @@
|
|||||||
#define LUA_USE_APICHECK 1
|
#define LUA_USE_APICHECK 1
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* Lsyncd runtime configuration
|
* Lsyncd runtime configuration
|
||||||
*/
|
*/
|
||||||
extern struct settings {
|
extern struct settings {
|
||||||
/* If not NULL Lsyncd logs into this file. */
|
char * log_file; // If not NULL Lsyncd logs into this file.
|
||||||
char * log_file;
|
bool log_syslog; // If true Lsyncd sends log messages to syslog
|
||||||
|
char * log_ident; // If not NULL the syslog identity (otherwise "Lsyncd")
|
||||||
/* If true Lsyncd sends log messages to syslog */
|
int log_facility; // The syslog facility
|
||||||
bool log_syslog;
|
int log_level; // -1 logs everything, 0 normal mode, LOG_ERROR errors only.
|
||||||
|
bool nodaemon; // True if Lsyncd shall not daemonize.
|
||||||
/* If not NULL the syslog identity (otherwise "Lsyncd") */
|
char * pidfile; // If not NULL Lsyncd writes its pid into this file.
|
||||||
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;
|
|
||||||
|
|
||||||
} settings;
|
} settings;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* time comparisons - wrap around safe
|
* time comparisons - wrap around safe
|
||||||
*/
|
*/
|
||||||
#define time_after(a,b) ((long)(b) - (long)(a) < 0)
|
#define time_after(a,b) ((long)(b) - (long)(a) < 0)
|
||||||
#define time_before(a,b) time_after(b,a)
|
#define time_before(a,b) time_after(b,a)
|
||||||
#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
|
#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
|
||||||
#define time_before_eq(a,b) time_after_eq(b,a)
|
#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);
|
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);
|
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 hup;
|
||||||
extern volatile sig_atomic_t term;
|
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_calloc(size_t nmemb, size_t size);
|
||||||
extern void * s_malloc(size_t size);
|
extern void * s_malloc(size_t size);
|
||||||
extern void * s_realloc(void *ptr, size_t size);
|
extern void * s_realloc(void *ptr, size_t size);
|
||||||
extern char * s_strdup(const char *src);
|
extern char * s_strdup(const char *src);
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* Logging
|
* 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);
|
extern int check_logcat(const char *name);
|
||||||
|
|
||||||
/* logs a string */
|
// logs a string
|
||||||
#define logstring(cat, message) \
|
#define logstring(cat, message) \
|
||||||
{int p; if ((p = check_logcat(cat)) <= settings.log_level) \
|
{int p; if ((p = check_logcat(cat)) <= settings.log_level) \
|
||||||
{logstring0(p, cat, message);}}
|
{logstring0(p, cat, message);}}
|
||||||
extern void logstring0(int priority, const char *cat, const char *message);
|
extern void logstring0(int priority, const char *cat, const char *message);
|
||||||
|
|
||||||
/* logs a formated string */
|
// logs a formated string
|
||||||
#define printlogf(L, cat, ...) \
|
#define printlogf(L, cat, ...) \
|
||||||
{int p; if ((p = check_logcat(cat)) <= settings.log_level) \
|
{int p; if ((p = check_logcat(cat)) <= settings.log_level) \
|
||||||
{printlogf0(L, p, cat, __VA_ARGS__);}}
|
{printlogf0(L, p, cat, __VA_ARGS__);}}
|
||||||
extern void
|
extern void
|
||||||
printlogf0(lua_State *L,
|
printlogf0(lua_State *L,
|
||||||
int priority,
|
int priority,
|
||||||
const char *cat,
|
const char *cat,
|
||||||
const char *fmt,
|
const char *fmt,
|
||||||
...)
|
...)
|
||||||
__attribute__((format(printf, 4, 5)));
|
__attribute__((format(printf, 4, 5)));
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* File-descriptor helpers
|
* 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);
|
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);
|
extern void close_exec_fd(int fd);
|
||||||
|
|
||||||
|
|
||||||
@ -122,35 +108,35 @@ extern void close_exec_fd(int fd);
|
|||||||
* read-ready or write-ready.
|
* read-ready or write-ready.
|
||||||
*/
|
*/
|
||||||
struct observance {
|
struct observance {
|
||||||
/* The file descriptor to observe. */
|
// The file descriptor to observe.
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* Function to call when read becomes ready. */
|
// Function to call when read becomes ready.
|
||||||
void (*ready)(lua_State *, struct observance *);
|
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 *);
|
void (*writey)(lua_State *, struct observance *);
|
||||||
|
|
||||||
/* Function to call to clean up */
|
// Function to call to clean up
|
||||||
void (*tidy)(struct observance *);
|
void (*tidy)(struct observance *);
|
||||||
|
|
||||||
/* Extra tokens to pass to the functions- */
|
// Extra tokens to pass to the functions.
|
||||||
void *extra;
|
void *extra;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* makes the core observe a file descriptor */
|
// makes the core observe a file descriptor
|
||||||
extern void observe_fd(
|
extern void observe_fd(
|
||||||
int fd,
|
int fd,
|
||||||
void (*ready) (lua_State *, struct observance *),
|
void (*ready) (lua_State *, struct observance *),
|
||||||
void (*writey)(lua_State *, struct observance *),
|
void (*writey)(lua_State *, struct observance *),
|
||||||
void (*tidy) (struct observance *),
|
void (*tidy) (struct observance *),
|
||||||
void *extra
|
void *extra
|
||||||
);
|
);
|
||||||
|
|
||||||
/* stops the core to observe a file descriptor */
|
// stops the core to observe a file descriptor
|
||||||
extern void nonobserve_fd(int fd);
|
extern void nonobserve_fd(int fd);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* inotify
|
* inotify
|
||||||
*/
|
*/
|
||||||
#ifdef LSYNCD_WITH_INOTIFY
|
#ifdef LSYNCD_WITH_INOTIFY
|
||||||
@ -158,7 +144,7 @@ extern void register_inotify(lua_State *L);
|
|||||||
extern void open_inotify(lua_State *L);
|
extern void open_inotify(lua_State *L);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* fanotify
|
* fanotify
|
||||||
*/
|
*/
|
||||||
#ifdef LSYNCD_WITH_FANOTIFY
|
#ifdef LSYNCD_WITH_FANOTIFY
|
||||||
@ -166,12 +152,11 @@ extern void register_fanotify(lua_State *L);
|
|||||||
extern void open_fanotify(lua_State *L);
|
extern void open_fanotify(lua_State *L);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/**
|
||||||
* /dev/fsevents
|
* /dev/fsevents
|
||||||
*/
|
*/
|
||||||
#ifdef LSYNCD_WITH_FSEVENTS
|
#ifdef LSYNCD_WITH_FSEVENTS
|
||||||
extern void open_fsevents(lua_State *L);
|
extern void open_fsevents(lua_State *L);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
13
lsyncd.lua
13
lsyncd.lua
@ -1,14 +1,15 @@
|
|||||||
--============================================================================
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
-- lsyncd.lua Live (Mirror) Syncing Demon
|
-- lsyncd.lua Live (Mirror) Syncing Demon
|
||||||
--
|
--
|
||||||
-- License: GPLv2 (see COPYING) or any later version
|
|
||||||
--
|
|
||||||
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
|
||||||
--
|
|
||||||
-- This is the "runner" part of Lsyncd. It containts all its high-level logic.
|
-- 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
|
-- It works closely together with the Lsyncd core in lsyncd.c. This means it
|
||||||
-- cannot be runned directly from the standard lua interpreter.
|
-- cannot be runned directly from the standard lua interpreter.
|
||||||
--============================================================================
|
--
|
||||||
|
-- License: GPLv2 (see COPYING) or any later version
|
||||||
|
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||||
|
--
|
||||||
|
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
-- require('profiler')
|
-- require('profiler')
|
||||||
-- profiler.start()
|
-- profiler.start()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user