[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdelibs/kabc/plugins
From:       Tobias Koenig <tokoe () kde ! org>
Date:       2003-08-28 19:35:30
[Download RAW message or body]

CVS commit by tokoe: 

Add intelligent lock file handling to ResourceDir as well and add an AddressBook::error()
message, to tell the user which application blocks which resource.


  M +25 -1     dir/resourcedir.cpp   1.21
  M +4 -1      file/resourcefile.cpp   1.23


--- kdelibs/kabc/plugins/dir/resourcedir.cpp  #1.20:1.21
@@ -19,4 +19,6 @@
 */
 
+#include <errno.h>
+#include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -239,5 +241,25 @@ bool ResourceDir::lock( const QString &p
   kdDebug(5700) << "-- lock name: " << lockName << endl;
 
-  if ( QFile::exists( lockName ) ) return false;
+  if ( QFile::exists( lockName ) ) {  // check if it is a stale lock file
+    QFile file( lockName );
+    if ( !file.open( IO_ReadOnly ) )
+      return false;
+
+    QDataStream t( &file );
+
+    QString app; int pid;
+    t >> pid >> app;
+
+    int retval = ::kill( pid, 0 );
+    if ( retval == -1 && errno == ESRCH ) { // process doesn't exists anymore
+      QFile::remove( lockName );
+      kdError() << "dedect stale lock file from process '" << app << "'" << endl;
+      file.close();
+    } else {
+      addressBook()->error( i18n( "The resource '%1' is locked by application '%2'." )
+                            .arg( resourceName() ).arg( app )  );
+      return false;
+    }
+  }
 
   QString lockUniqueName;
@@ -249,4 +271,6 @@ bool ResourceDir::lock( const QString &p
   QFile file( mLockUniqueName );
   file.open( IO_WriteOnly );
+  QDataStream t( &file );
+  t << ::getpid() << QString( KGlobal::instance()->instanceName() );
   file.close();
 

--- kdelibs/kabc/plugins/file/resourcefile.cpp  #1.22:1.23
@@ -260,6 +260,9 @@ bool ResourceFile::lock( const QString &
       kdError() << "dedect stale lock file from process '" << app << "'" << endl;
       file.close();
-    } else
+    } else {
+      addressBook()->error( i18n( "The resource '%1' is locked by application '%2'." )
+                            .arg( resourceName() ).arg( app )  );
       return false;
+    }
   }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic