From 3e1f7baa000e20156c72a49902f928dad7553adb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Kupec?= Date: Sat, 15 May 2010 12:16:31 +0200 Subject: [PATCH] Check pkgkit only if acq. lock fails (bnc #580513) --- src/Zypper.cc | 46 ++++++++++++++++++++++++++++++++-------------- src/utils/misc.cc | 4 ++++ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/Zypper.cc b/src/Zypper.cc index 88c1d19..a99807d 100644 --- a/src/Zypper.cc +++ b/src/Zypper.cc @@ -2474,7 +2474,6 @@ void Zypper::doCommand() try { const char *roh = getenv("ZYPP_READONLY_HACK"); - if (roh != NULL && roh[0] == '1') zypp_readonly_hack::IWantIt (); @@ -2483,8 +2482,15 @@ void Zypper::doCommand() || command() == ZypperCommand::TARGET_OS ) zypp_readonly_hack::IWantIt (); // #247001, #302152 + God = zypp::getZYpp(); + } + catch (ZYppFactoryException & excpt_r) + { + ZYPP_CAUGHT (excpt_r); + + bool still_locked = true; // check for packagekit (bnc #580513) - else if (packagekit_running()) + if (excpt_r.lockerName().find("packagekitd") != string::npos) { // ask user wheter to tell it to quit out().info(_( @@ -2497,10 +2503,10 @@ void Zypper::doCommand() PROMPT_PACKAGEKIT_QUIT, _("Tell PackageKit to quit?"), false); // tell it to quit - while (reply) + while (reply && still_locked) { packagekit_suggest_quit(); - ::sleep(1); + ::sleep(2); if (packagekit_running()) { out().info(_("PackageKit is still running (probably busy).")); @@ -2508,20 +2514,32 @@ void Zypper::doCommand() PROMPT_PACKAGEKIT_QUIT, _("Try again?"), false); } else - reply = false; + still_locked = false; } } - God = zypp::getZYpp(); - } - catch (ZYppFactoryException & excpt_r) - { - ZYPP_CAUGHT (excpt_r); - ERR << "A ZYpp transaction is already in progress." << endl; - out().error(excpt_r.asString()); + if (still_locked) + { + ERR << "A ZYpp transaction is already in progress." << endl; + out().error(excpt_r.asString()); - setExitCode(ZYPPER_EXIT_ERR_ZYPP); - throw (ExitRequestException("ZYpp locked")); + setExitCode(ZYPPER_EXIT_ERR_ZYPP); + throw (ExitRequestException("ZYpp locked")); + } + else + { + // try to get the lock again + try { God = zypp::getZYpp(); } + catch (ZYppFactoryException & e) + { + // this should happen only rarely, so no special handling here + ERR << "still locked." << endl; + out().error(e.asString()); + + setExitCode(ZYPPER_EXIT_ERR_ZYPP); + throw (ExitRequestException("ZYpp locked")); + } + } } catch (Exception & excpt_r) { diff --git a/src/utils/misc.cc b/src/utils/misc.cc index ebd2125..9996259 100644 --- a/src/utils/misc.cc +++ b/src/utils/misc.cc @@ -544,10 +544,14 @@ bool packagekit_running() string line; for (line = pkcheck.receiveLine(); !line.empty(); line = pkcheck.receiveLine()) + { + DBG << "dbus-send: " << line << endl; if (line.find("boolean") != string::npos && line.find("true") != string::npos) result = true; + } pkcheck.close(); + DBG << result << endl; return result; } -- 2.7.4