From af0f961b368f34bf90899c07cdfc796dd9c300f3 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 3 May 2017 10:02:17 +0545 Subject: Fix #7508 stop write_config after reset_factory_defaults (cherry picked from commit 3dcaae882cdfdd86826be4db9b38ce04389701ec) --- src/etc/inc/config.lib.inc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/etc/inc/config.lib.inc b/src/etc/inc/config.lib.inc index 5bafa65..00eadd9 100644 --- a/src/etc/inc/config.lib.inc +++ b/src/etc/inc/config.lib.inc @@ -560,6 +560,16 @@ function write_config($desc="Unknown", $backup = true, $write_config_only = fals session_commit(); } + if (isset($config['reset_factory_defaults'])) { + /* + We have put a default config.xml on disk and are about to reboot + or reload it. Do not let any system or package code try to save + state to config because that would overwrite the default config + with the running config. + */ + return false; + } + if ($backup) { backup_config(); } @@ -634,7 +644,7 @@ function write_config($desc="Unknown", $backup = true, $write_config_only = fals * integer - indicates completion ******/ function reset_factory_defaults($lock = false, $reboot_required = true) { - global $g; + global $config, $g; conf_mount_rw(); @@ -666,6 +676,17 @@ function reset_factory_defaults($lock = false, $reboot_required = true) { disable_security_checks(); + /* + Let write_config know that we are awaiting reload of the current config + to factory defaults. Either the system is about to reboot, throwing away + the current in-memory config as it shuts down, or the in-memory config + is about to be reloaded on-the-fly by parse_config. + + In both cases, we want to ensure that write_config does not flush the + in-memory config back to disk. + */ + $config['reset_factory_defaults'] = true; + /* call the wizard */ if ($reboot_required) { // If we need a reboot first then touch a different trigger file. -- cgit v1.1