From 555e5b401c237198218e457e29bec11e059f6aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Tue, 10 Sep 2013 10:03:59 +0200 Subject: [PATCH] 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 --- cli/src/connections.c | 17 +++++++++++++++++ cli/src/connections.h | 2 ++ cli/src/nmcli.c | 1 + 3 files changed, 20 insertions(+) diff --git a/cli/src/connections.c b/cli/src/connections.c index 8225cce979..43743842c8 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -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) { diff --git a/cli/src/connections.h b/cli/src/connections.h index a1ed1c1cf3..4ccd8c81cc 100644 --- a/cli/src/connections.h +++ b/cli/src/connections.h @@ -24,4 +24,6 @@ NMCResultCode do_connections (NmCli *nmc, int argc, char **argv); +void nmc_cleanup_readline (void); + #endif /* NMC_CONNECTIONS_H */ diff --git a/cli/src/nmcli.c b/cli/src/nmcli.c index 9dad8d2511..1fa365e6e7 100644 --- a/cli/src/nmcli.c +++ b/cli/src/nmcli.c @@ -284,6 +284,7 @@ signal_handling_thread (void *arg) { case SIGINT: case SIGQUIT: case SIGTERM: + nmc_cleanup_readline (); printf (_("\nError: nmcli terminated by signal %d."), signo); exit (1); break;