B
Babu
Hi,
I have an application that maintains its configuration file. This file
is read frequently but written to very rarely. There may be several
processes attempting to read and write to the config file.
The application reads the configuration file into a buffer, inflicts
changes on the buffer and writes the buffer to the file.
The intended logic for writing the buffer into the config file is as
follows
# create a copy of config.txt say as config.txt.bak
open CONFIG_FILE, "config.txt";
flock CONFIG_FILE, LOCK_EX;
eval {
print CONFIG_FILE "blah blah blah";
close CONFIG_FILE;
}
if ($@)
{
#CRITICAL POINT
#move config.txt.bak to config.txt
}
An issue arises when the writer process is at "CRITICAL POINT" and
another reader process attempts to read the config. File. Since the
write operation has failed, the current config. File is corrupt and the
original config. File has not been restored yet. So the reader process
gets into trouble.
Any idea on how to tackle this?
TIA,
Babu
I have an application that maintains its configuration file. This file
is read frequently but written to very rarely. There may be several
processes attempting to read and write to the config file.
The application reads the configuration file into a buffer, inflicts
changes on the buffer and writes the buffer to the file.
The intended logic for writing the buffer into the config file is as
follows
# create a copy of config.txt say as config.txt.bak
open CONFIG_FILE, "config.txt";
flock CONFIG_FILE, LOCK_EX;
eval {
print CONFIG_FILE "blah blah blah";
close CONFIG_FILE;
}
if ($@)
{
#CRITICAL POINT
#move config.txt.bak to config.txt
}
An issue arises when the writer process is at "CRITICAL POINT" and
another reader process attempts to read the config. File. Since the
write operation has failed, the current config. File is corrupt and the
original config. File has not been restored yet. So the reader process
gets into trouble.
Any idea on how to tackle this?
TIA,
Babu