From 49d2cff26cc8c38b172af6d5aad62dc24ae6e4f5 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 24 Mar 2006 16:35:31 +0000 Subject: [PATCH] only lock if we are running as root --- zypp/CheckSum.h | 12 ++++- zypp/ZYppFactory.cc | 77 ++++++++++++++++++--------- zypp/source/susetags/ProductMetadataParser.cc | 22 ++++++++ zypp/source/susetags/ProductMetadataParser.h | 4 ++ zypp/source/susetags/SuseTagsProductImpl.h | 6 +++ 5 files changed, 95 insertions(+), 26 deletions(-) diff --git a/zypp/CheckSum.h b/zypp/CheckSum.h index 5b3bd24..cd9873c 100644 --- a/zypp/CheckSum.h +++ b/zypp/CheckSum.h @@ -12,6 +12,8 @@ #ifndef ZYPP_CHECKSUM_H #define ZYPP_CHECKSUM_H +#include + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -23,8 +25,14 @@ namespace zypp : _type(type) , _checksum(checksum) {} - std::string type() { return _type; } - std::string checksum() { return _checksum; } + + CheckSum() + {} + + std::string type() const + { return _type; } + std::string checksum() const + { return _checksum; } private: std::string _type; std::string _checksum; diff --git a/zypp/ZYppFactory.cc b/zypp/ZYppFactory.cc index bd52133..b8d9d64 100644 --- a/zypp/ZYppFactory.cc +++ b/zypp/ZYppFactory.cc @@ -71,7 +71,7 @@ namespace zypp Pathname lock_file = Pathname(ZYPP_LOCK_FILE); _zypp_lockfile = fopen(lock_file.asString().c_str(), mode); if (_zypp_lockfile == 0) - ZYPP_THROW (Exception( "Cant open " + lock_file.asString() ) ); + ZYPP_THROW (Exception( "Cant open " + lock_file.asString() + " in mode " + std::string(mode) ) ); } void closeLockFile() @@ -169,43 +169,59 @@ namespace zypp if ( locker_pid == curr_pid ) { // alles ok, we are requesting the instance again - MIL << "Lockfile found, but it is myself. Assuming same process getting zypp instance again." << std::endl; + //MIL << "Lockfile found, but it is myself. Assuming same process getting zypp instance again." << std::endl; return false; } else { if ( isProcessRunning(locker_pid) ) { - MIL << locker_pid << " is running and has a ZYpp lock. Sorry" << std::endl; - return true; - } - else - { - MIL << locker_pid << " has a ZYpp lock, but process is not running. Cleaning lock file." << std::endl; - if ( filesystem::unlink(lock_file) == 0 ) + if ( geteuid() == 0 ) { - createLockFile(); - // now open it for reading - openLockFile("r"); - shLockFile(); - return false; + // i am root + MIL << locker_pid << " is running and has a ZYpp lock. Sorry" << std::endl; + return true; } else { - ERR << "Can't clean lockfile. Sorry, can't create a new lock. Zypp still locked." << std::endl; - return true; + MIL << locker_pid << " is running and has a ZYpp lock. Access as normal user allowed." << std::endl; + return false; + } + } + else + { + if ( geteuid() == 0 ) + { + MIL << locker_pid << " has a ZYpp lock, but process is not running. Cleaning lock file." << std::endl; + if ( filesystem::unlink(lock_file) == 0 ) + { + createLockFile(); + // now open it for reading + openLockFile("r"); + shLockFile(); + return false; + } + else + { + ERR << "Can't clean lockfile. Sorry, can't create a new lock. Zypp still locked." << std::endl; + return true; + } } } } } else { - createLockFile(); - // now open it for reading - openLockFile("r"); - shLockFile(); + if ( geteuid() == 0 ) + { + createLockFile(); + // now open it for reading + openLockFile("r"); + shLockFile(); + } return false; } + return true; } }; @@ -250,11 +266,24 @@ namespace zypp // ZYpp::Ptr ZYppFactory::getZYpp() const { - static ZYpp::Ptr _instance( new ZYpp( ZYpp::Impl_Ptr(new ZYpp::Impl) ) ); - if ( globalLock.zyppLocked() ) - return 0; - else + static ZYpp::Ptr _instance; + + if ( _instance ) + { return _instance; + } + else + { + if ( globalLock.zyppLocked() ) + { + return 0; + } + else + { + _instance = new ZYpp( ZYpp::Impl_Ptr(new ZYpp::Impl) ); + return _instance; + } + } } /****************************************************************** diff --git a/zypp/source/susetags/ProductMetadataParser.cc b/zypp/source/susetags/ProductMetadataParser.cc index cf8549d..8ba9c5e 100644 --- a/zypp/source/susetags/ProductMetadataParser.cc +++ b/zypp/source/susetags/ProductMetadataParser.cc @@ -128,6 +128,8 @@ namespace zypp prodImpl->_language = value; else if(key == "TIMEZONE") prodImpl->_timezone = value; + else if(key == "META") + parseFileCheckSum( key, value, prodImpl->_descr_files_checksums); else DBG << "parse error" << std::endl; } @@ -233,6 +235,26 @@ namespace zypp } } + void ProductMetadataParser::parseFileCheckSum( const std::string &key, const std::string &value, std::map &container) + { + std::list splitted; + str::split( value, std::back_inserter(splitted), " "); + if (splitted.size() != 3) + { + ERR << "Parse error in checksum. Expected [type checksum file], got [" << value << "]" << std::endl; + } + else + { + std::string checksum_type = splitted.front(); + splitted.pop_front(); + std::string checksum_str = splitted.front(); + splitted.pop_front(); + std::string filename = splitted.front(); + splitted.pop_front(); + MIL << "Checksum for " << filename << " is " << checksum_str << " (" << checksum_type << ")" << std::endl; + container[filename] = CheckSum(checksum_type, checksum_str); + } + } ///////////////////////////////////////////////////////////////// } // namespace susetags /////////////////////////////////////////////////////////////////// diff --git a/zypp/source/susetags/ProductMetadataParser.h b/zypp/source/susetags/ProductMetadataParser.h index fbf5888..79071c7 100644 --- a/zypp/source/susetags/ProductMetadataParser.h +++ b/zypp/source/susetags/ProductMetadataParser.h @@ -19,6 +19,7 @@ #include "zypp/parser/tagfile/ParseException.h" +#include "zypp/CheckSum.h" #include "zypp/Pathname.h" #include "zypp/Product.h" #include "zypp/source/susetags/SuseTagsProductImpl.h" @@ -69,6 +70,9 @@ namespace zypp * REQUIRES line */ void parseRequires( const std::string &key, const std::string &value, zypp::CapSet &container); + + void parseFileCheckSum( const std::string &key, const std::string &value, std::map &container); + }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/source/susetags/SuseTagsProductImpl.h b/zypp/source/susetags/SuseTagsProductImpl.h index 6e4737a..e24d33c 100644 --- a/zypp/source/susetags/SuseTagsProductImpl.h +++ b/zypp/source/susetags/SuseTagsProductImpl.h @@ -12,6 +12,9 @@ #ifndef ZYPP_DETAIL_SUSETAGS_PRODUCTIMPL_H #define ZYPP_DETAIL_SUSETAGS_PRODUCTIMPL_H +#include + +#include "zypp/CheckSum.h" #include "zypp/CapSet.h" #include "zypp/detail/ProductImplIf.h" #include "zypp/Source.h" @@ -69,7 +72,10 @@ namespace zypp std::string _language; std::string _timezone; + std::map _descr_files_checksums; + Source_Ref _source; + }; /////////////////////////////////////////////////////////////////// -- 2.7.4