Fixed bug #8980: unlink of non existant lockfiles generates warnings in frontend...
authorSusanne Moog <typo3@susannemoog.de>
Fri, 15 Oct 2010 09:03:47 +0000 (09:03 +0000)
committerSusanne Moog <typo3@susannemoog.de>
Fri, 15 Oct 2010 09:03:47 +0000 (09:03 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9063 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_lock.php

index 594d32c..579db70 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-10-15  Susanne Moog  <typo3@susanne-moog.de>
+
+       * Fixed bug #8980: unlink of non existant lockfiles generates warnings in frontend (Thanks to André Stösel)
+
 2010-10-14  Jeff Segars  <jeff@webempoweredchurch.org>
 
        * Fixed bug #15800: Cleanup CSH code (Thanks to Benjamin Mack and Steffen Kamper)
index ad7abb1..5fc14b4 100644 (file)
@@ -151,22 +151,28 @@ class t3lib_lock {
                        case 'simple':
                                if (is_file($this->resource)) {
                                        $this->sysLog('Waiting for a different process to release the lock');
-                                       $i = 0;
-                                       while ($i<$this->loops) {
-                                               $i++;
-                                               usleep($this->step * 1000);
-                                               clearstatcache();
-                                               if (!is_file($this->resource)) {        // Lock became free, leave the loop
-                                                       $this->sysLog('Different process released the lock');
-                                                       $noWait = FALSE;
-                                                       break;
-                                               }
+                                       $maxExecutionTime = ini_get('max_execution_time');
+                                       $maxAge = time() - ($maxExecutionTime ? $maxExecutionTime : 120);
+                                       if(@filectime($this->resource) < $maxAge) {
+                                               @unlink($this->resource);
+                                               $this->sysLog('Unlink stale lockfile');
                                        }
-                               } else {
-                                       $noWait = TRUE;
                                }
 
-                               if (($this->filepointer = touch($this->resource)) == FALSE) {
+                               $isAcquired = FALSE;
+                               for ($i = 0; $i < $this->loops; $i++) {
+                                       $filepointer = @fopen($this->resource, 'x');
+                                       if ($filepointer !== FALSE) {
+                                               fclose($filepointer);
+                                               $this->sysLog('Lock aquired');
+                                               $noWait = ($i === 0);
+                                               $isAcquired = TRUE;
+                                               break;
+                                       }
+                                       usleep($this->step * 1000);
+                               }
+
+                               if (!$isAcquired) {
                                        throw new Exception('Lock file could not be created');
                                }
                        break;