cli: reset terminal using libreadline when quitting on signal (bgo #706118)
readline() makes changes to terminal and when it doesn't receive unix signals, it has no chance to perform cleanups on exit. So we have to call its cleanup functions manually on exit. https://bugzilla.gnome.org/show_bug.cgi?id=706118
This commit is contained in:
@@ -4307,6 +4307,8 @@ typedef struct {
|
||||
int *rl_attempted_completion_over_x;
|
||||
int *rl_completion_append_character_x;
|
||||
const char **rl_completer_word_break_characters_x;
|
||||
void (*rl_free_line_state_func) (void);
|
||||
void (*rl_cleanup_after_signal_func) (void);
|
||||
} EditLibSymbols;
|
||||
|
||||
static EditLibSymbols edit_lib_symbols;
|
||||
@@ -4663,6 +4665,12 @@ load_cmd_line_edit_lib (void)
|
||||
if (!g_module_symbol (module, "rl_completer_word_break_characters",
|
||||
(gpointer) (&edit_lib_symbols.rl_completer_word_break_characters_x)))
|
||||
goto error;
|
||||
if (!g_module_symbol (module, "rl_free_line_state",
|
||||
(gpointer) (&edit_lib_symbols.rl_free_line_state_func)))
|
||||
goto error;
|
||||
if (!g_module_symbol (module, "rl_cleanup_after_signal",
|
||||
(gpointer) (&edit_lib_symbols.rl_cleanup_after_signal_func)))
|
||||
goto error;
|
||||
|
||||
/* Set a pointer to an alternative function to create matches */
|
||||
*edit_lib_symbols.rl_attempted_completion_function_x = (CPPFunction *) nmcli_editor_tab_completion;
|
||||
@@ -4676,6 +4684,15 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
nmc_cleanup_readline (void)
|
||||
{
|
||||
if (edit_lib_symbols.rl_free_line_state_func)
|
||||
edit_lib_symbols.rl_free_line_state_func ();
|
||||
if (edit_lib_symbols.rl_cleanup_after_signal_func)
|
||||
edit_lib_symbols.rl_cleanup_after_signal_func ();
|
||||
}
|
||||
|
||||
static char *
|
||||
readline_x (const char *prompt)
|
||||
{
|
||||
|
Reference in New Issue
Block a user