summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorErmal <eri@pfsense.org>2010-03-19 15:55:04 +0000
committerErmal <eri@pfsense.org>2010-03-19 15:55:04 +0000
commit541989d59005d5b9250d4d51f55cbc4da218937a (patch)
treed52270e174b89fcc940b32443e895c1f854b943f /etc
parent773c99bc37c742cc94a1894914c5ba4a7b5abdd7 (diff)
downloadpfsense-541989d59005d5b9250d4d51f55cbc4da218937a.zip
pfsense-541989d59005d5b9250d4d51f55cbc4da218937a.tar.gz
Ticket #434. Do not die when parsing config since we know how to recover. Only die during packages.
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/config.lib.inc7
-rw-r--r--etc/inc/pfsense-utils.inc5
-rw-r--r--etc/inc/xmlparse.inc9
3 files changed, 13 insertions, 8 deletions
diff --git a/etc/inc/config.lib.inc b/etc/inc/config.lib.inc
index 61f76ea..56a8ef8 100644
--- a/etc/inc/config.lib.inc
+++ b/etc/inc/config.lib.inc
@@ -465,14 +465,13 @@ function write_config($desc="Unknown", $backup = true) {
backup_config();
if (time() > mktime(0, 0, 0, 9, 1, 2004)) /* make sure the clock settings are plausible */
- $changetime = time();
+ $config['revision']['time'] = time();
/* Log the running script so it's not entirely unlogged what changed */
if ($desc == "Unknown")
$desc = "{$_SERVER['SCRIPT_NAME']} made unknown change";
$config['revision']['description'] = $desc;
- $config['revision']['time'] = $changetime;
$lockkey = lock('config');
@@ -485,7 +484,8 @@ function write_config($desc="Unknown", $backup = true) {
if (!safe_write_file("{$g['cf_conf_path']}/config.xml", $xmlconfig, false)) {
log_error("WARNING: Config contents could not be save. Could not open file!");
unlock($lockkey);
- die("Unable to open {$g['cf_conf_path']}/config.xml for writing in write_config()\n");
+ file_notice("Unable to open {$g['cf_conf_path']}/config.xml for writing in write_config()\n");
+ return -1;
}
if($g['platform'] == "embedded" or $g['platform'] == "nanobsd") {
@@ -495,6 +495,7 @@ function write_config($desc="Unknown", $backup = true) {
}
/* re-read configuration */
+ /* NOTE: We assume that the file can be parsed since we wrote it. */
$config = parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']);
/* write config cache */
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index 9841da4..d4e153b 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -637,8 +637,9 @@ function restore_config_section($section, $new_contents) {
fwrite($fout, $new_contents);
fclose($fout);
$section_xml = parse_xml_config($g['tmp_path'] . "/tmpxml", $section);
- $config[$section] = &$section_xml;
- unlink($g['tmp_path'] . "/tmpxml");
+ if ($section_xml != -1)
+ $config[$section] = &$section_xml;
+ @unlink($g['tmp_path'] . "/tmpxml");
write_config("Restored {$section} of config file (maybe from CARP partner)");
conf_mount_ro();
return;
diff --git a/etc/inc/xmlparse.inc b/etc/inc/xmlparse.inc
index 85f18e7..459ee15 100644
--- a/etc/inc/xmlparse.inc
+++ b/etc/inc/xmlparse.inc
@@ -173,7 +173,8 @@ function parse_xml_config_pkg($cffile, $rootobj, $isstring = "false") {
$listtags[] = $tag;
}
}
- return parse_xml_config_raw($cffile, $rootobj, $isstring);
+ if (parse_xml_config_raw($cffile, $rootobj, $isstring) == -1)
+ die("XML error: not $rootboj object found!\n");
}
function parse_xml_regdomain(&$rdattributes, $rdfile = '/etc/regdomain.xml', $rootobj = 'regulatory-data') {
@@ -208,7 +209,8 @@ function parse_xml_config_raw($cffile, $rootobj, $isstring = "false") {
xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE, 1);
if (!($fp = fopen($cffile, "r"))) {
- die("Error: could not open XML input\n");
+ log_error("Error: could not open XML input\n");
+ return -1;
}
while ($data = fread($fp, 4096)) {
@@ -222,7 +224,8 @@ function parse_xml_config_raw($cffile, $rootobj, $isstring = "false") {
xml_parser_free($xml_parser);
if (!$parsedcfg[$rootobj]) {
- die("XML error: no $rootobj object found!\n");
+ log_error("XML error: no $rootobj object found!\n");
+ return -1;
}
return $parsedcfg[$rootobj];
OpenPOWER on IntegriCloud