2010-11-22 14:54:50 +00:00
|
|
|
/**
|
|
|
|
* lsyncd.h Live (Mirror) Syncing Demon
|
|
|
|
*
|
|
|
|
* License: GPLv2 (see COPYING) or any later version
|
|
|
|
*
|
|
|
|
* Authors: Axel Kittenberger <axkibe@gmail.com>
|
|
|
|
*
|
|
|
|
* Interface between the core modules.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LSYNCD_H
|
|
|
|
#define LSYNCD_H
|
|
|
|
|
2011-07-19 13:29:19 +00:00
|
|
|
/* some older machines need this to see pselect */
|
|
|
|
#define _BSD_SOURCE 1
|
2011-08-16 14:25:30 +00:00
|
|
|
#define _XOPEN_SOURCE 700
|
|
|
|
#define _DARWIN_C_SOURCE 1
|
2011-07-19 13:29:19 +00:00
|
|
|
|
2010-11-22 14:54:50 +00:00
|
|
|
/* includes needed for headerfile */
|
|
|
|
#include "config.h"
|
|
|
|
|
2010-11-22 21:06:02 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdbool.h>
|
2010-11-22 14:54:50 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define LUA_USE_APICHECK 1
|
|
|
|
#include <lua.h>
|
|
|
|
|
2010-11-22 21:06:02 +00:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* 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;
|
|
|
|
|
2011-03-01 14:57:26 +00:00
|
|
|
/* If not NULL the syslog identity (otherwise "Lsyncd") */
|
|
|
|
char * log_ident;
|
|
|
|
|
|
|
|
/* The syslog facility */
|
|
|
|
int log_facility;
|
|
|
|
|
2010-11-22 21:06:02 +00:00
|
|
|
/* -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;
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* time comparisons - wrap around safe
|
|
|
|
*/
|
2010-11-22 14:54:50 +00:00
|
|
|
#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)
|
|
|
|
|
2010-11-29 10:56:39 +00:00
|
|
|
/* returns (on Lua stack) the current kernels * clock state (jiffies) */
|
|
|
|
extern int l_now(lua_State *L);
|
2010-11-22 14:54:50 +00:00
|
|
|
|
2010-11-22 21:06:02 +00:00
|
|
|
/* 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 */
|
|
|
|
extern volatile sig_atomic_t hup;
|
|
|
|
extern volatile sig_atomic_t term;
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
2010-11-22 14:54:50 +00:00
|
|
|
* wrappers for heap management, they exit if out-of-memory.
|
|
|
|
*/
|
2010-11-22 21:06:02 +00:00
|
|
|
|
2010-11-22 14:54:50 +00:00
|
|
|
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);
|
|
|
|
|
2010-11-22 21:06:02 +00:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* Logging
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Returns the positive priority if name is configured to be logged, or -1 */
|
|
|
|
extern int check_logcat(const char *name);
|
|
|
|
|
2010-11-22 14:54:50 +00:00
|
|
|
/* 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 */
|
|
|
|
#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,
|
|
|
|
const char *cat,
|
|
|
|
const char *fmt,
|
|
|
|
...)
|
|
|
|
__attribute__((format(printf, 4, 5)));
|
|
|
|
|
2010-11-22 21:06:02 +00:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* File-descriptor helpers
|
|
|
|
*/
|
|
|
|
|
2010-11-22 14:54:50 +00:00
|
|
|
/* 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. */
|
|
|
|
extern void close_exec_fd(int fd);
|
|
|
|
|
2010-11-28 09:15:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An observance to be called when a file descritor becomes
|
|
|
|
* read-ready or write-ready.
|
|
|
|
*/
|
|
|
|
struct observance {
|
|
|
|
/* The file descriptor to observe. */
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* Function to call when read becomes ready. */
|
|
|
|
void (*ready)(lua_State *, struct observance *);
|
|
|
|
|
|
|
|
/* Function to call when write becomes ready. */
|
|
|
|
void (*writey)(lua_State *, struct observance *);
|
|
|
|
|
|
|
|
/* Function to call to clean up */
|
|
|
|
void (*tidy)(struct observance *);
|
|
|
|
|
|
|
|
/* Extra tokens to pass to the functions- */
|
|
|
|
void *extra;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* makes the core observe a file descriptor */
|
2010-11-26 16:17:36 +00:00
|
|
|
extern void observe_fd(
|
|
|
|
int fd,
|
2010-11-28 09:15:54 +00:00
|
|
|
void (*ready) (lua_State *, struct observance *),
|
|
|
|
void (*writey)(lua_State *, struct observance *),
|
|
|
|
void (*tidy) (struct observance *),
|
|
|
|
void *extra
|
|
|
|
);
|
2010-11-22 21:06:02 +00:00
|
|
|
|
|
|
|
/* stops the core to observe a file descriptor */
|
2010-11-28 09:15:54 +00:00
|
|
|
extern void nonobserve_fd(int fd);
|
2010-11-22 21:06:02 +00:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* inotify
|
|
|
|
*/
|
2010-11-26 16:52:24 +00:00
|
|
|
#ifdef LSYNCD_WITH_INOTIFY
|
2010-11-22 21:06:02 +00:00
|
|
|
extern void register_inotify(lua_State *L);
|
|
|
|
extern void open_inotify(lua_State *L);
|
2010-11-28 09:15:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* fanotify
|
|
|
|
*/
|
|
|
|
#ifdef LSYNCD_WITH_FANOTIFY
|
|
|
|
extern void register_fanotify(lua_State *L);
|
|
|
|
extern void open_fanotify(lua_State *L);
|
2010-11-26 16:52:24 +00:00
|
|
|
#endif
|
2010-11-26 16:17:36 +00:00
|
|
|
|
2010-11-26 16:52:24 +00:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* /dev/fsevents
|
|
|
|
*/
|
|
|
|
#ifdef LSYNCD_WITH_FSEVENTS
|
|
|
|
extern void open_fsevents(lua_State *L);
|
|
|
|
#endif
|
2010-11-26 16:17:36 +00:00
|
|
|
|
2010-11-22 21:06:02 +00:00
|
|
|
|
2010-11-22 14:54:50 +00:00
|
|
|
#endif
|