-# Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
use IO::File;
use File::Basename;
use Autom4te::ChannelDefs;
+use Autom4te::Channels qw(msg);
use Autom4te::FileUtils;
require Exporter;
my ($fh, $mode) = @_;
# Cannot use @_ here.
- # On some systems (e.g. GNU/Linux with NFSv2), flock(2) does not work over
- # NFS, but Perl prefers that over fcntl(2) if it exists and if
- # perl was not built with -Ud_flock. Normally, this problem is harmless,
- # so ignore the ENOLCK errors that are reported in that situation,
- # However, if the invoker is using "make -j", the problem is not harmless,
- # so report it in that case, by inspecting MAKEFLAGS and looking for
- # any arguments indicating that the invoker used -j.
- # Admittedly this is a bit of a hack.
- if (!flock ($fh, $mode)
- && (!$!{ENOLCK}
- || (exists $ENV{'MAKEFLAGS'}
- && " -$ENV{'MAKEFLAGS'}" =~ / (-[BdeikrRsSw]*j|---?jobs)/)))
+ # Unless explicitly configured otherwise, Perl implements its `flock' with the
+ # first of flock(2), fcntl(2), or lockf(3) that works. These can fail on
+ # NFS-backed files, with ENOLCK (GNU/Linux) or EOPNOTSUPP (FreeBSD); we
+ # usually ignore these errors. If $ENV{MAKEFLAGS} suggests that a parallel
+ # invocation of GNU `make' has invoked the tool we serve, report all locking
+ # failures and abort.
+ #
+ # On Unicos, flock(2) and fcntl(2) over NFS hang indefinitely when `lockd' is
+ # not running. NetBSD NFS clients silently grant all locks. We do not
+ # attempt to defend against these dangers.
+ if (!flock ($fh, $mode))
{
+ my $make_j = (exists $ENV{'MAKEFLAGS'}
+ && " -$ENV{'MAKEFLAGS'}" =~ / (-[BdeikrRsSw]*j|---?jobs)/);
+ my $note = "\nforgo `make -j' or use a file system that supports locks";
my $file = $fh->name;
- fatal ("cannot lock $file with mode $mode "
- . "(perhaps you are running make -j on a lame NFS client?): $!");
+
+ msg ($make_j ? 'fatal' : 'unsupported',
+ "cannot lock $file with mode $mode: $!" . ($make_j ? $note : ""))
+ if $make_j || !($!{ENOLCK} || $!{EOPNOTSUPP});
}
}