From: Duncan Mac-Vicar P Date: Thu, 27 Mar 2008 16:18:56 +0000 (+0000) Subject: - the lock passes the two testcases now X-Git-Tag: 6.6.0~1202 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4027166d17b028935c121e2e3c6deedcc19b2913;p=platform%2Fupstream%2Flibzypp.git - the lock passes the two testcases now --- diff --git a/tests/zypp/base/CMakeLists.txt b/tests/zypp/base/CMakeLists.txt index 48f259b12..ff7b15309 100644 --- a/tests/zypp/base/CMakeLists.txt +++ b/tests/zypp/base/CMakeLists.txt @@ -1,3 +1,3 @@ ADD_TESTS(Sysconfig ) -#ADD_TESTS( InterProcessMutex2 ) +ADD_TESTS( InterProcessMutex InterProcessMutex2 ) diff --git a/tests/zypp/base/InterProcessMutex_test.cc b/tests/zypp/base/InterProcessMutex_test.cc index 9b939a472..5758c253b 100644 --- a/tests/zypp/base/InterProcessMutex_test.cc +++ b/tests/zypp/base/InterProcessMutex_test.cc @@ -26,8 +26,6 @@ using namespace std; using namespace zypp; using namespace zypp::base; -#define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/base/data/Sysconfig") - BOOST_AUTO_TEST_CASE(WaitForTheOther) { int r = 0; @@ -45,8 +43,6 @@ BOOST_AUTO_TEST_CASE(WaitForTheOther) else if ( r == 0 ) { MIL << "child, PID: " << getpid() << endl; - // child - //BOOST_REQUIRE_THROW( InterProcessMutex("testcase"), ZYppLockedException); sleep(3); InterProcessMutex mutex2(InterProcessMutex::Reader,"testcase"); } @@ -55,10 +51,7 @@ BOOST_AUTO_TEST_CASE(WaitForTheOther) MIL << "parent: " << getpid() << endl; InterProcessMutex mutex(InterProcessMutex::Writer,"testcase"); // parent - sleep(3); - - MIL << "first lock will go out of scope" << endl; - + sleep(6); } } //if ( r > 0 ) diff --git a/zypp/base/InterProcessMutex.cc b/zypp/base/InterProcessMutex.cc index 76f3d5c2c..f721d9ec7 100644 --- a/zypp/base/InterProcessMutex.cc +++ b/zypp/base/InterProcessMutex.cc @@ -58,12 +58,12 @@ InterProcessMutex::InterProcessMutex( ConsumerType ctype, // try to create the lock file atomically, this will fail if // the lock exists - if ( ( _fd = open(lock_file.c_str(), O_WRONLY | O_CREAT | O_EXCL) ) == -1 ) + if ( ( _fd = open(lock_file.c_str(), O_RDWR | O_CREAT | O_EXCL) ) == -1 ) { struct flock lock; // the file exists, lets see if someone has it locked exclusively - if ( (_fd = open(lock_file.c_str(), O_RDONLY)) == -1 ) + if ( (_fd = open(lock_file.c_str(), O_RDWR)) == -1 ) { ZYPP_THROW(Exception(str::form(_("It %d, Can't open lock file: %s"), k, strerror(errno)))); } @@ -142,10 +142,7 @@ InterProcessMutex::InterProcessMutex( ConsumerType ctype, { // either there is no lock or a reader has it so we just // acquire a reader lock. - // TODO to know wether there is no lock over the file or there - // is a reader, we would need to test for a writer lock - // that conflicts with it. - // + // try to get more lock info lock.l_type = F_WRLCK; @@ -280,7 +277,7 @@ InterProcessMutex::InterProcessMutex( ConsumerType ctype, } } // end loop - MIL << "Finish constructor" << endl; + LMIL << "Lock intialized" << endl; } @@ -289,6 +286,10 @@ InterProcessMutex::~InterProcessMutex() try { Pathname lock_file = lockFilePath(); + LMIL << "dropping " + << ( (_type == Reader ) ? "reader" : "writer" ) + << " lock on " << lock_file << endl; + switch ( _type ) { case Reader: diff --git a/zypp/base/InterProcessMutex.h b/zypp/base/InterProcessMutex.h index 0dcc55c2a..b4f540d7f 100644 --- a/zypp/base/InterProcessMutex.h +++ b/zypp/base/InterProcessMutex.h @@ -72,7 +72,8 @@ public: int timeout = -1 ); /** - * Destructor + * Destructor, gives up the lock on the named + * resource. */ ~InterProcessMutex();