From 9f881d099df700f068e5cc014d089dd9639db731 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 6 Feb 2011 16:47:38 +0100 Subject: Only remove the indexer lock when there is really a stale lock Previously the rmdir could be executed when the lock directory had been deleted by another indexer already. This could lead to a race condition when another indexer call creates the lock again between the if and the rmdir. This issue still exists for stale lock directories but they normally shouldn't exist. This also prevents the loop from becoming an endless loop when the lock directory can't be created. This change also fixes a syntax error in the indexer and prevents an endless loop when the lock directory exists but can't be deleted. --- lib/exe/indexer.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 010ca7987..0042e92d2 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -153,11 +153,15 @@ function runIndexer(){ $lock = $conf['lockdir'].'/_indexer.lock'; while(!@mkdir($lock,$conf['dmode'])){ usleep(50); - if(time()-@filemtime($lock) > 60*5){ + if(is_dir($lock) && time()-@filemtime($lock) > 60*5){ // looks like a stale lock - remove it - @rmdir($lock); - print "runIndexer(): stale lock removed".NL; - }elseif($run++ = 1000){ + if (!@rmdir($lock)) { + print "runIndexer(): removing the stale lock failed".NL; + return false; + } else { + print "runIndexer(): stale lock removed".NL; + } + }elseif($run++ == 1000){ // we waited 5 seconds for that lock print "runIndexer(): indexer locked".NL; return false; -- cgit v1.2.3