F
Fiftyvolts
I'm writing a set of CGI scripts that create and manage Berkeley DB
files. I need them to be able to read and write to the files with out
having other users klobber them before they get the chance. I want to
use file locking but there are some issues.
I am am unluckily stuck with a slow moving IT department managing the
webserver, and am stuck with perl 5.005 with only the standard modules
installed (and no good hope of getting a new version or module
installed since, quite frankly, they don't know what they are doing and
won't let me take care of myself). This is truly the one large
difficulty in my purpose.
Traditionally file locking was supposed to go like this:
$x = tie %hash, DB_File, 'data', O_RDWR;
open(DB, $x->fd);
flock(DB, LOCK_EX);
but it, as the author of DB_File reveales, someone pointed out that
when you tie the %hash the file is read before the lock is made. He
suggest several modules that can mimic flock, but I am unable to obtain
them in a timely manner. So my question is wheater the following
approach will work properly:
open(DB, 'data');
flock(DB, LOCK_EX);
tie %hash, DB_File, 'data', O_RDWR;
My initial testing seems to indicate that it does, but one never knows
until something breaks. Any thoughts?
Thanks,
MST
files. I need them to be able to read and write to the files with out
having other users klobber them before they get the chance. I want to
use file locking but there are some issues.
I am am unluckily stuck with a slow moving IT department managing the
webserver, and am stuck with perl 5.005 with only the standard modules
installed (and no good hope of getting a new version or module
installed since, quite frankly, they don't know what they are doing and
won't let me take care of myself). This is truly the one large
difficulty in my purpose.
Traditionally file locking was supposed to go like this:
$x = tie %hash, DB_File, 'data', O_RDWR;
open(DB, $x->fd);
flock(DB, LOCK_EX);
but it, as the author of DB_File reveales, someone pointed out that
when you tie the %hash the file is read before the lock is made. He
suggest several modules that can mimic flock, but I am unable to obtain
them in a timely manner. So my question is wheater the following
approach will work properly:
open(DB, 'data');
flock(DB, LOCK_EX);
tie %hash, DB_File, 'data', O_RDWR;
My initial testing seems to indicate that it does, but one never knows
until something breaks. Any thoughts?
Thanks,
MST