diff options
author | Chris Hall <GMCH@hestia.halldom.com> | 2010-04-28 12:20:52 +0100 |
---|---|---|
committer | Chris Hall <GMCH@hestia.halldom.com> | 2010-04-28 12:20:52 +0100 |
commit | 4876784d99d81f66b07f9806ef5660d6cc229e58 (patch) | |
tree | bcca6c8941f24cb94e656447c5f690152d43c34e | |
parent | 6c2482c466aa420875f330893dc36101c3e7fd46 (diff) | |
download | quagga-4876784d99d81f66b07f9806ef5660d6cc229e58.tar.bz2 quagga-4876784d99d81f66b07f9806ef5660d6cc229e58.tar.xz |
Fix vty being closed while waiting on '--more--' prompt.
The vty_half_close() did not properly take care of the CLI state
when in "cli_more_wait" state.
This fix tests for cli_more_wait state in vty_half_close() and
explicitly exits that state. (Instead of letting the state be
cleared implicitly, which didn't quite tidy up quickly enough.)
-rw-r--r-- | lib/command.h | 4 | ||||
-rw-r--r-- | lib/vty.c | 2 | ||||
-rw-r--r-- | lib/vty_cli.c | 46 | ||||
-rw-r--r-- | lib/vty_cli.h | 4 | ||||
-rw-r--r-- | lib/vty_io.c | 8 |
5 files changed, 51 insertions, 13 deletions
diff --git a/lib/command.h b/lib/command.h index 1c66c083..ba7c4bb2 100644 --- a/lib/command.h +++ b/lib/command.h @@ -393,4 +393,8 @@ extern char *argv_concat (const char* const* argv, int argc, int shift); /* struct host global, ick */ extern struct host host; +#ifdef QDEBUG +extern const char *debug_banner ; +#endif + #endif /* _ZEBRA_COMMAND_H */ @@ -23,7 +23,7 @@ #include "zebra.h" #include <stdbool.h> -#include "version.h" +#include "lib/version.h" #include "vty_io.h" #include "vty.h" diff --git a/lib/vty_cli.c b/lib/vty_cli.c index 461d511e..fab266b1 100644 --- a/lib/vty_cli.c +++ b/lib/vty_cli.c @@ -689,7 +689,7 @@ uty_cli_cmd_complete(vty_io vio, enum cmd_return_code ret) * Outputs the new prompt line. */ extern void -uty_cli_go_more_wait(vty_io vio) +uty_cli_enter_more_wait(vty_io vio) { VTY_ASSERT_LOCKED() ; @@ -705,6 +705,40 @@ uty_cli_go_more_wait(vty_io vio) } ; /*------------------------------------------------------------------------------ + * Exit the "--more--" CLI. + * + * Wipes the "--more--" prompt. + * + * This is used when the user responds to the prompt. + * + * It is also used when the vty is "half-closed". In this case, it is (just) + * possible that the '--more--' prompt is yet to be completely written away, + * so: + * + * * assert that is either: !vio->cli_blocked (most of the time it will) + * or: !vio_fifo_empty(&vio->cli_obuf) + * + * * note that can wipe the prompt even though it hasn't been fully + * written away yet. (The effect is to append the wipe action to the + * cli_obuf !) + */ +extern void +uty_cli_exit_more_wait(vty_io vio) +{ + VTY_ASSERT_LOCKED() ; + + assert( (!vio->cli_blocked || !vio_fifo_empty(&vio->cli_obuf)) + && !vio->cmd_out_enabled && vio->cli_more_wait) ; + + uty_cli_wipe(vio, 0) ; /* wipe the prompt ('--more--') + before changing the CLI state */ + + vio->cli_blocked = 1 ; /* back to blocked waiting for output */ + vio->cli_more_wait = 0 ; /* exit more_wait */ + vio->cmd_out_enabled = 1 ; /* re-enable output */ +} ; + +/*------------------------------------------------------------------------------ * Handle the "--more--" state. * * Deals with the first stage if cli_blocked. @@ -792,11 +826,7 @@ uty_cli_more_wait(vty_io vio) * Return write_ready to tidy up the screen and, unless cleared, write * some more. */ - uty_cli_wipe(vio, 0) ; - - vio->cli_blocked = 1 ; /* back to blocked waiting for output */ - vio->cli_more_wait = 0 ; /* exit more_wait */ - vio->cmd_out_enabled = 1 ; /* re-enable output */ + uty_cli_exit_more_wait(vio) ; return now_ready ; } ; @@ -1082,11 +1112,11 @@ uty_cli_wipe(vty_io vio, int len) b += vio->cl.cp ; } ; - /* Stuff ahead of the current position if any ahead of new len */ + /* Wipe anything ahead of the current position and ahead of new len */ if ((a + b) > len) uty_cli_out_wipe_n(vio, +a) ; - /* Stuff behind current position, but ahead of new len */ + /* Wipe anything behind current position, but ahead of new len */ if (b > len) { uty_cli_out_wipe_n(vio, -(b - len)) ; diff --git a/lib/vty_cli.h b/lib/vty_cli.h index 5bf682ac..f532616a 100644 --- a/lib/vty_cli.h +++ b/lib/vty_cli.h @@ -35,7 +35,9 @@ extern enum vty_readiness uty_cli(vty_io vio) ; extern keystroke_callback uty_cli_iac_callback ; extern void uty_cli_hist_add (vty_io vio, const char* cmd_line) ; -extern void uty_cli_go_more_wait(vty_io vio) ; +extern void uty_cli_enter_more_wait(vty_io vio) ; +extern void uty_cli_exit_more_wait(vty_io vio) ; + extern void uty_free_host_name(void) ; extern void uty_check_host_name(void) ; diff --git a/lib/vty_io.c b/lib/vty_io.c index c4b4f528..9fd9ff2a 100644 --- a/lib/vty_io.c +++ b/lib/vty_io.c @@ -716,11 +716,13 @@ uty_half_close (vty_io vio, const char* reason) /* Turn off "--more--" so that all output clears without interruption. * - * Note that if is waiting for "--more--", then shutting the read side - * causes it to be readable, but EOF -- so that will flush through. + * If is sitting on a "--more--" prompt, then exit the wait_more CLI. */ vio->cli_more_enabled = 0 ; + if (vio->cli_more_wait) + uty_cli_exit_more_wait(vio) ; + /* If a command is not in progress, enable output, which will clear * the output buffer if there is anything there, plus any close reason, * and then close. @@ -1696,7 +1698,7 @@ uty_write_fifo_lc(vty_io vio, vio_fifo vf, vio_line_control lc) * cleared. */ if (lc->paused && vio->cli_more_enabled) - uty_cli_go_more_wait(vio) ; + uty_cli_enter_more_wait(vio) ; return 1 ; /* FIFO or line control, not empty */ } ; |