Fix for vppctl and interactive commands (VPP-1038) 62/9062/2
authorChris Luke <chrisy@flirble.org>
Thu, 26 Oct 2017 14:44:43 +0000 (10:44 -0400)
committerFlorin Coras <florin.coras@gmail.com>
Fri, 27 Oct 2017 22:47:16 +0000 (22:47 +0000)
- Interactive commands like "ping" read extra input from the
  input stream.
- In the case of "ping" it is simply a signal to cease the current
  operation.
- "vppctl", in non-interactive mode, will issue a "quit" immediately
  after the requested command to queue up closing of the session.
- This resulted in "ping" thinking a keypress was seen and returning
  control to the CLI; the "quit" command however is consumed by the
  keypress event handler and thus the session does not close.

- This patch reworks vppctl slightly to only issue "quit" after the
  command has completed. In particular it uses the fact that VPP issues
  NUL bytes as a surrogate prompt between output of commands to signal
  acknowledgement that the command has completed; vppctl now flags
  that the quit should be issued after the next such acknowledgement.
- Since input it still accepted, the user can still terminate the
  "ping" early, if desired.

Change-Id: I7e3dbe767f32f8e364ccb5f81799759b311585df
Signed-off-by: Chris Luke <chrisy@flirble.org>
src/vpp/app/vppctl.c

index f81a0ce..66fe00a 100644 (file)
@@ -147,6 +147,7 @@ main (int argc, char *argv[])
   u8 *cmd = 0;
   int do_quit = 0;
   int is_interactive = 0;
+  int acked = 1;               /* counts messages from VPP; starts at 1 */
   int sent_ttype = 0;
 
 
@@ -314,7 +315,10 @@ main (int argc, char *argv[])
                    }
 
                  while (q < (p + len) && !*q)
-                   q++;
+                   {
+                     q++;
+                     acked++;  /* every NUL is an acknowledgement */
+                   }
                  len -= q - p;
                  p = q;
                }
@@ -322,7 +326,7 @@ main (int argc, char *argv[])
              vec_reset_length (str);
            }
 
-         if (do_quit)
+         if (do_quit && do_quit < acked)
            {
              /* Ask the other end to close the connection */
              clib_socket_tx_add_formatted (s, "quit\n");
@@ -339,7 +343,7 @@ main (int argc, char *argv[])
              clib_socket_tx_add_formatted (s, "%s\n", cmd);
              clib_socket_tx (s);
              vec_free (cmd);
-             do_quit = 1;
+             do_quit = acked;  /* quit after the next response */
            }
        }
       else