From 5db36e0af847f18c2efa3678dd61c8474eba595a Mon Sep 17 00:00:00 2001 From: Dmitry Yu Okunev Date: Thu, 15 Jan 2015 16:15:05 +0300 Subject: [PATCH] Polishing examples --- Makefile.am | 18 ++++++++++++++---- clsync.h | 4 ++++ common.h | 2 ++ ctx.h | 6 ------ examples/clsync-synchandler-rsyncso.c | 25 +++++++++++++------------ examples/clsync-synchandler-so.c | 1 + gencompilerflags.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ indexes.h | 5 +++++ main.c | 14 +++++++++++++- port-hacks.h | 8 +++++--- sync.c | 14 +++++++------- 11 files changed, 126 insertions(+), 33 deletions(-) create mode 100644 gencompilerflags.c diff --git a/Makefile.am b/Makefile.am index 645c4f7..0a81606 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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: diff --git a/clsync.h b/clsync.h index b98cc33..c8aad79 100644 --- a/clsync.h +++ b/clsync.h @@ -24,6 +24,10 @@ #include #include +#ifndef CLSYNC_ITSELF +# include +#endif + #define CLSYNC_API_VERSION 2 enum eventobjtype { diff --git a/common.h b/common.h index 5b1019d..4f1f1d5 100644 --- a/common.h +++ b/common.h @@ -68,6 +68,8 @@ #include #include +#define CLSYNC_ITSELF + #include "configuration.h" #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/ctx.h b/ctx.h index abad07d..967a876 100644 --- a/ctx.h +++ b/ctx.h @@ -395,11 +395,5 @@ struct ctx { }; typedef struct ctx ctx_t; - -struct fileinfo { - stat64_t lstat; -}; -typedef struct fileinfo fileinfo_t; - #endif diff --git a/examples/clsync-synchandler-rsyncso.c b/examples/clsync-synchandler-rsyncso.c index a45e799..5501969 100644 --- a/examples/clsync-synchandler-rsyncso.c +++ b/examples/clsync-synchandler-rsyncso.c @@ -3,6 +3,7 @@ #include // Required header: +#include #include // Optional headers: @@ -10,10 +11,10 @@ #include #include -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; } diff --git a/examples/clsync-synchandler-so.c b/examples/clsync-synchandler-so.c index ff73ccb..fb38640 100644 --- a/examples/clsync-synchandler-so.c +++ b/examples/clsync-synchandler-so.c @@ -3,6 +3,7 @@ #include // Required header: +#include #include // Optional headers: diff --git a/gencompilerflags.c b/gencompilerflags.c new file mode 100644 index 0000000..4474bfb --- /dev/null +++ b/gencompilerflags.c @@ -0,0 +1,62 @@ +#include + +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; +} diff --git a/indexes.h b/indexes.h index 0c715cc..2ab5fce 100644 --- a/indexes.h +++ b/indexes.h @@ -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 diff --git a/main.c b/main.c index 7e228c1..53e71ae 100644 --- a/main.c +++ b/main.c @@ -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); diff --git a/port-hacks.h b/port-hacks.h index 67032df..1e742ee 100644 --- a/port-hacks.h +++ b/port-hacks.h @@ -62,9 +62,11 @@ #endif -#ifndef O_PATH -# warning O_PATH is not set -# define O_PATH 0 +#ifdef CLSYNC_ITSELF +# ifndef O_PATH +# warning O_PATH is not set +# define O_PATH 0 +# endif #endif #endif // __PORT_HACKS_H diff --git a/sync.c b/sync.c index b49941a..b6d3341 100644 --- a/sync.c +++ b/sync.c @@ -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]) { -- libgit2 0.24.0