At first, you'd think this wasn't a hole. But opening an SDBM file (the last time I looked) actually causes some file I/O. So what happens in this window is that two processes have read some bookkeeping data from the file into memory, one process gets the lock and proceeds to do things that side effect bookkeeping, while the other process blocks. When the first process frees the lock, the second process unblocks, but has data in memory that is now inconsistent with what's on disk. Oops.my $db = tie(%h, 'SDBM_File', 'filename', O_RDWR|O_CREAT, 0666) or die "Couldn't tie SDBM file 'filename': $!; aborting"; --> # right here flock($db->fd, LOCK_EX);
The way around this is to use a separate file for locking, and acquire the lock before opening the SDBM file.
I may be working off of stale info, though. Can someone who has access to SDBM source confirm that significant I/O happens when the file gets opened?
In reply to Re: Re: Locking a SDBM_File
by dws
in thread Locking a SDBM_File
by Brett Wraight
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |