mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-09-27 22:49:02 +00:00
refactor code to use execv instead of execl.
This commit is contained in:
parent
e6782df02d
commit
c04d167c76
36
lsyncd.c
36
lsyncd.c
@ -354,11 +354,30 @@ bool rsync(char const * src, const char * dest, bool recursive)
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
char const * opts = recursive ? "-ltr" : "-ltd";
|
char const * opts = recursive ? "-ltr" : "-ltd";
|
||||||
|
const int MAX_ARGS = 100;
|
||||||
|
char * argv[MAX_ARGS];
|
||||||
|
int argc=0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
argv[argc++] = s_strdup(rsync_binary);
|
||||||
|
argv[argc++] = s_strdup("--delete");
|
||||||
|
argv[argc++] = s_strdup(opts);
|
||||||
if (exclude_file) {
|
if (exclude_file) {
|
||||||
printlogf(LOG_DEBUG, "exec %s(%s,%s,%s,%s,%s,%s)", rsync_binary, "--delete", opts, "--exclude-from", exclude_file, src, dest);
|
argv[argc++] = s_strdup("--exclude-from");
|
||||||
} else {
|
argv[argc++] = s_strdup(exclude_file);
|
||||||
printlogf(LOG_DEBUG, "exec %s(%s,%s,%s,%s)", rsync_binary, "--delete", opts, src, dest);
|
}
|
||||||
|
argv[argc++] = s_strdup(src);
|
||||||
|
argv[argc++] = s_strdup(dest);
|
||||||
|
argv[argc++] = NULL;
|
||||||
|
|
||||||
|
if (argc > MAX_ARGS) { /* check for error condition */
|
||||||
|
printlogf(LOG_ERROR, "Internal error: too many (%i) options passed", argc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* debug dump of command-line options */
|
||||||
|
for (i=0; i<argc; ++i) {
|
||||||
|
printlogf(LOG_DEBUG, "exec parameter %i:%s", i, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag_dryrun) {
|
if (flag_dryrun) {
|
||||||
@ -373,17 +392,18 @@ bool rsync(char const * src, const char * dest, bool recursive)
|
|||||||
freopen(logfile, "a", stderr);
|
freopen(logfile, "a", stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exclude_file) {
|
execv(rsync_binary, argv);
|
||||||
execl(rsync_binary, rsync_binary, "--delete", opts, "--exclude-from", exclude_file, src, dest, NULL);
|
|
||||||
} else {
|
|
||||||
execl(rsync_binary, rsync_binary, "--delete", opts, src, dest, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
printlogf(LOG_ERROR, "Failed executing [%s]", rsync_binary);
|
printlogf(LOG_ERROR, "Failed executing [%s]", rsync_binary);
|
||||||
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i=0; i<argc; ++i) {
|
||||||
|
if (argv[i])
|
||||||
|
free(argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
assert(WIFEXITED(status));
|
assert(WIFEXITED(status));
|
||||||
if (WEXITSTATUS(status)){
|
if (WEXITSTATUS(status)){
|
||||||
|
Loading…
Reference in New Issue
Block a user