Author: dmacvicar Date: Thu Mar 27 17:18:56 2008 New Revision: 9285 URL: http://svn.opensuse.org/viewcvs/zypp?rev=9285&view=rev Log: - the lock passes the two testcases now Modified: trunk/libzypp/tests/zypp/base/CMakeLists.txt trunk/libzypp/tests/zypp/base/InterProcessMutex_test.cc trunk/libzypp/zypp/base/InterProcessMutex.cc trunk/libzypp/zypp/base/InterProcessMutex.h Modified: trunk/libzypp/tests/zypp/base/CMakeLists.txt URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/base/CMakeLists.txt?rev=9285&r1=9284&r2=9285&view=diff ============================================================================== --- trunk/libzypp/tests/zypp/base/CMakeLists.txt (original) +++ trunk/libzypp/tests/zypp/base/CMakeLists.txt Thu Mar 27 17:18:56 2008 @@ -1,3 +1,3 @@ ADD_TESTS(Sysconfig ) -#ADD_TESTS( InterProcessMutex2 ) +ADD_TESTS( InterProcessMutex InterProcessMutex2 ) Modified: trunk/libzypp/tests/zypp/base/InterProcessMutex_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/base/InterProcessMutex_test.cc?rev=9285&r1=9284&r2=9285&view=diff ============================================================================== --- trunk/libzypp/tests/zypp/base/InterProcessMutex_test.cc (original) +++ trunk/libzypp/tests/zypp/base/InterProcessMutex_test.cc Thu Mar 27 17:18:56 2008 @@ -26,8 +26,6 @@ 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 @@ 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 @@ 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 ) Modified: trunk/libzypp/zypp/base/InterProcessMutex.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/InterProcessMutex.cc?rev=9285&r1=9284&r2=9285&view=diff ============================================================================== --- trunk/libzypp/zypp/base/InterProcessMutex.cc (original) +++ trunk/libzypp/zypp/base/InterProcessMutex.cc Thu Mar 27 17:18:56 2008 @@ -58,12 +58,12 @@ // 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 @@ { // 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 @@ } } // end loop - MIL << "Finish constructor" << endl; + LMIL << "Lock intialized" << endl; } @@ -289,6 +286,10 @@ try { Pathname lock_file = lockFilePath(); + LMIL << "dropping " + << ( (_type == Reader ) ? "reader" : "writer" ) + << " lock on " << lock_file << endl; + switch ( _type ) { case Reader: Modified: trunk/libzypp/zypp/base/InterProcessMutex.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/InterProcessMutex.h?rev=9285&r1=9284&r2=9285&view=diff ============================================================================== --- trunk/libzypp/zypp/base/InterProcessMutex.h (original) +++ trunk/libzypp/zypp/base/InterProcessMutex.h Thu Mar 27 17:18:56 2008 @@ -72,7 +72,8 @@ int timeout = -1 ); /** - * Destructor + * Destructor, gives up the lock on the named + * resource. */ ~InterProcessMutex(); -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org