mirror of
https://github.com/upa/mscp.git
synced 2026-02-04 03:24:58 +08:00
fix -q to redirect stdout to /dev/null (#30)
This commit is contained in:
26
src/main.c
26
src/main.c
@@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -311,6 +312,24 @@ long atol_with_unit(char *value, bool i)
|
|||||||
return v * factor;
|
return v * factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int to_dev_null(int fd)
|
||||||
|
{
|
||||||
|
int nfd = open("/dev/null", O_WRONLY);
|
||||||
|
if (nfd < 0) {
|
||||||
|
pr_err("open /dev/null: %s", strerrno());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dup2(nfd, fd) < 0) {
|
||||||
|
pr_err("dup2: %s", strerrno());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(nfd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct mscp_ssh_opts s;
|
struct mscp_ssh_opts s;
|
||||||
@@ -320,7 +339,7 @@ int main(int argc, char **argv)
|
|||||||
int ch, n, i, ret;
|
int ch, n, i, ret;
|
||||||
int direction = 0;
|
int direction = 0;
|
||||||
char *remote = NULL, *checkpoint_save = NULL, *checkpoint_load = NULL;
|
char *remote = NULL, *checkpoint_save = NULL, *checkpoint_load = NULL;
|
||||||
bool dryrun = false, resume = false;
|
bool quiet = false, dryrun = false, resume = false;
|
||||||
int nr_options = 0;
|
int nr_options = 0;
|
||||||
|
|
||||||
memset(&s, 0, sizeof(s));
|
memset(&s, 0, sizeof(s));
|
||||||
@@ -378,7 +397,7 @@ int main(int argc, char **argv)
|
|||||||
o.severity++;
|
o.severity++;
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
o.severity = MSCP_SEVERITY_NONE;
|
quiet = true;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
dryrun = true;
|
dryrun = true;
|
||||||
@@ -441,6 +460,9 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (quiet)
|
||||||
|
to_dev_null(STDOUT_FILENO);
|
||||||
|
|
||||||
s.password = getenv(ENV_SSH_AUTH_PASSWORD);
|
s.password = getenv(ENV_SSH_AUTH_PASSWORD);
|
||||||
s.passphrase = getenv(ENV_SSH_AUTH_PASSPHRASE);
|
s.passphrase = getenv(ENV_SSH_AUTH_PASSPHRASE);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user