Author: jkupec
Date: Tue Apr 29 22:55:22 2008
New Revision: 9893
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9893&view=rev
Log:
- basic cleanup upon SIGINT and SIGTERM (will remove
temporary repos) (bnc #340505)
Modified:
trunk/zypper/doc/zypper.8
trunk/zypper/src/zypper-main.cc
trunk/zypper/src/zypper-main.h
trunk/zypper/src/zypper-utils.cc
trunk/zypper/src/zypper.cc
trunk/zypper/src/zypper.h
Modified: trunk/zypper/doc/zypper.8
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/doc/zypper.8?rev=9893&r1=9892&r2=9893&view=diff
==============================================================================
--- trunk/zypper/doc/zypper.8 (original)
+++ trunk/zypper/doc/zypper.8 Tue Apr 29 22:55:22 2008
@@ -679,6 +679,9 @@
Returned by the \fBinstall\fR and the \fBremove\fR command in case any of the
arguments does not match any of the available (or installed) resolvable names
or other capabilities.
+105 - ZYPPER_EXIT_ON_SIGNAL
+Returned upon exiting after receiving a SIGINT or SIGTERM.
+
.SH "COMPATIBILITY WITH RUG"
.LP
Modified: trunk/zypper/src/zypper-main.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-main.cc?rev=9893&r1=9892&r2=9893&view=diff
==============================================================================
--- trunk/zypper/src/zypper-main.cc (original)
+++ trunk/zypper/src/zypper-main.cc Tue Apr 29 22:55:22 2008
@@ -1,4 +1,6 @@
#include <iostream>
+#include
+//#include
#include "zypp/base/Logger.h"
#include "zypp/base/LogControl.h"
@@ -19,6 +21,34 @@
KeyRingCallbacks keyring_callbacks;
DigestCallbacks digest_callbacks;
+
+void signal_handler(int sig)
+{
+ Zypper & zypper = *Zypper::instance();
+ if (zypper.exitRequested())
+ {
+ /*
+ if (zypper.runningShell())
+ {
+ cout << endl << zypp::str::form(
+ _("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
+ }
+ else*/
+ {
+ // translators: this will show up if you press ctrl+c twice outside of zypper shell
+ cerr << _("OK OK! Exitting immediately...") << endl;
+ zypper.cleanup();
+ exit(ZYPPER_EXIT_ON_SIGNAL);
+ }
+ }
+ else
+ zypper.requestExit();
+}
+
+
int main(int argc, char **argv)
{
struct Bye {
@@ -38,5 +68,10 @@
logfile = ZYPPER_LOG;
zypp::base::LogControl::instance().logfile( logfile );
+ if (::signal(SIGINT, signal_handler) == SIG_ERR)
+ cerr << "Failed to set SIGINT handler." << endl;
+ if (::signal(SIGTERM, signal_handler) == SIG_ERR)
+ cerr << "Failed to set SIGTERM handler." << endl;
+
return Zypper::instance()->main(argc, argv);
}
Modified: trunk/zypper/src/zypper-main.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-main.h?rev=9893&r1=9892&r2=9893&view=diff
==============================================================================
--- trunk/zypper/src/zypper-main.h (original)
+++ trunk/zypper/src/zypper-main.h Tue Apr 29 22:55:22 2008
@@ -21,6 +21,7 @@
#define ZYPPER_EXIT_INF_REBOOT_NEEDED 102 // reboot needed after install/upgrade
#define ZYPPER_EXIT_INF_RESTART_NEEDED 103 // restart of package manager itself needed
#define ZYPPER_EXIT_INF_CAP_NOT_FOUND 104 // given capability not found (for install/remove)
+#define ZYPPER_EXIT_ON_SIGNAL 105 // SIGINT or SIGTERM received
// undefine _ and _PL macros from libzypp
#ifdef _
Modified: trunk/zypper/src/zypper-utils.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-utils.cc?rev=9893&r1=9892&r2=9893&view=diff
==============================================================================
--- trunk/zypper/src/zypper-utils.cc (original)
+++ trunk/zypper/src/zypper-utils.cc Tue Apr 29 22:55:22 2008
@@ -32,8 +32,9 @@
line_read = NULL;
}
- /* Get a line from the user. */
- line_read = readline ("zypper> ");
+ //::rl_catch_signals = 0;
+ /* Get a line from the user. */
+ line_read = ::readline ("zypper> ");
/* If the line has any text in it,
save it on the history. */
Modified: trunk/zypper/src/zypper.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=9893&r1=9892&r2=9893&view=diff
==============================================================================
--- trunk/zypper/src/zypper.cc (original)
+++ trunk/zypper/src/zypper.cc Tue Apr 29 22:55:22 2008
@@ -62,7 +62,7 @@
: _argc(0), _argv(NULL), _out_ptr(NULL),
_command(ZypperCommand::NONE),
_exit_code(ZYPPER_EXIT_OK),
- _running_shell(false), _running_help(false),
+ _running_shell(false), _running_help(false), _exit_requested(false),
_sh_argc(0), _sh_argv(NULL)
{
MIL << "Hi, me zypper " VERSION " built " << __DATE__ << " " << __TIME__ << endl;
@@ -642,7 +642,7 @@
else
safeDoCommand();
}
- catch (Exception & e)
+ catch (const Exception & e)
{
out().error(e.msg());
print_unknown_command_hint(*this);
Modified: trunk/zypper/src/zypper.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.h?rev=9893&r1=9892&r2=9893&view=diff
==============================================================================
--- trunk/zypper/src/zypper.h (original)
+++ trunk/zypper/src/zypper.h Tue Apr 29 22:55:22 2008
@@ -142,10 +142,14 @@
void setExitCode(int exit) { _exit_code = exit; }
bool runningShell() const { return _running_shell; }
bool runningHelp() const { return _running_help; }
-
+ bool exitRequested() const { return _exit_requested; }
+ void requestExit() { _exit_requested = true; }
+
int argc() { return _running_shell ? _sh_argc : _argc; }
char ** argv() { return _running_shell ? _sh_argv : _argv; }
+ void cleanup();
+
public:
~Zypper();
private:
@@ -157,7 +161,6 @@
void shellCleanup();
void safeDoCommand();
void doCommand();
- void cleanup();
void setCommand(const ZypperCommand & command) { _command = command; }
void setRunningShell(bool value = true) { _running_shell = value; }
@@ -179,6 +182,7 @@
int _exit_code;
bool _running_shell;
bool _running_help;
+ bool _exit_requested;
RuntimeData _rdata;
@@ -196,11 +200,6 @@
{
public:
ExitRequestException(const std::string & msg = "") : zypp::Exception(msg) {}
-// ExitRequestException(const std::string & msg = "") : _msg(msg) {}
-
-// const std::string & msg() const { return _msg; }
-private:
-// std::string _msg;
};
#endif /*ZYPPER_H*/
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org