diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2010-02-14 12:53:58 -0500 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2010-02-14 12:53:58 -0500 |
commit | e5977136bb173ab2c03ed4cdbc692ba0cb1996b0 (patch) | |
tree | cd657f45910b5efa007beef0d65a2c0cd13f853c /etc | |
parent | 8daddfd1bfffae7ff14f7b50cdaa3929b5110557 (diff) | |
download | pfsense-e5977136bb173ab2c03ed4cdbc692ba0cb1996b0.zip pfsense-e5977136bb173ab2c03ed4cdbc692ba0cb1996b0.tar.gz |
Write out config.xml.tmp first and then move into place after it is written trying to avoid half written files during panic or livelock situations
Diffstat (limited to 'etc')
-rw-r--r-- | etc/inc/config.lib.inc | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/etc/inc/config.lib.inc b/etc/inc/config.lib.inc index 2c2c126..ea0c206 100644 --- a/etc/inc/config.lib.inc +++ b/etc/inc/config.lib.inc @@ -68,9 +68,10 @@ function encrypted_configxml() { if(!strstr($data, "<pfsense>")) $data = ""; if($data) { - $fd = fopen($g['conf_path'] . "/config.xml", "w"); + $fd = fopen($g['conf_path'] . "/config.xml.tmp", "w"); fwrite($fd, $data); fclose($fd); + exec("/bin/mv {$g['conf_path']}/config.xml.tmp {$g['conf_path']}/config.xml"); echo "\nConfig.xml unlocked.\n"; fclose($fp); } else { @@ -456,22 +457,25 @@ function write_config($desc="Unknown", $backup = true) { conf_mount_rw(); - /* write new configuration */ - $fd = fopen("{$g['conf_path']}/config.xml", "w"); - if (!$fd) { - // Unable to open temporary file for writing + /* write new configuration to a .tmp file first and then move into place */ + $fd = fopen("{$g['conf_path']}/config.xml.tmp", "w"); + if (!$fd) { + // Unable to open temporary file for writing log_error("WARNING: Config contents could not be save. Could not open file!"); unlock($lockkey); - return false; - } - if (!fwrite($fd, $xmlconfig)) { - // Unable to write to temporary file + return false; + } + if (!fwrite($fd, $xmlconfig)) { + // Unable to write to temporary file log_error("WARNING: Config contents could not be written on file."); - fclose($fd); + fclose($fd); unlock($lockkey); - return false; - } - fclose($fd); + return false; + } + fclose($fd); + + // Move completely written file into place + exec("/bin/mv {$g['conf_path']}/config.xml.tmp {$g['conf_path']}/config.xml"); if($g['platform'] == "embedded" or $g['platform'] == "nanobsd") { cleanup_backupcache(5, true); |