- exit immediately after ctrl+c in prompt (bnc #417997)
authorJan Kupec <jkupec@suse.cz>
Sun, 9 Nov 2008 10:35:44 +0000 (10:35 +0000)
committerJan Kupec <jkupec@suse.cz>
Sun, 9 Nov 2008 10:35:44 +0000 (10:35 +0000)
src/Zypper.h
src/main.cc
src/utils/prompt.cc

index 7a024f2..9566ea1 100644 (file)
@@ -105,6 +105,7 @@ struct RuntimeData
     , commit_pkg_current(0)
     , seen_verify_hint(false)
     , action_rpm_download(false)
+    , waiting_for_input(false)
   {}
 
   std::list<zypp::RepoInfo> 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<zypp::RepoManager> RepoManager_Ptr;
index cb46ec5..b56cc1d 100644 (file)
@@ -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
   {
index fe3efc7..7e9e429 100644 (file)
@@ -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;