|
Posted by CptDondo on 10/02/06 23:59
I have an embedded system that will save configuration files based on
user input. This device will be used in areas that have uncertain
power, and a battery backup is not a realistic option.
It is not critical that the user's latest changes be saved, but it is
critical that the system have a valid configuration file, so I want to
minimize the chances of having a corrupt config file.
I've come up with this:
$oldConfFile = $confFile . ".bak";
$newConfFile = $confFile . ".new";
$fp = fopen($newConfFile, "w");
// FIXME error message here
if ($fp == false ) return array();
fputs($fp, $newConfig);
fclose($fp);
rename($confFile,$oldConfFile);
rename($newConfFile,$confFile);
which is about as atomic as I can think of.... And I can do some
checking on boot and (possibly) copy either the .bak or the .new file
over to the config file if it is valid and the main config file is not.
Can anyone offer any comments or suggestions for making this more robust?
[Back to original message]
|