mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 09:04:39 +00:00
MVC/Config - fix locking regresion in https://github.com/opnsense/core/issues/6565. When we call for an explicit lock() we should keep track of this ourselves so loadFromStream() doesn't unlock it after reading. closes https://github.com/opnsense/core/issues/6630
This commit is contained in:
parent
18d6e18d76
commit
4e1562af51
@ -57,6 +57,12 @@ class Config extends Singleton
|
||||
*/
|
||||
private $simplexml = null;
|
||||
|
||||
/**
|
||||
* status field: file is locked (Exclusive)
|
||||
* @var bool
|
||||
*/
|
||||
private $statusIsLocked = false;
|
||||
|
||||
/**
|
||||
* status field: valid config loaded
|
||||
* @var bool
|
||||
@ -310,6 +316,7 @@ class Config extends Singleton
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->statusIsLocked = false;
|
||||
$this->config_file = FactoryDefault::getDefault()->get('config')->globals->config_path . "config.xml";
|
||||
try {
|
||||
$this->load();
|
||||
@ -381,7 +388,9 @@ class Config extends Singleton
|
||||
|
||||
$result = simplexml_load_string($xml);
|
||||
restore_error_handler();
|
||||
flock($fp, LOCK_UN);
|
||||
if (!$this->statusIsLocked) {
|
||||
flock($fp, LOCK_UN);
|
||||
}
|
||||
if ($result != null) {
|
||||
break; // successful load
|
||||
}
|
||||
@ -746,6 +755,7 @@ class Config extends Singleton
|
||||
{
|
||||
if ($this->config_file_handle !== null) {
|
||||
flock($this->config_file_handle, LOCK_EX);
|
||||
$this->statusIsLocked = true;
|
||||
if ($reload) {
|
||||
$this->load();
|
||||
}
|
||||
@ -760,6 +770,7 @@ class Config extends Singleton
|
||||
{
|
||||
if (is_resource($this->config_file_handle)) {
|
||||
flock($this->config_file_handle, LOCK_UN);
|
||||
$this->statusIsLocked = false;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user