diff options
author | Michael Hamann <michael@content-space.de> | 2011-02-06 16:47:38 +0100 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2011-02-06 17:47:17 +0100 |
commit | 9f881d099df700f068e5cc014d089dd9639db731 (patch) | |
tree | d4bc29af80f6fb8bd5b98e62b69a4a14845e8e83 | |
parent | 0993d1c5d3a1738d8aeef80d1d03d3189f5ca858 (diff) | |
download | rpg-9f881d099df700f068e5cc014d089dd9639db731.tar.gz rpg-9f881d099df700f068e5cc014d089dd9639db731.tar.bz2 |
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.
-rw-r--r-- | lib/exe/indexer.php | 12 |
1 files changed, 8 insertions, 4 deletions
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; |