Subject: bin/35619: unlink+fopen race in makewhatis
To: None <firstname.lastname@example.org, email@example.com>
From: None <uwe@NetBSD.org>
Date: 02/15/2007 23:45:00
>Synopsis: unlink+fopen race in makewhatis
>Arrival-Date: Thu Feb 15 23:45:00 +0000 2007
>Originator: Valery Ushakov
if ((out = fopen(whatisdb, "w")) == NULL)
err(EXIT_FAILURE, "Cannot open `%s'", whatisdb);
to create the whatis database. If two hosts share the man dir
via NFS and if both run makehwatis, there is a race that might
cause two instances of makewhatis to dump whatis database into
the same file.
Even if we don't consider the race, there's a window in which the
whatis database is incompelte (as makewhatis is still running).
A smaller example:
host1$ (echo A; sleep 10; echo B) > a &
host2$ (echo 1; sleep 10; echo 2) > a &
There's a window in which you can see a to contain "1\bB\b"
makewhatis should use temp file + rename(2) so that the whatis database
is consistent at all times.