From 3f711a56200fee6d55033e8f13e6ba21e02f3cd0 Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Sun, 9 Nov 2008 10:35:44 +0000 Subject: [PATCH] - exit immediately after ctrl+c in prompt (bnc #417997) --- src/Zypper.h | 4 ++++ src/main.cc | 14 +++++++++++--- src/utils/prompt.cc | 8 ++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Zypper.h b/src/Zypper.h index 7a024f2..9566ea1 100644 --- a/src/Zypper.h +++ b/src/Zypper.h @@ -105,6 +105,7 @@ struct RuntimeData , commit_pkg_current(0) , seen_verify_hint(false) , action_rpm_download(false) + , waiting_for_input(false) {} std::list repos; @@ -146,6 +147,9 @@ struct RuntimeData bool seen_verify_hint; bool action_rpm_download; + + //! \todo move this to a separate Status struct + bool waiting_for_input; }; typedef zypp::shared_ptr RepoManager_Ptr; diff --git a/src/main.cc b/src/main.cc index cb46ec5..b56cc1d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -30,18 +30,26 @@ void signal_handler(int sig) _("Use '%s' or enter '%s' to quit the shell."), "Ctrl+D", "quit") << endl; ::rl_reset_after_signal(); exit(ZYPPER_EXIT_ON_SIGNAL); - //! \todo improve to drop to shell only + //! \todo improve to drop to shell only } else*/ { - // translators: this will show up if you press ctrl+c twice outside of zypper shell + // translators: this will show up if you press ctrl+c twice (but outside of zypper shell) cerr << endl << _("OK OK! Exiting immediately...") << endl; zypper.cleanup(); exit(ZYPPER_EXIT_ON_SIGNAL); } } + else if (zypper.runtimeData().waiting_for_input) + { + zypper.cleanup(); + exit(ZYPPER_EXIT_ON_SIGNAL); + } else + { + //! \todo cerr << endl << _("Trying to exit gracefully...") << endl; zypper.requestExit(); + } } @@ -71,7 +79,7 @@ int main(int argc, char **argv) if (::signal(SIGINT, signal_handler) == SIG_ERR) out.error("Failed to set SIGINT handler."); if (::signal(SIGTERM, signal_handler) == SIG_ERR) - out.error("Failed to set SIGTERM handler."); + out.error("Failed to set SIGTERM handler."); try { diff --git a/src/utils/prompt.cc b/src/utils/prompt.cc index fe3efc7..7e9e429 100644 --- a/src/utils/prompt.cc +++ b/src/utils/prompt.cc @@ -188,6 +188,14 @@ unsigned int get_prompt_reply(Zypper & zypper, return poptions.defaultOpt(); } + // set runtimeData().waiting_for_input flag while in this function + struct Bye + { + Bye(bool * flag) : _flag(flag) { *_flag = true; } + ~Bye() { *_flag = false; } + bool * _flag; + } say_goodbye(&zypper.runtimeData().waiting_for_input); + // open a terminal for input (bnc #436963) ifstream stm("/dev/tty", ifstream::in); // istream & stm = cin; -- 2.7.4