From 51b900b30728d7f6c99f402511f6090687ea6d5c Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Sun, 5 Aug 2018 15:18:09 +0200 Subject: [PATCH] Reset terminal on erroneous console exit This ensures that the terminal is resetted on an erroneous exit when using the Icinga 2 console. refs #6382 --- lib/cli/consolecommand.cpp | 9 +++++++++ lib/cli/editline.hpp | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp index 774879207..f62430977 100644 --- a/lib/cli/consolecommand.cpp +++ b/lib/cli/consolecommand.cpp @@ -532,6 +532,11 @@ void ConsoleCommand::ExecuteScriptCompletionHandler(boost::mutex& mutex, boost:: } catch (const std::exception& ex) { Log(LogCritical, "ConsoleCommand") << "HTTP query failed: " << ex.what(); + + /* Ensures that the terminal state is resetted */ + rl_deprep_terminal(); + + Application::Exit(EXIT_FAILURE); } } @@ -554,6 +559,10 @@ void ConsoleCommand::AutocompleteScriptCompletionHandler(boost::mutex& mutex, bo } catch (const std::exception& ex) { Log(LogCritical, "ConsoleCommand") << "HTTP query failed: " << ex.what(); + + /* Ensures that the terminal state is resetted */ + rl_deprep_terminal(); + Application::Exit(EXIT_FAILURE); } } diff --git a/lib/cli/editline.hpp b/lib/cli/editline.hpp index f284c207b..cd78e5d57 100644 --- a/lib/cli/editline.hpp +++ b/lib/cli/editline.hpp @@ -24,6 +24,7 @@ extern "C" { char *readline(const char *prompt); int add_history(const char *line); +void rl_deprep_terminal(); typedef char *ELFunction(const char *, int);