From 576f0877f30f21113e940459d12b6c7a9db4e582 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 22 Oct 2018 18:01:48 +0200 Subject: [PATCH] cli: initialize readline before installing the redisplay handler Otherwise readline decides to initialize terminal handling at the first readline call, and if that happens at the point it sees our non-echoing rl_redisplay. At that point, unless already intialized, readline wrongly convinces itself we do our own handling of terminal peculiarities (such as cursor movement, or erases). We do not -- we merely wrap the stock rl_redisplay(), temporarily hiding the actual characters. The rl_initialize() in nmc_readline_echo()s fixes broken line editing in password prompts that weren't preceded a previous non-password prompt. The other one is there for consistency only. (I guess we should be initializing readline before use anyway; although it seems to initialize itself anyway if we fail to do so...) https://github.com/NetworkManager/NetworkManager/pull/241 (cherry picked from commit 05d6c993dd0cee474540f74902d213d084a86782) --- clients/cli/common.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clients/cli/common.c b/clients/cli/common.c index 88e9815455..d3f5f865f6 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -931,6 +931,8 @@ nmc_readline (const char *prompt_fmt, ...) va_list args; char *prompt, *str; + rl_initialize (); + va_start (args, prompt_fmt); prompt = g_strdup_vprintf (prompt_fmt, args); va_end (args); @@ -985,6 +987,8 @@ nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) prompt = g_strdup_vprintf (prompt_fmt, args); va_end (args); + rl_initialize (); + /* Hide the actual password */ if (!echo_on) { saved_history = history_get_history_state ();