Esempio n. 1
0
 static function runScript($cli, $scriptFile)
 {
     $scriptMutex = new eZMutex($scriptFile);
     $lockTS = $scriptMutex->lockTS();
     $runScript = false;
     $maxTime = self::maxScriptExecutionTime();
     if ($lockTS === false) {
         if ($scriptMutex->lock()) {
             $scriptMutex->setMeta('pid', getmypid());
             $runScript = true;
         } else {
             $cli->error('Failed to aquire cronjob part lock: ' . $scriptFile);
         }
     } else {
         if ($lockTS < time() - 2 * $maxTime) {
             $cli->output('Forcing to steal the mutex lock: ' . $scriptFile);
             $runScript = eZRunCronjobs::stealMutex($cli, $scriptMutex, true);
         } else {
             if ($lockTS < time() - $maxTime) {
                 $cli->output('Trying to steal the mutex lock: ' . $scriptFile);
                 $runScript = eZRunCronjobs::stealMutex($cli, $scriptMutex);
             } else {
                 $cli->output('Cronjob part locked by other process: ' . $scriptMutex->meta('pid'));
             }
         }
     }
     if ($runScript) {
         global $script;
         global $isQuiet;
         global $cronPart;
         include $scriptFile;
         $scriptMutex->unlock();
     }
 }
 /**
  * Test scenario for issue #13622: mutex - windows file are not remove
  *
  * Test Outline
  * ------------
  * 1. Create a mutex for test.txt
  * 2. Lock the mutex.
  * 3. Unlock the mutex.
  *
  * @result: the mutex lock file is not removed.
  * @expected: the mutex lock file is removed.
  * @link http://issues.ez.no/13622
  */
 public function testUnlock()
 {
     $scriptMutex = new eZMutex('test.txt');
     $lockTS = $scriptMutex->lockTS();
     $lockFileName = $this->readAttribute($scriptMutex, 'FileName');
     if ($lockTS === false && $scriptMutex->lock()) {
         $scriptMutex->setMeta('pid', getmypid());
         $scriptMutex->unlock();
         $this->assertFalse(file_exists($lockFileName), 'Mutex lock file was not removed.');
     } else {
         $this->fail("Unable to create a locking mutex. This might be the result of the failure of a previous test. Please remove the lock file {$lockFileName} from the file system and run the test again.");
     }
 }
Esempio n. 3
0
 function steal($force = false)
 {
     $stealMutex = new eZMutex($this->Name . eZMutex::STEAL_STRING);
     if (!$force) {
         // Aquire a steal mutex, and steal the mutex.
         if ($stealMutex->test()) {
             return false;
         }
         if ($stealMutex->lock()) {
             $stealMutex->setMeta('pid', getmypid());
             if ($this->lock()) {
                 // sleep for 1 second in case lock has only been granted beacause a larger
                 // cleanup is in progress.
                 sleep(1);
                 $stealMutex->unlock();
                 return true;
             }
         }
     } else {
         $stealPid = $stealMutex->meta('pid');
         if (is_numeric($stealPid) && $stealPid != 0 && function_exists('posix_kill')) {
             eZDebug::writeNotice('Killing steal mutex process: ' . $stealPid);
             posix_kill($stealPid, 9);
         }
         // If other steal mutex exists, kill it, and create your own.
         $this->unlock();
         return $this->lock();
     }
     return false;
 }