redmine

Polishing examples

... ... @@ -2,7 +2,9 @@ ACLOCAL_AMFLAGS = -I m4
SUBDIRS = examples
if CLSYNC
bin_PROGRAMS = clsync
bin_PROGRAMS = clsync gencompilerflags
gencompilerflags_SOURCES = gencompilerflags.c
clsync_SOURCES = calc.c cluster.c error.c fileutils.c glibex.c \
indexes.c main.c malloc.c rules.c stringex.c sync.c \
... ... @@ -76,7 +78,12 @@ if SOCKET
clsync_SOURCES += socket.c control.c program.h
endif
main.o: revision.h
gencompilerflags_CFLAGS = $(clsync_CFLAGS)
main.o: compilerflags.h
compilerflags.h: gencompilerflags
./gencompilerflags > compilerflags.h
dist_man_MANS = man/man1/clsync.1
endif
... ... @@ -108,11 +115,14 @@ libclsync_includedir = $(includedir)/libclsync
if CLSYNC
clsync_include_HEADERS = \
clsync.h \
port-hacks.h \
configuration.h \
ctx.h \
error.h \
indexes.h \
malloc.h
malloc.h \
compilerflags.h
if SOCKET
clsync_include_HEADERS += \
socket.h
... ... @@ -134,7 +144,7 @@ if LIBCLSYNC
pkgconfig_DATA = pkgconfig/libclsync.pc
endif
CLEANFILES = revision.h
CLEANFILES = compilerflags.h gencompilerflags
if CLSYNC
CLEANFILES += examples/rules
clean-local:
... ...
... ... @@ -24,6 +24,10 @@
#include <stdint.h>
#include <sys/types.h>
#ifndef CLSYNC_ITSELF
# include <clsync/port-hacks.h>
#endif
#define CLSYNC_API_VERSION 2
enum eventobjtype {
... ...
... ... @@ -68,6 +68,8 @@
#include <libgen.h>
#include <pthread.h>
#define CLSYNC_ITSELF
#include "configuration.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
... ...
... ... @@ -395,11 +395,5 @@ struct ctx {
};
typedef struct ctx ctx_t;
struct fileinfo {
stat64_t lstat;
};
typedef struct fileinfo fileinfo_t;
#endif
... ...
... ... @@ -3,6 +3,7 @@
#include <errno.h>
// Required header:
#include <clsync/compilerflags.h>
#include <clsync/clsync.h>
// Optional headers:
... ... @@ -10,10 +11,10 @@
#include <clsync/error.h>
#include <clsync/ctx.h>
struct ctx *ctx_p = NULL;
struct indexes *indexes_p = NULL;
static struct ctx *ctx_p = NULL;
static struct indexes *indexes_p = NULL;
char *argv[11] = {NULL};
static const char *argv[11] = {NULL};
// Optional function, you can erase it.
int clsyncapi_init(struct ctx *_ctx_p, struct indexes *_indexes_p) {
... ... @@ -22,17 +23,17 @@ int clsyncapi_init(struct ctx *_ctx_p, struct indexes *_indexes_p) {
ctx_p = _ctx_p;
indexes_p = _indexes_p;
if(ctx_p->destdir == NULL) {
if (ctx_p->destdir == NULL) {
error("dest-dir is not set.");
return EINVAL;
}
if(ctx_p->flags[RSYNCPREFERINCLUDE]) {
if (ctx_p->flags[RSYNCPREFERINCLUDE]) {
error("clsync-synchandler-rsyncso.so cannot be used in conjunction with \"--rsync-prefer-include\" option.");
return EINVAL;
}
if(ctx_p->flags[THREADING]) {
if (ctx_p->flags[THREADING]) {
error("this handler is not pthread-safe.");
return EINVAL;
}
... ... @@ -52,12 +53,12 @@ int clsyncapi_init(struct ctx *_ctx_p, struct indexes *_indexes_p) {
int clsyncapi_rsync(const char *inclistfile, const char *exclistfile) {
debug(1, "inclistfile == \"%s\"; exclistfile == \"%s\"", inclistfile, exclistfile);
argv[3] = (char *)exclistfile;
argv[5] = (char *)inclistfile;
argv[3] = exclistfile;
argv[5] = inclistfile;
if(ctx_p->flags[DEBUG] >= 3) {
if (ctx_p->flags[DEBUG] >= 3) {
int i=0;
while(argv[i] != NULL) {
while (argv[i] != NULL) {
debug(3, "argv[%i] == \"%s\"", i, argv[i]);
i++;
}
... ... @@ -65,7 +66,7 @@ int clsyncapi_rsync(const char *inclistfile, const char *exclistfile) {
// Forking
int pid = clsyncapi_fork(ctx_p);
switch(pid) {
switch (pid) {
case -1:
error("Cannot fork().");
return errno;
... ... @@ -75,7 +76,7 @@ int clsyncapi_rsync(const char *inclistfile, const char *exclistfile) {
}
int status;
if(waitpid(pid, &status, 0) != pid) {
if (waitpid(pid, &status, 0) != pid) {
error("Cannot waitid().");
return errno;
}
... ...
... ... @@ -3,6 +3,7 @@
#include <errno.h>
// Required header:
#include <clsync/compilerflags.h>
#include <clsync/clsync.h>
// Optional headers:
... ...
#include <stdio.h>
int main() {
printf("%s",
#ifdef _DEBUG_SUPPORT
"#define _DEBUG_SUPPORT\n"
#endif
#ifdef _DEBUG_FORCE
"#define _DEBUG_FORCE\n"
#endif
#ifdef KQUEUE_SUPPORT
"#define KQUEUE_SUPPORT\n"
#endif
#ifdef INOTIFY_SUPPORT
"#define INOTIFY_SUPPORT\n"
#endif
#ifdef INOTIFY_OLD
"#define INOTIFY_OLD\n"
#endif
#ifdef FANOTIFY_SUPPORT
"#define FANOTIFY_SUPPORT\n"
#endif
#ifdef BSM_SUPPORT
"#define BSM_SUPPORT\n"
#endif
#ifdef GIO_SUPPORT
"#define GIO_SUPPORT\n"
#endif
#ifdef DTRACEPIPE_SUPPORT
"#define DTRACEPIPE_SUPPORT\n"
#endif
#ifdef BACKTRACE_SUPPORT
"#define BACKTRACE_SUPPORT\n"
#endif
#ifdef CAPABILITIES_SUPPORT
"#define CAPABILITIES_SUPPORT\n"
#endif
#ifdef SECCOMP_SUPPORT
"#define SECCOMP_SUPPORT\n"
#endif
#ifdef GETMNTENT_SUPPORT
"#define GETMNTENT_SUPPORT\n"
#endif
#ifdef UNSHARE_SUPPORT
"#define UNSHARE_SUPPORT\n"
#endif
#ifdef PIVOTROOT_OPT_SUPPORT
"#define PIVOTROOT_OPT_SUPPORT\n"
#endif
#ifdef CGROUP_SUPPORT
"#define CGROUP_SUPPORT\n"
#endif
#ifdef TRE_SUPPORT
"#define TRE_SUPPORT\n"
#endif
#ifdef HL_LOCKS
"#define HL_LOCKS\n"
#endif
);
return 0;
}
... ...
... ... @@ -26,6 +26,11 @@
#include "error.h"
#include "malloc.h"
struct fileinfo {
stat64_t lstat;
};
typedef struct fileinfo fileinfo_t;
struct indexes {
GHashTable *wd2fpath_ht; // watching descriptor -> file path
GHashTable *fpath2wd_ht; // file path -> watching descriptor
... ...
... ... @@ -2488,6 +2488,7 @@ int main(int _argc, char *_argv[]) {
error("Got error while realpath() on \"%s\" [#1].", ctx_p->destdir);
ret = errno;
}
debug(5, "rdestdir == \"%s\"", rdestdir);
if (!ret) {
parse_parameter(ctx_p, DESTDIR, rdestdir, PS_CORRECTION);
... ... @@ -2523,6 +2524,17 @@ int main(int _argc, char *_argv[]) {
}
}
if (ctx_p->handlerfpath != NULL) {
char *rhandlerfpath = realpath(ctx_p->handlerfpath, NULL);
if (rhandlerfpath == NULL) {
error("Got error while realpath() on \"%s\" [#0].", ctx_p->handlerfpath);
ret = errno;
}
debug(5, "rhandlerfpath == \"%s\"", rhandlerfpath);
ctx_p->handlerfpath = rhandlerfpath;
}
debug(9, "chdir(\"%s\");", ctx_p->watchdir);
if (chdir(ctx_p->watchdir)) {
error("Got error while chdir(\"%s\")", ctx_p->watchdir);
... ... @@ -2792,7 +2804,7 @@ int main(int _argc, char *_argv[]) {
}
}
debug(1, "%s [%s] (%p) -> %s [%s]", ctx_p->watchdir, ctx_p->watchdirwslash, ctx_p->watchdirwslash, ctx_p->destdir?ctx_p->destdir:"", ctx_p->destdirwslash?ctx_p->destdirwslash:"");
debug(1, "%s [%s] (%p) -> %s [%s] (%p)", ctx_p->watchdir, ctx_p->watchdirwslash, ctx_p->watchdirwslash, ctx_p->destdir?ctx_p->destdir:"", ctx_p->destdirwslash?ctx_p->destdirwslash:"", ctx_p->destdirwslash);
{
int rc = ctx_check(ctx_p);
... ...
... ... @@ -62,9 +62,11 @@
#endif
#ifndef O_PATH
#ifdef CLSYNC_ITSELF
# ifndef O_PATH
# warning O_PATH is not set
# define O_PATH 0
# endif
#endif
#endif // __PORT_HACKS_H
... ...
... ... @@ -3799,7 +3799,7 @@ int sync_run(ctx_t *ctx_p) {
// dlopen()
void *synchandler_handle = dlopen(ctx_p->handlerfpath, RTLD_NOW|RTLD_LOCAL);
if(synchandler_handle == NULL) {
if (synchandler_handle == NULL) {
error("Cannot load shared object file \"%s\": %s", ctx_p->handlerfpath, dlerror());
return -1;
}
... ... @@ -3807,16 +3807,16 @@ int sync_run(ctx_t *ctx_p) {
// resolving init, sync and deinit functions' handlers
ctx_p->handler_handle = synchandler_handle;
ctx_p->handler_funct.init = (api_funct_init) dlsym(ctx_p->handler_handle, API_PREFIX"init");
if(ctx_p->flags[MODE] == MODE_RSYNCSO) {
if (ctx_p->flags[MODE] == MODE_RSYNCSO) {
ctx_p->handler_funct.rsync = (api_funct_rsync)dlsym(ctx_p->handler_handle, API_PREFIX"rsync");
if(ctx_p->handler_funct.rsync == NULL) {
if (ctx_p->handler_funct.rsync == NULL) {
char *dlerror_str = dlerror();
error("Cannot resolve symbol "API_PREFIX"rsync in shared object \"%s\": %s",
ctx_p->handlerfpath, dlerror_str != NULL ? dlerror_str : "No error description returned.");
}
} else {
ctx_p->handler_funct.sync = (api_funct_sync)dlsym(ctx_p->handler_handle, API_PREFIX"sync");
if(ctx_p->handler_funct.sync == NULL) {
if (ctx_p->handler_funct.sync == NULL) {
char *dlerror_str = dlerror();
error("Cannot resolve symbol "API_PREFIX"sync in shared object \"%s\": %s",
ctx_p->handlerfpath, dlerror_str != NULL ? dlerror_str : "No error description returned.");
... ... @@ -3825,8 +3825,8 @@ int sync_run(ctx_t *ctx_p) {
ctx_p->handler_funct.deinit = (api_funct_deinit)dlsym(ctx_p->handler_handle, API_PREFIX"deinit");
// running init function
if(ctx_p->handler_funct.init != NULL)
if((ret = ctx_p->handler_funct.init(ctx_p, &indexes))) {
if (ctx_p->handler_funct.init != NULL)
if ((ret = ctx_p->handler_funct.init(ctx_p, &indexes))) {
error("Cannot init sync-handler module.");
return ret;
}
... ... @@ -3834,7 +3834,7 @@ int sync_run(ctx_t *ctx_p) {
// Initializing rand-generator if it's required
if(ctx_p->listoutdir)
if (ctx_p->listoutdir)
srand(time(NULL));
if (!ctx_p->flags[ONLYINITSYNC]) {
... ...