All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft,v2] cli: save history on ctrl-d with editline
@ 2021-11-24 23:16 Pablo Neira Ayuso
  0 siblings, 0 replies; only message in thread
From: Pablo Neira Ayuso @ 2021-11-24 23:16 UTC (permalink / raw)
  To: netfilter-devel

Missing call to cli_exit() to save the history when ctrl-d is pressed in
nft -i.

Moreover, remove call to rl_callback_handler_remove() in cli_exit() for
editline cli since it does not call rl_callback_handler_install().

And print newline otherwise shell prompt is garbled:

 nft> ^D[user@system]$

Fixes: bc2d5f79c2ea ("cli: use plain readline() interface with libedit")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: print newline after ctrl-d to fix shell prompt.

 src/cli.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/cli.c b/src/cli.c
index 8729176680cf..ba1d86b7c436 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -152,13 +152,6 @@ static void cli_complete(char *line)
 	nft_run_cmd_from_buffer(cli_nft, line);
 	free(line);
 }
-
-void cli_exit(void)
-{
-	rl_callback_handler_remove();
-	rl_deprep_terminal();
-	write_history(histfile);
-}
 #endif
 
 #if defined(HAVE_LIBREADLINE)
@@ -188,6 +181,13 @@ int cli_init(struct nft_ctx *nft)
 	return 0;
 }
 
+void cli_exit(void)
+{
+	rl_callback_handler_remove();
+	rl_deprep_terminal();
+	write_history(histfile);
+}
+
 #elif defined(HAVE_LIBEDIT)
 
 int cli_init(struct nft_ctx *nft)
@@ -212,10 +212,18 @@ int cli_init(struct nft_ctx *nft)
 
 		cli_complete(line);
 	}
+	cli_exit();
 
 	return 0;
 }
 
+void cli_exit(void)
+{
+	rl_deprep_terminal();
+	write_history(histfile);
+	printf("\n");
+}
+
 #else /* HAVE_LINENOISE */
 
 int cli_init(struct nft_ctx *nft)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-24 23:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 23:16 [PATCH nft,v2] cli: save history on ctrl-d with editline Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.