redmine

Added support of "direct" mode

... ... @@ -123,6 +123,9 @@
#define COLLECTDELAY_INSTANT ((unsigned int)~0)
#define MSG_SECURITY_PROBLEM "Security problem: argv_free(NULL). Don't use this application until the bug fill be fixed. Report about the problem to: "AUTHOR
#define require_strlen_le(str, limit) \
if (strlen(str) >= limit)\
critical("length of "TOSTR(str)" (\"%s\") >= "TOSTR(limit));\
... ... @@ -130,7 +133,8 @@
enum paramsource_enum {
PS_UNKNOWN = 0,
PS_ARGUMENT,
PS_CONFIG
PS_CONFIG,
PS_DEFAULTS,
};
typedef enum paramsource_enum paramsource_t;
... ... @@ -199,7 +203,7 @@ struct threadinfo {
uint32_t iteration;
thread_callbackfunct_t callback;
thread_callbackfunct_arg_t *callback_arg;
char **argv;
char **argv;
pthread_t pthread;
int exitcode;
int errcode;
... ... @@ -251,6 +255,12 @@ struct dosync_arg {
api_eventinfo_t *api_ei;
int api_ei_count;
char buf[BUFSIZ+1];
// for be read by sync_parameter_get():
const char *include_list[MAXARGUMENTS+2];
size_t include_list_count;
const char *list_type_str;
const char *evmask_str;
};
struct doubleentry {
... ...
... ... @@ -103,3 +103,31 @@ filesz:1M\n\
#define DTRACE_PATH "dtrace"
#define SYSLOG_BUFSIZ (1<<16)
#define DEFAULT_SYNCHANDLER_ARGS_SIMPLE "sync \%label\% \%EVENT-MASK\% \%INCLUDE-LIST\%"
#define DEFAULT_SYNCHANDLER_ARGS_DIRECT "\%INCLUDE-LIST\% \%destination-dir\%/"
#define DEFAULT_SYNCHANDLER_ARGS_SHELL_NR "synclist \%label\% \%INCLUDE-LIST-PATH\%"
#define DEFAULT_SYNCHANDLER_ARGS_SHELL_R "initialsync \%label\% \%INCLUDE-LIST\%"
#define DEFAULT_SYNCHANDLER_ARGS_RDIRECT_E "-aH --delete --exclude-from \%EXCLUDE-LIST-PATH\% --include-from \%INCLUDE-LIST-PATH\% --exclude=* \%watch-dir\%/ \%destination-dir\%/"
#define DEFAULT_SYNCHANDLER_ARGS_RDIRECT_I "-aH --delete --include-from \%INCLUDE-LIST-PATH\% --exclude=* \%watch-dir\%/ \%destination-dir\%/"
#define DEFAULT_SYNCHANDLER_ARGS_RSHELL_E "rsynclist \%label% \%INCLUDE-LIST-PATH\% %EXCLUDE-LIST-PATH%"
#define DEFAULT_SYNCHANDLER_ARGS_RSHELL_I "rsynclist \%label% \%INCLUDE-LIST-PATH\%"
#define RSYNC_ARGS_E { \
"-aH", \
"--delete", \
"--exclude-from", \
"\%EXCLUDE-LIST-PATH\%",\
"--include-from", \
"\%INCLUDE-LIST-PATH\%",\
"--exclude=*", \
NULL }
#define RSYNC_ARGS_I { \
"-aH", \
"--delete", \
"--include-from", \
"\%INCLUDE-LIST-PATH\%",\
"--exclude=*", \
NULL }
... ...
... ... @@ -99,13 +99,15 @@ enum flags_enum {
MONITOR = 19|OPTION_LONGOPTONLY,
SYNCHANDLERARGS = 20|OPTION_LONGOPTONLY,
SYNCHANDLERARGS0 = 20|OPTION_LONGOPTONLY,
SYNCHANDLERARGS1 = 21|OPTION_LONGOPTONLY,
};
typedef enum flags_enum flags_t;
enum mode_id {
MODE_UNSET = 0,
MODE_SIMPLE,
MODE_DIRECT,
MODE_SHELL,
MODE_RSYNCSHELL,
MODE_RSYNCDIRECT,
... ... @@ -176,6 +178,28 @@ struct notifyenginefuncts {
int (*add_watch_dir)(struct ctx *ctx_p, struct indexes *indexes_p, const char *const accpath);
};
enum shflags {
SHFL_NONE = 0x00,
SHFL_RSYNC_ARGS = 0x01,
SHFL_INCLUDE_LIST = 0x02,
SHFL_INCLUDE_LIST_PATH = 0x04,
SHFL_EXCLUDE_LIST_PATH = 0x08,
};
typedef enum shflags shflags_t;
enum shargsid {
SHARGS_PRIMARY = 0,
SHARGS_INITIAL,
SHARGS_MAX,
};
struct synchandler_args {
char *v[MAXARGUMENTS];
int c;
char isexpanded[MAXARGUMENTS];
};
typedef struct synchandler_args synchandler_args_t;
struct ctx {
#ifndef LIBCLSYNC
uid_t uid;
... ... @@ -245,8 +269,8 @@ struct ctx {
void *indexes_p;
void *fsmondata;
char *synchandler_argv[MAXARGUMENTS];
int synchandler_argc;
synchandler_args_t synchandler_args[SHARGS_MAX];
shflags_t synchandler_argf;
};
typedef struct ctx ctx_t;
... ...
#!/bin/sh
mkdir -m 700 -p testdir/from
cat > rules <<EOF
-d^[Dd]ont[Ss]ync\$
+*.*
EOF
clsync -K example-simple -M simple -w2 -t5 -W ./testdir/from -S $(which echo) -R rules $@
... ...
This diff is collapsed. Click to expand it.
... ... @@ -19,5 +19,12 @@
extern int main_rehash(ctx_t *ctx_p);
extern int main_status_update(ctx_t *ctx_p, state_t state);
extern char *parameter_expand(ctx_t *ctx_p, char *arg, int ignorewarnings, char *(*parameter_get)(char *variable_name, void *arg), void *parameter_get_arg);
extern char *parameter_expand(
ctx_t *ctx_p,
char *arg,
int exceptionflags,
int *macros_count_p,
int *expand_count_p,
const char *(*parameter_get)(const char *variable_name, void *arg),
void *parameter_get_arg
);
... ...
... ... @@ -44,13 +44,19 @@ will be substituted with previously set value of option
(see
.BR "CONFIGURATION FILE" )
.I sync\-handler\-arguments
applies only to modes:
.RS
simple, shell, rsyncdirect, rsyncshell
.RE
To set
.I sync\-handler\-arguments
in config file use '--'. An example:
.RS
-- = -aH --exclude-from %EXCLUDE-LIST% --include-from=%INCLUDE-LIST% --exclude '*' %watch-dir%/ %destination-dir%/
.RE
.B \-W, \-\-watch\-dir
.I watch\-dir
.RS 8
... ... @@ -984,17 +990,40 @@ is only a convenient way to run a syncing script.
.B clsync
can run
.I sync\-handler
in six ways. Which way will be used depends on specified mode (see
in seven ways. Which way will be used depends on specified mode (see
.IR \-\-mode )
.I sync\-handler\-arguments
is used only in modes:
.RS
simple
.br
shell
.br
rsyncdirect
.br
rsyncshell
.RE
If
.I sync\-handler\-arguments
is not set then default setting is used.
case
.B simple
.RS
Executes for every syncing file/dir:
.br
.I sync\-handler
.RS
.I sync\-handler sync\-handler\-arguments
.RE
Default
.I sync\-handler\-arguments
are:
.RS
sync
.I label evmask path [nodes]
.I %label% %EVENT\-MASK% %INCLUDE\-LIST%
.RE
In this case,
.I sync\-handler
... ... @@ -1005,43 +1034,103 @@ With
it's passed bitmask of events with the file or directory (see
"/usr/include/linux/inotify.h").
Additional substitutions:
.RS
.B %EVENT\-MASK%
.RS
Is replaced by integer of events IDs.
.RE
.B %INCLUDE\-LIST%
.RS
Is replaced by the list of files/dirs to be synced
.RE
.RE
Not recommended. Not well tested.
.RE
case
.B direct
.RS
Executes for every sync:
.RS
.I sync\-handler sync\-handler\-arguments
.RE
.I sync\-handler
is supposed to be a path to
.BR cp "-like"
utility.
Default
.I sync\-handler\-arguments
are:
.RS
%INCLUDE\-LIST% %destination-dir%/
.RE
Additional substitutions:
.RS
.B %INCLUDE\-LIST%
.RS
Is replaced by the list of files/dirs to be synced
.RE
.RE
Recommended case.
.RE
case
.B shell
.RS
Executes for every sync (if
.B recursivesync
is not used instead):
.br
.I sync\-handler
synclist
.I label listpath [nodes]
.RS
.I sync\-handler sync\-handler\-arguments
.RE
Default
.I sync\-handler\-arguments
are:
.RS
synclist %label% %INCLUDE\-LIST\-PATH%
.RE
Executes for initial syncs if option
Default
.I sync\-handler\-arguments
for initial sync if
.I \-\-have\-recursive\-sync
is set:
.br
.I sync\-handler
recursivesync
.I label dirpath [nodes]
is set are:
.RS
initialsync %label% %INCLUDE\-LIST%
.RE
In this case,
.I sync\-handler
is supposed to non\-recursively sync files and directories from list in a file
by path
.I listpath
(see below). With
.I evmask
it's passed bitmask of events with the file or directory (see
"/usr/include/linux/inotify.h").
by path %INCLUDE\-LIST\-PATH% on "synclist".
Also
.I sync\-handler
is supposed to recursively sync data from directory by path
.I dirpath
with manual excluding extra files.
%INCLUDE\-LIST\-PATH% with manual excluding extra files on "initialsync".
Additional substitutions:
.RS
.B %TYPE%
.RS
Is replaced by "sync"/"initialsync".
.RE
.B %INCLUDE\-LIST\-PATH%
.RS
Is replaced by the path of the include list file
.RE
.B %INCLUDE\-LIST%
.RS
Is replaced by the list of files/dirs to be synced
.RE
.RE
Not recommended. Not well tested.
.RE
... ... @@ -1050,47 +1139,50 @@ case
.B rsyncdirect
.RS
Executes for every sync:
.br
.RS
.I sync\-handler sync\-handler\-arguments
.RE
.I sync\-handler
is supposed to be a path to
.B rsync
binary.
Default value for
Default
.I sync\-handler\-arguments
is
are:
.RS
\-aH \-\-delete \-\-exclude\-from %EXCLUDE\-LIST% \-\-include\-from
%INCLUDE-LIST% --exclude='*' %watch-dir%/ %destination-dir%/
\-aH \-\-delete \-\-exclude\-from %EXCLUDE\-LIST\-PATH% \-\-include\-from
%INCLUDE\-LIST\-PATH% --exclude='*' %watch-dir%/ %destination-dir%/
.RE
if option
.I \-\-rsync-\-prefer\-include
is not set and
.RS
\-aH \-\-delete \-\-include\-from %INCLUDE-LIST% --exclude='*' %watch-dir%/
%destination-dir%/
\-aH \-\-delete \-\-include\-from %INCLUDE\-LIST\-PATH% --exclude='*'
%watch-dir%/ %destination-dir%/
.RE
if the option is set
Error code "24" from
.I sync\-handler
will be ignored in this case.
will be ignored in this case. We also recommend to ignore exitcode "23".
Additional substitutions:
.RS
%INCLUDE-LIST%
.B %INCLUDE\-LIST\-PATH%
.RS
Is replaced by the path of the include list file
.RE
.B %EXCLUDE\-LIST\-PATH%
.RS
Is replaced by path to include list file
Is replaced by the path of the exclude list file
.RE
%EXCLUDE-LIST%
.B %RSYNC\-ARGS%
.RS
Is replaced by path to exclude list file
Is replaced by default
.IR sync\-handler\-arguments ", but"
without "%watch-dir%/ %destination-dir%/"
.RE
.RE
... ... @@ -1101,17 +1193,23 @@ case
.B rsyncshell
.RS
Executes for every sync:
.br
.I sync\-handler
rsynclist
.I label rsync\-listpath [nodes] [rsync\-exclude\-listpath]
.RS
.I sync\-handler sync\-handler\-arguments
.RE
Default
.I sync\-handler\-arguments
are:
.RS
rsynclist %label% %INCLUDE\-LIST\-PATH% [%EXCLUDE\-LIST\-PATH%]
.RE
In this case,
.I sync\-handler
is supposed to run "rsync" application with parameters:
\-aH \-\-delete\-before \-\-include\-from
.I rsync\-listpath
.I %INCLUDE\-LIST\-PATH%
\-\-exclude '*'
if option
... ... @@ -1121,15 +1219,27 @@ is enabled.
And with parameters:
\-aH \-\-delete\-before \-\-exclude\-from
.I rsync\-exclude\-listpath
.I %EXCLUDE\-LIST\-PATH%
\-\-include\-from
.I rsync\-listpath
.I %INCLUDE\-LIST\-PATH%
\-\-exclude '*'
if option
.I \-\-rsync\-prefer\-include
is disabled.
Additional substitutions:
.RS
.B %INCLUDE\-LIST\-PATH%
.RS
Is replaced by the path of the rsync include list file
.RE
.B %EXCLUDE\-LIST\-PATH%
.RS
Is replaced by the path of the rsync exclude list file
.RE
.RE
Recommended case.
.RE
... ... @@ -1280,17 +1390,15 @@ See example file "clsync-synchandler-so.c".
Recommended case.
.RE
About the
.I label
The
.I %label%
see
.IR \-\-label .
.br
.I nodes
is comma-separated list of cluster nodes names where to sync to (see
.IR \-\-cluster-node-name )
The listfile by path
.I listpath
.I %INCLUDE\-LIST\-PATH%
(case
.BR shell ")"
contains lines separated by NL (without CR) of next format:
.RS
sync
... ...
... ... @@ -70,14 +70,15 @@ static int _str_splitargs(
}
int str_splitargs(
char *instr,
char *_instr,
int (*handler)(char *, size_t, void *),
void *arg
) {
debug(9, "");
char *arg_start, *ptr;
char *arg_start, *ptr, *instr;
int quotes = 0;
instr = strdup(_instr);
ptr = instr;
arg_start = instr;
while (1) {
... ... @@ -145,5 +146,7 @@ int str_splitargs(
}
}
return _str_splitargs(strchr(arg_start, 0), &arg_start, quotes, handler, arg);
int rc = _str_splitargs(strchr(arg_start, 0), &arg_start, quotes, handler, arg);
free(instr);
return rc;
}
... ...
This diff is collapsed. Click to expand it.
... ... @@ -48,4 +48,5 @@ extern int sync_prequeue_loadmark
);
extern int sync_prequeue_unload(struct ctx *ctx_p, struct indexes *indexes_p);
extern int *state_p;
extern const char *sync_parameter_get(const char *variable_name, void *_dosync_arg_p);
... ...