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

List:       kde-commits
Subject:    KDE/kdelibs/kdecore/io
From:       Nickolai Shaforostoff <shafff () ukr ! net>
Date:       2009-02-20 19:36:45
Message-ID: 1235158605.660971.13068.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 929151 by shaforo:

I forgot to commit my patch to trunk.

CCMAIL:faure@kde.org
thanks for noticing this.



 M  +2 -1      klockfile.h  
 M  +42 -44    klockfile_unix.cpp  


--- trunk/KDE/kdelibs/kdecore/io/klockfile.h #929150:929151
@@ -78,7 +78,8 @@
 
      /**
       * Automatically remove a lock when a lock is detected that is stale
-      * for more than staleTime() seconds.
+      * for more than staleTime() seconds, or if the process that created it
+      * is not running anymore.
       */
      ForceFlag = 2
    };
--- trunk/KDE/kdelibs/kdecore/io/klockfile_unix.cpp #929150:929151
@@ -275,54 +275,13 @@
            break;
         }
      }
-     else // KLockFile::Fail
+     else // KLockFile::Fail -- there is already such a file present (e.g. left by a crashed app)
      {
         if (!d->staleTimer.isNull() && d->statBuf != st_buf)
            d->staleTimer = QTime();
 
-        if (!d->staleTimer.isNull())
+        if (d->staleTimer.isNull())
         {
-           bool isStale = false;
-           if ((d->pid > 0) && !d->hostname.isEmpty())
-           {
-              // Check if hostname is us
-              char hostname[256];
-              hostname[0] = 0;
-              gethostname(hostname, 255);
-              hostname[255] = 0;
-
-              if (d->hostname == QLatin1String(hostname))
-              {
-                 // Check if pid still exists
-                 int res = ::kill(d->pid, 0);
-                 if ((res == -1) && (errno == ESRCH))
-                    isStale = true;
-              }
-           }
-           if (d->staleTimer.elapsed() > (d->staleTime*1000))
-              isStale = true;
-
-           if (isStale)
-           {
-              if ((options & ForceFlag) == 0)
-                 return KLockFile::LockStale;
-
-              result = deleteStaleLock(d->file, d->statBuf, d->linkCountSupport, d->componentData);
-
-              if (result == KLockFile::LockOK)
-              {
-                 // Lock deletion successful
-                 d->staleTimer = QTime();
-                 continue; // Now try to get the new lock
-              }
-              else if (result != KLockFile::LockFail)
-              {
-                 return result;
-              }
-           }
-        }
-        else
-        {
            memcpy(&(d->statBuf), &st_buf, sizeof(KDE_struct_stat));
            d->staleTimer.start();
 
@@ -342,9 +301,48 @@
                  d->hostname = ts.readLine();
            }
         }
+
+        bool isStale = false;
+        if ((d->pid > 0) && !d->hostname.isEmpty())
+        {
+           // Check if hostname is us
+           char hostname[256];
+           hostname[0] = 0;
+           gethostname(hostname, 255);
+           hostname[255] = 0;
+
+           if (d->hostname == QLatin1String(hostname))
+           {
+              // Check if pid still exists
+              int res = ::kill(d->pid, 0);
+              if ((res == -1) && (errno == ESRCH))
+                 isStale = true;
+           }
+        }
+        if (d->staleTimer.elapsed() > (d->staleTime*1000))
+           isStale = true;
+
+        if (isStale)
+        {
+           if ((options & ForceFlag) == 0)
+              return KLockFile::LockStale;
+
+           result = deleteStaleLock(d->file, d->statBuf, d->linkCountSupport, d->componentData);
+
+           if (result == KLockFile::LockOK)
+           {
+              // Lock deletion successful
+              d->staleTimer = QTime();
+              continue; // Now try to get the new lock
+           }
+           else if (result != KLockFile::LockFail)
+           {
+              return result;
+           }
+        }
      }
 
-     if ((options & NoBlockFlag) != 0)
+     if (options & NoBlockFlag)
         break;
 
      struct timeval tv;
[prev in list] [next in list] [prev in thread] [next in thread] 

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