mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-15 07:48:52 +00:00
[ticket/11515] Extra check after acquiring locks.
Add additional check to flock.php and db.php to ensure lock aquiring. PHPBB3-11515
This commit is contained in:
parent
967817143d
commit
9063556a57
3 changed files with 37 additions and 2 deletions
|
@ -147,6 +147,27 @@ class config implements \ArrayAccess, \IteratorAggregate, \Countable
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks configuration option's value only if the new_value matches the
|
||||||
|
* current configuration value and the configuration value does exist.Called
|
||||||
|
*only after set_atomic has been called.
|
||||||
|
*
|
||||||
|
* @param string $key The configuration option's name
|
||||||
|
* @param string $old_value Current configuration value
|
||||||
|
* @param string $new_value New configuration value
|
||||||
|
* @throws \phpbb\exception\http_exception when configuration value is set and not equal to *new_value.
|
||||||
|
* @return bool True if the value was changed, false otherwise.
|
||||||
|
*/
|
||||||
|
public function ensure_lock($key, $new_value)
|
||||||
|
{
|
||||||
|
if(isset($this->config[$key]) && $this->config[$key] == $new_value)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new \phpbb\exception\http_exception(500, 'Failure while aqcuiring locks.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments an integer configuration value.
|
* Increments an integer configuration value.
|
||||||
*
|
*
|
||||||
|
|
|
@ -110,8 +110,17 @@ class db
|
||||||
// process we failed to acquire the lock.
|
// process we failed to acquire the lock.
|
||||||
$this->locked = $this->config->set_atomic($this->config_name, $lock_value, $this->unique_id, false);
|
$this->locked = $this->config->set_atomic($this->config_name, $lock_value, $this->unique_id, false);
|
||||||
|
|
||||||
|
if ($this->locked == true)
|
||||||
|
{
|
||||||
|
if ($this->config->ensure_lock($this->config_name, $this->unique_id))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
return $this->locked;
|
return $this->locked;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does this process own the lock?
|
* Does this process own the lock?
|
||||||
|
|
|
@ -101,7 +101,12 @@ class flock
|
||||||
|
|
||||||
if ($this->lock_fp)
|
if ($this->lock_fp)
|
||||||
{
|
{
|
||||||
@flock($this->lock_fp, LOCK_EX);
|
if (@flock($this->lock_fp, LOCK_EX))
|
||||||
|
{
|
||||||
|
return (bool) $this->lock_fp;
|
||||||
|
} else {
|
||||||
|
throw new \phpbb\exception\http_exception(500, 'Failure while aqcuiring locks.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool) $this->lock_fp;
|
return (bool) $this->lock_fp;
|
||||||
|
|
Loading…
Add table
Reference in a new issue