Re: PATCH: Make install-info use fcntl (via perl's flock) for locking
tags 2531 - patch
Nathanael Nerode writes ("PATCH: Make install-info use fcntl (via perl's flock) for locking"):
> This patch converts install-info to use perl's flock for locking.
> As part of this change, it now operates directly on the dir file
Unfortunately, this is wrong. If you operate directly on the dir file
then disk full and other errors can cause the file to be truncated.
This is OK if you write the new version to a temp file and rename into
place, because only the temp file is damaged. If you try to do it by
writing to the primary file directly then if your script fails and the
primary file is damaged, the next run will probablu overwrite the
For this reason, when using fcntl locking, you generally have to use a
Also, when changing between different locking methods, you have to
either be sure that only your program might be editing the file, or
you have to have a dual running approach. In this case one
possibility would be to use the .lock file that current install-info
uses as the separate lockfile and to write `perl-flock' into it to
indicate that the lock is held either (a) by the process which created
the file empty or (b) if the file contains `perl-flock' by the process
with a Perl flock on the file.
So the process of locking and updating would be:
1. Attempt to open .lock for writing O_EXCL
a. If this succeeds, write "perl-flock\n"
b. If this fails,
i. open the file for reading; if this fails ENOENT
go back to start
ii. check whether the file contains only "perl-flock\n"
and if not sleep 1 and go back to start
2. Lock .lock with Perl's flock
3. Read old file contents
4. Write new file contents to temporary file
5. Unlink old backup file
6. link(2) old file to backup file
7. rename(2) temporary file to primary file