Subject: Cross-building from FreeBSD: file locking on METALOG
To: None <tech-toolchain@netbsd.org>
From: Andrew Reilly <andrew-netbsd@areilly.bpc-users.org>
List: tech-toolchain
Date: 06/26/2006 14:28:45
Hi all,
I've been trying to cross-build a couple of NetBSD ports (i386
and evbarm) from my main FreeBSD amd64 workstation, and running
into a couple of problems (one of which seems to be well on the
way to resolution with the switch to gcc4: thanks!)
One that surprised me was that it seems that lines are added to
$(DESTDIR)/METALOG with $(METALOG.add) from bsd.own.mk (please
correct me if I'm wrong!). $(METALOG.add) is "$(TOOL_CAT) -l
>> $(METALOG)", where TOOL_CAT is NetBSD's cat in the tool
directory, and -l seems to be a NetBSD specific option to cat to
lock the output file with fcntl() or wait until that's possible.
That seems like a really neat idea, except that apparently
fcntl(.., F_SETLOCKW,..) doesn't work on regular files on
FreeBSD at the moment. After some discussion I've discovered
that the FreeBSD way to do this is with lockf(1), which uses
open(..., |O_EXLOCK|..., ) to lock a named file and execute a
child command on success. So the equivalent would be: lockf -k
METALOG cat >> METALOG.
I'm about to try tweaking bsd.own.mk to see if that helps with
forward progress...
I just looked and the lockf man page claims that it's been in
FreeBSD since 2.2, which was long, long ago. Any particular
reason that NetBSD hasn't acquired a version for itself yet? It
seems like a more flexible and general way to achieve this sort
of thing than having a non-standard option to a standard
utility (although I thought that cat -l was a neat-o idea myself
until I was shown lockf...)
Cheers,
--
Andrew