From 4e1562af51a54e9d7d810bda00d46d3d84f711eb Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 22 Jun 2023 10:53:27 +0200 Subject: [PATCH] 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 --- .../mvc/app/library/OPNsense/Core/Config.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php index 263bc7405..9d9baf206 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php +++ b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php @@ -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; }