Add -m option to allow multiple commands on command line
This commit is contained in:
parent
fd3702f973
commit
16676ae726
3 changed files with 31 additions and 12 deletions
|
@ -2741,6 +2741,9 @@ This option disables resolving IP addresses to hostnames.
|
||||||
With this option hostnames will be resolved only to IPv4 addresses.
|
With this option hostnames will be resolved only to IPv4 addresses.
|
||||||
@item -6
|
@item -6
|
||||||
With this option hostnames will be resolved only to IPv6 addresses.
|
With this option hostnames will be resolved only to IPv6 addresses.
|
||||||
|
@item -m
|
||||||
|
With this option multiple commands can be specified on the command line.
|
||||||
|
Each argument will be interpreted as a whole command.
|
||||||
@end table
|
@end table
|
||||||
@c }}}
|
@c }}}
|
||||||
@c {{{ SS:Security with chronyc
|
@c {{{ SS:Security with chronyc
|
||||||
|
|
|
@ -38,6 +38,10 @@ resolve hostnames only to IPv4 addresses
|
||||||
\fB\-6\fR
|
\fB\-6\fR
|
||||||
resolve hostnames only to IPv6 addresses
|
resolve hostnames only to IPv6 addresses
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-m\fR
|
||||||
|
allow multiple commands to be specified on the command line. Each argument
|
||||||
|
will be interpreted as a whole command.
|
||||||
|
.TP
|
||||||
\fIcommand\fR
|
\fIcommand\fR
|
||||||
specify command. If no command is given, chronyc will read commands
|
specify command. If no command is given, chronyc will read commands
|
||||||
interactively.
|
interactively.
|
||||||
|
|
24
client.c
24
client.c
|
@ -2516,7 +2516,7 @@ process_line(char *line, int *quit)
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
process_args(int argc, char **argv)
|
process_args(int argc, char **argv, int multi)
|
||||||
{
|
{
|
||||||
int total_length, i, ret, quit;
|
int total_length, i, ret, quit;
|
||||||
char *line;
|
char *line;
|
||||||
|
@ -2527,15 +2527,25 @@ process_args(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
line = (char *) malloc((2 + total_length) * sizeof(char));
|
line = (char *) malloc((2 + total_length) * sizeof(char));
|
||||||
line[0] = 0;
|
|
||||||
for (i=0; i<argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
|
line[0] = '\0';
|
||||||
|
if (multi) {
|
||||||
|
strcat(line, argv[i]);
|
||||||
|
} else {
|
||||||
|
for (; i < argc; i++) {
|
||||||
strcat(line, argv[i]);
|
strcat(line, argv[i]);
|
||||||
if (i + 1 < argc)
|
if (i + 1 < argc)
|
||||||
strcat(line, " ");
|
strcat(line, " ");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
strcat(line, "\n");
|
strcat(line, "\n");
|
||||||
|
|
||||||
ret = process_line(line, &quit);
|
ret = process_line(line, &quit);
|
||||||
|
if (!ret)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
|
|
||||||
|
@ -2563,7 +2573,7 @@ main(int argc, char **argv)
|
||||||
char *line;
|
char *line;
|
||||||
const char *progname = argv[0];
|
const char *progname = argv[0];
|
||||||
const char *hostname = "localhost";
|
const char *hostname = "localhost";
|
||||||
int quit = 0, ret = 1;
|
int quit = 0, ret = 1, multi = 0;
|
||||||
int port = DEFAULT_CANDM_PORT;
|
int port = DEFAULT_CANDM_PORT;
|
||||||
|
|
||||||
/* Parse command line options */
|
/* Parse command line options */
|
||||||
|
@ -2578,6 +2588,8 @@ main(int argc, char **argv)
|
||||||
if (*argv) {
|
if (*argv) {
|
||||||
port = atoi(*argv);
|
port = atoi(*argv);
|
||||||
}
|
}
|
||||||
|
} else if (!strcmp(*argv, "-m")) {
|
||||||
|
multi = 1;
|
||||||
} else if (!strcmp(*argv, "-n")) {
|
} else if (!strcmp(*argv, "-n")) {
|
||||||
no_dns = 1;
|
no_dns = 1;
|
||||||
} else if (!strcmp(*argv, "-4")) {
|
} else if (!strcmp(*argv, "-4")) {
|
||||||
|
@ -2590,7 +2602,7 @@ main(int argc, char **argv)
|
||||||
printf("chronyc (chrony) version %s\n", PROGRAM_VERSION_STRING);
|
printf("chronyc (chrony) version %s\n", PROGRAM_VERSION_STRING);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (!strncmp(*argv, "-", 1)) {
|
} else if (!strncmp(*argv, "-", 1)) {
|
||||||
fprintf(stderr, "Usage : %s [-h <hostname>] [-p <port-number>] [-n] [-4|-6] [command]\n", progname);
|
fprintf(stderr, "Usage : %s [-h <hostname>] [-p <port-number>] [-n] [-4|-6] [-m] [command]\n", progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
break; /* And process remainder of line as a command */
|
break; /* And process remainder of line as a command */
|
||||||
|
@ -2608,7 +2620,7 @@ main(int argc, char **argv)
|
||||||
open_io(hostname, port);
|
open_io(hostname, port);
|
||||||
|
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
ret = process_args(argc, argv);
|
ret = process_args(argc, argv, multi);
|
||||||
} else {
|
} else {
|
||||||
do {
|
do {
|
||||||
line = read_line();
|
line = read_line();
|
||||||
|
|
Loading…
Reference in a new issue