mirror of
https://github.com/upa/mscp.git
synced 2026-05-19 11:07:28 +08:00
fix dryrun handling on main.c
This commit is contained in:
24
src/main.c
24
src/main.c
@@ -44,7 +44,7 @@ void usage(bool print_help) {
|
|||||||
"\n"
|
"\n"
|
||||||
" -v increment verbose output level\n"
|
" -v increment verbose output level\n"
|
||||||
" -q disable output\n"
|
" -q disable output\n"
|
||||||
" -D dry run\n"
|
" -D dry run. check copy destinations with -vvv\n"
|
||||||
" -r no effect\n"
|
" -r no effect\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -l LOGIN_NAME login name\n"
|
" -l LOGIN_NAME login name\n"
|
||||||
@@ -197,6 +197,7 @@ int main(int argc, char **argv)
|
|||||||
int pipe_fd[2];
|
int pipe_fd[2];
|
||||||
int ch, n, i, ret;
|
int ch, n, i, ret;
|
||||||
char *remote;
|
char *remote;
|
||||||
|
bool dryrun = false;
|
||||||
|
|
||||||
memset(&s, 0, sizeof(s));
|
memset(&s, 0, sizeof(s));
|
||||||
memset(&o, 0, sizeof(o));
|
memset(&o, 0, sizeof(o));
|
||||||
@@ -234,7 +235,7 @@ int main(int argc, char **argv)
|
|||||||
o.severity = MSCP_SEVERITY_NONE;
|
o.severity = MSCP_SEVERITY_NONE;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
o.dryrun = true;
|
dryrun = true;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
/* for compatibility with scp */
|
/* for compatibility with scp */
|
||||||
@@ -319,13 +320,14 @@ int main(int argc, char **argv)
|
|||||||
remote = t[i - 1].remote;
|
remote = t[i - 1].remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pipe(pipe_fd) < 0) {
|
if (!dryrun) {
|
||||||
fprintf(stderr, "pipe: %s\n", strerrno());
|
if (pipe(pipe_fd) < 0) {
|
||||||
return -1;
|
fprintf(stderr, "pipe: %s\n", strerrno());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
msg_fd = pipe_fd[0];
|
||||||
|
o.msg_fd = pipe_fd[1];
|
||||||
}
|
}
|
||||||
msg_fd = pipe_fd[0];
|
|
||||||
o.msg_fd = pipe_fd[1];
|
|
||||||
|
|
||||||
|
|
||||||
if ((m = mscp_init(remote, &o, &s)) == NULL) {
|
if ((m = mscp_init(remote, &o, &s)) == NULL) {
|
||||||
fprintf(stderr, "mscp_init: %s\n", mscp_get_error());
|
fprintf(stderr, "mscp_init: %s\n", mscp_get_error());
|
||||||
@@ -354,6 +356,11 @@ int main(int argc, char **argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dryrun) {
|
||||||
|
ret = 0;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (pthread_create(&tid_stat, NULL, print_stat_thread, NULL) < 0) {
|
if (pthread_create(&tid_stat, NULL, print_stat_thread, NULL) < 0) {
|
||||||
fprintf(stderr, "pthread_create: %s\n", strerrno());
|
fprintf(stderr, "pthread_create: %s\n", strerrno());
|
||||||
return -1;
|
return -1;
|
||||||
@@ -373,6 +380,7 @@ int main(int argc, char **argv)
|
|||||||
pthread_cancel(tid_stat);
|
pthread_cancel(tid_stat);
|
||||||
pthread_join(tid_stat, NULL);
|
pthread_join(tid_stat, NULL);
|
||||||
|
|
||||||
|
out:
|
||||||
mscp_cleanup(m);
|
mscp_cleanup(m);
|
||||||
mscp_free(m);
|
mscp_free(m);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user