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:
Jiří Klimeš
2013-09-10 10:03:59 +02:00
parent 663014ed62
commit 555e5b401c
3 changed files with 20 additions and 0 deletions

View File

@@ -4307,6 +4307,8 @@ typedef struct {
int *rl_attempted_completion_over_x; int *rl_attempted_completion_over_x;
int *rl_completion_append_character_x; int *rl_completion_append_character_x;
const char **rl_completer_word_break_characters_x; const char **rl_completer_word_break_characters_x;
void (*rl_free_line_state_func) (void);
void (*rl_cleanup_after_signal_func) (void);
} EditLibSymbols; } EditLibSymbols;
static EditLibSymbols edit_lib_symbols; 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", if (!g_module_symbol (module, "rl_completer_word_break_characters",
(gpointer) (&edit_lib_symbols.rl_completer_word_break_characters_x))) (gpointer) (&edit_lib_symbols.rl_completer_word_break_characters_x)))
goto error; 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 */ /* Set a pointer to an alternative function to create matches */
*edit_lib_symbols.rl_attempted_completion_function_x = (CPPFunction *) nmcli_editor_tab_completion; *edit_lib_symbols.rl_attempted_completion_function_x = (CPPFunction *) nmcli_editor_tab_completion;
@@ -4676,6 +4684,15 @@ error:
return NULL; 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 * static char *
readline_x (const char *prompt) readline_x (const char *prompt)
{ {

View File

@@ -24,4 +24,6 @@
NMCResultCode do_connections (NmCli *nmc, int argc, char **argv); NMCResultCode do_connections (NmCli *nmc, int argc, char **argv);
void nmc_cleanup_readline (void);
#endif /* NMC_CONNECTIONS_H */ #endif /* NMC_CONNECTIONS_H */

View File

@@ -284,6 +284,7 @@ signal_handling_thread (void *arg) {
case SIGINT: case SIGINT:
case SIGQUIT: case SIGQUIT:
case SIGTERM: case SIGTERM:
nmc_cleanup_readline ();
printf (_("\nError: nmcli terminated by signal %d."), signo); printf (_("\nError: nmcli terminated by signal %d."), signo);
exit (1); exit (1);
break; break;