]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add -m option to allow multiple commands on command line
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 4 Oct 2010 13:48:09 +0000 (15:48 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 4 Oct 2010 13:53:35 +0000 (15:53 +0200)
chrony.texi
chronyc.1
client.c

index d1c77b31a339aca7a39b128c92c4fa76ebca8ce5..beb6b40f72eebe5a0a7fe8b60d07081b29f47eed 100644 (file)
@@ -2741,6 +2741,9 @@ This option disables resolving IP addresses to hostnames.
 With this option hostnames will be resolved only to IPv4 addresses.
 @item -6
 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
 @c }}}
 @c {{{ SS:Security with chronyc
index 7183c2ef0cf60b824ae624a09a9c135f101b4c74..af0f060a17cccdb17843f193f1cbd5c26b493dde 100644 (file)
--- a/chronyc.1
+++ b/chronyc.1
@@ -38,6 +38,10 @@ resolve hostnames only to IPv4 addresses
 \fB\-6\fR
 resolve hostnames only to IPv6 addresses
 .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
 specify command.  If no command is given, chronyc will read commands
 interactively.
index 64147d1765eb0388c3b3e3be0222831214c43ce0..f2b195ad79f476318b4a8bc923eab5fe9e636ba1 100644 (file)
--- a/client.c
+++ b/client.c
@@ -2516,7 +2516,7 @@ process_line(char *line, int *quit)
 /* ================================================== */
 
 static int
-process_args(int argc, char **argv)
+process_args(int argc, char **argv, int multi)
 {
   int total_length, i, ret, quit;
   char *line;
@@ -2527,15 +2527,25 @@ process_args(int argc, char **argv)
   }
 
   line = (char *) malloc((2 + total_length) * sizeof(char));
-  line[0] = 0;
-  for (i=0; i<argc; i++) {
-    strcat(line, argv[i]);
-    if (i + 1 < argc)
-      strcat(line, " ");
-  }
-  strcat(line, "\n");
 
-  ret = process_line(line, &quit);
+  for (i = 0; i < argc; i++) {
+    line[0] = '\0';
+    if (multi) {
+      strcat(line, argv[i]);
+    } else {
+      for (; i < argc; i++) {
+        strcat(line, argv[i]);
+        if (i + 1 < argc)
+          strcat(line, " ");
+      }
+    }
+
+    strcat(line, "\n");
+
+    ret = process_line(line, &quit);
+    if (!ret)
+      break;
+  }
 
   free(line);
 
@@ -2563,7 +2573,7 @@ main(int argc, char **argv)
   char *line;
   const char *progname = argv[0];
   const char *hostname = "localhost";
-  int quit = 0, ret = 1;
+  int quit = 0, ret = 1, multi = 0;
   int port = DEFAULT_CANDM_PORT;
 
   /* Parse command line options */
@@ -2578,6 +2588,8 @@ main(int argc, char **argv)
       if (*argv) {
         port = atoi(*argv);
       }
+    } else if (!strcmp(*argv, "-m")) {
+      multi = 1;
     } else if (!strcmp(*argv, "-n")) {
       no_dns = 1;
     } else if (!strcmp(*argv, "-4")) {
@@ -2590,7 +2602,7 @@ main(int argc, char **argv)
       printf("chronyc (chrony) version %s\n", PROGRAM_VERSION_STRING);
       exit(0);
     } 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);
     } else {
       break; /* And process remainder of line as a command */
@@ -2608,7 +2620,7 @@ main(int argc, char **argv)
   open_io(hostname, port);
 
   if (argc > 0) {
-    ret = process_args(argc, argv);
+    ret = process_args(argc, argv, multi);
   } else {
     do {
       line = read_line();