1
# Copyright (C) 2001, 2003 Free Software Foundation, Inc.
1
# Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
18
# Written by Akim Demaille <akim@freefriends.org>.
218
219
my ($fh, $mode) = @_;
219
220
# Cannot use @_ here.
221
# On some systems (e.g. GNU/Linux with NFSv2), flock(2) does not work over
222
# NFS, but Perl prefers that over fcntl(2) if it exists and if
223
# perl was not built with -Ud_flock. Normally, this problem is harmless,
224
# so ignore the ENOLCK errors that are reported in that situation,
225
# However, if the invoker is using "make -j", the problem is not harmless,
226
# so report it in that case, by inspecting MAKEFLAGS and looking for
227
# any arguments indicating that the invoker used -j.
228
# Admittedly this is a bit of a hack.
229
if (!flock ($fh, $mode)
231
|| " -$ENV{'MAKEFLAGS'}" =~ / (-[BdeikrRsSw]*j|---?jobs)/))
222
# Unless explicitly configured otherwise, Perl implements its `flock' with the
223
# first of flock(2), fcntl(2), or lockf(3) that works. These can fail on
224
# NFS-backed files, with ENOLCK (GNU/Linux) or EOPNOTSUPP (FreeBSD); we
225
# usually ignore these errors. If $ENV{MAKEFLAGS} suggests that a parallel
226
# invocation of GNU `make' has invoked the tool we serve, report all locking
227
# failures and abort.
229
# On Unicos, flock(2) and fcntl(2) over NFS hang indefinitely when `lockd' is
230
# not running. NetBSD NFS clients silently grant all locks. We do not
231
# attempt to defend against these dangers.
232
if (!flock ($fh, $mode))
234
my $make_j = (exists $ENV{'MAKEFLAGS'}
235
&& " -$ENV{'MAKEFLAGS'}" =~ / (-[BdeikrRsSw]*j|---?jobs)/);
236
my $note = "\nforgo `make -j' or use a file system that supports locks";
233
237
my $file = $fh->name;
234
fatal "cannot lock $file with mode $mode (perhaps you are running make -j on a lame NFS client?): $!";
239
msg ($make_j ? 'fatal' : 'unsupported',
240
"cannot lock $file with mode $mode: $!" . ($make_j ? $note : ""))
241
if $make_j || !($!{ENOLCK} || $!{EOPNOTSUPP});