Subject: | Flock and open for writing race condition |
It looks to me that this code
open my $fh, '>', $filename
or croak "Can't open config file '$filename' for writing
(\L$!\E)";
flock($fh,LOCK_EX|LOCK_NB)
|| croak "Can't write to locked config file '$filename'"
if ! ref $filename;
will actually destroy file before croak 'Can't write to locked config file'
AFAIK, open in not distructive read/write mode + flock + seek +
truncate is advised here - http://www.perlmonks.org/index.pl?node_id=7058