- the lock passes the two testcases now
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 27 Mar 2008 16:18:56 +0000 (16:18 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 27 Mar 2008 16:18:56 +0000 (16:18 +0000)
tests/zypp/base/CMakeLists.txt
tests/zypp/base/InterProcessMutex_test.cc
zypp/base/InterProcessMutex.cc
zypp/base/InterProcessMutex.h

index 48f259b1212a56a1e5ac0518ffb475f5b5fe2f3f..ff7b15309704e665a7ff4057a0ae753076959706 100644 (file)
@@ -1,3 +1,3 @@
 
 ADD_TESTS(Sysconfig )
-#ADD_TESTS( InterProcessMutex2 )
+ADD_TESTS( InterProcessMutex InterProcessMutex2 )
index 9b939a4726f4557d48faae53f33c357d6c7612b5..5758c253be1f8958a91cf91b1c50a8baed014ca6 100644 (file)
@@ -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 )
index 76f3d5c2c5103fc8ed55fd006059c7120d4bd3ca..f721d9ec729aaf4bd73cb20b2f88080938eb4afd 100644 (file)
@@ -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:
index 0dcc55c2aec3106c139144a4b67182a3802709c2..b4f540d7f65856db8ef98d8b96e90df5f1c3df5c 100644 (file)
@@ -72,7 +72,8 @@ public:
                        int timeout = -1 );
 
     /**
-     * Destructor
+     * Destructor, gives up the lock on the named
+     * resource.
      */
     ~InterProcessMutex();