March 2002 | Perl Hardware Store | 20 |
use Fcntl ':flock';
if (something()) { open F, $FILE or die ...; flock F, LOCK_SH; print while <F>; } else { open F, "> $FILE" or die ...; flock F, LOCK_EX; my $data = qx{some command}; print F $data; }
Oops, it's still wrong
The open clobbers the file contents before the file is locked
Maybe we can lock the file before we open it? ... Nope
Maybe the writer can open in append mode, lock the file, seek to the beginning, overwrite the contents, then call truncate ...
Bah!
Next | Copyright © 2002 M-J. Dominus |