From 4ad9b1767f8be99b4357d391abd7c4298973574c Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Mon, 2 Sep 2019 16:15:52 +0900 Subject: [PATCH] Imported Upstream version 17.5.2 --- VERSION.cmake | 4 ++-- package/libzypp.changes | 9 +++++++++ zypp/CMakeLists.txt | 1 + zypp/ExternalProgram.cc | 6 ++++-- zypp/ExternalProgram.h | 21 ++++++++++++++++++++- zypp/RepoManager.cc | 1 + zypp/ShutdownLock.cc | 32 ++++++++++++++++++++++++++++++++ zypp/ShutdownLock_p.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ zypp/target/TargetImpl.cc | 2 ++ zypp/ui/Selectable.cc | 5 +++-- 10 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 zypp/ShutdownLock.cc create mode 100644 zypp/ShutdownLock_p.h diff --git a/VERSION.cmake b/VERSION.cmake index c33ce82..7fb4ad1 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -61,8 +61,8 @@ SET(LIBZYPP_MAJOR "17") SET(LIBZYPP_COMPATMINOR "2") SET(LIBZYPP_MINOR "5") -SET(LIBZYPP_PATCH "1") +SET(LIBZYPP_PATCH "2") # -# LAST RELEASED: 17.5.1 (2) +# LAST RELEASED: 17.5.2 (2) # (The number in parenthesis is LIBZYPP_COMPATMINOR) #======= diff --git a/package/libzypp.changes b/package/libzypp.changes index 9783a12..315cea9 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,13 @@ ------------------------------------------------------------------- +Thu Jul 19 12:57:21 CEST 2018 - ma@suse.de + +- Prevent the system from sleeping during a commit + (fixes openSUSE/zypper#135) +- RepoManager: Explicitly request repo2solv to generate application + pseudo packages. +- version 17.5.2 (2) + +------------------------------------------------------------------- Wed Jul 18 10:55:49 CEST 2018 - ma@suse.de - libzypp-devel should not require cmake (bsc#1101349) diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index 559289f..34d1ebd 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -72,6 +72,7 @@ SET( zypp_SRCS ServiceInfo.cc Signature.cc SrcPackage.cc + ShutdownLock.cc SysContent.cc Target.cc TmpPath.cc diff --git a/zypp/ExternalProgram.cc b/zypp/ExternalProgram.cc index 54a5f2d..d5f1460 100644 --- a/zypp/ExternalProgram.cc +++ b/zypp/ExternalProgram.cc @@ -178,12 +178,12 @@ namespace zypp { - void ExternalProgram::start_program( const char *const *argv, + void ExternalProgram::start_program(const char *const *argv, const Environment & environment, Stderr_Disposition stderr_disp, int stderr_fd, bool default_locale, - const char * root ) + const char * root , bool switch_pgid) { pid = -1; _exitStatus = 0; @@ -307,6 +307,8 @@ namespace zypp { } else { + if ( switch_pgid ) + setpgid( 0, 0); renumber_fd (to_external[0], 0); // set new stdin ::close(from_external[0]); // Belongs to father process diff --git a/zypp/ExternalProgram.h b/zypp/ExternalProgram.h index 76ec38e..f3e67a0 100644 --- a/zypp/ExternalProgram.h +++ b/zypp/ExternalProgram.h @@ -19,6 +19,7 @@ #include #include +#include "zypp/APIConfig.h" #include "zypp/base/ExternalDataSource.h" #include "zypp/Pathname.h" @@ -225,10 +226,12 @@ namespace zypp { /** Remember execution errors like failed fork/exec. */ std::string _execError; + protected: + void start_program (const char *const *argv, const Environment & environment, Stderr_Disposition stderr_disp = Normal_Stderr, int stderr_fd = -1, bool default_locale = false, - const char* root = NULL); + const char* root = NULL, bool switch_pgid = false); }; @@ -299,6 +302,22 @@ namespace zypp { std::string _buffer; }; + /** ExternalProgram extended to change the progress group ID after forking. + * \see \ref ExternalProgram + */ + class ZYPP_LOCAL ExternalProgramWithSeperatePgid : public ExternalProgram + { + public: + ExternalProgramWithSeperatePgid (const char *const *argv, + Stderr_Disposition stderr_disp = Normal_Stderr, + int stderr_fd = -1, bool default_locale = false, + const Pathname& root = "") : ExternalProgram() + { + start_program( argv, Environment(), stderr_disp, stderr_fd, default_locale, root.c_str(), true ); + } + + }; + } // namespace zypp #endif // ZYPP_EXTERNALPROGRAM_H diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index fa022e0..3256d2e 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -1348,6 +1348,7 @@ namespace zypp cmd.push_back( "-o" ); cmd.push_back( solvfile.asString() ); cmd.push_back( "-X" ); // autogenerate pattern from pattern-package + cmd.push_back( "-A" ); // autogenerate application pseudo packages if ( repokind == RepoType::RPMPLAINDIR ) { diff --git a/zypp/ShutdownLock.cc b/zypp/ShutdownLock.cc new file mode 100644 index 0000000..4715fe0 --- /dev/null +++ b/zypp/ShutdownLock.cc @@ -0,0 +1,32 @@ +#include "ShutdownLock_p.h" + +#include "zypp/ExternalProgram.h" +#include + +zypp::ShutdownLock::ShutdownLock(const std::string &reason) +{ + try { + + std::string whyStr = str::form("--why=%s", reason.c_str()); + + const char* argv[] = + { + "/usr/bin/systemd-inhibit", + "--what=sleep:shutdown:idle", + "--who=zypp", + "--mode=block", + whyStr.c_str(), + "/usr/bin/cat", + NULL + }; + _prog = shared_ptr( new ExternalProgramWithSeperatePgid( argv, ExternalProgram::Discard_Stderr ) ); + } catch (...) { + } +} + +zypp::ShutdownLock::~ShutdownLock() +{ + if (_prog) { + _prog->kill(); + } +} diff --git a/zypp/ShutdownLock_p.h b/zypp/ShutdownLock_p.h new file mode 100644 index 0000000..ade9985 --- /dev/null +++ b/zypp/ShutdownLock_p.h @@ -0,0 +1,45 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/ShutdownLock_p.h + * +*/ + +#ifndef ZYPP_SHUTDOWNLOCK_P_H_INCLUDED +#define ZYPP_SHUTDOWNLOCK_P_H_INCLUDED + +#include + +#include "zypp/APIConfig.h" +#include "zypp/base/PtrTypes.h" + +namespace zypp +{ + +class ExternalProgramWithSeperatePgid; + +/** + * Attempts to create a lock to prevent the system + * from going into hibernate/shutdown. The lock is automatically + * released when the object is destroyed. + */ +class ZYPP_LOCAL ShutdownLock +{ +public: + ShutdownLock( const std::string &reason ); + ~ShutdownLock(); + +private: + shared_ptr _prog; + +}; + +} + + +#endif diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index 4b98ff7..f4596f6 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -38,6 +38,7 @@ #include "zypp/RepoStatus.h" #include "zypp/ExternalProgram.h" #include "zypp/Repository.h" +#include "zypp/ShutdownLock_p.h" #include "zypp/ResFilters.h" #include "zypp/HistoryLog.h" @@ -1095,6 +1096,7 @@ namespace zypp { // ----------------------------------------------------------------- // ZYppCommitPolicy policy_r( policy_rX ); + ShutdownLock lck("Zypp commit running."); // Fake outstanding YCP fix: Honour restriction to media 1 // at installation, but install all remaining packages if post-boot. diff --git a/zypp/ui/Selectable.cc b/zypp/ui/Selectable.cc index b7549e5..1d41383 100644 --- a/zypp/ui/Selectable.cc +++ b/zypp/ui/Selectable.cc @@ -160,11 +160,12 @@ namespace zypp Selectable::picklist_size_type Selectable::picklistPos( const sat::Solvable & solv_r ) const { - picklist_size_type idx = picklist_size_type(-1); + picklist_size_type idx = picklist_size_type(0); for ( const auto & pi : picklist() ) { if ( pi == solv_r ) - return ++idx; + return idx; + ++idx; } return picklistNoPos; } -- 2.7.4