flock(3C) on NFS files should fail with EOPNOTSUPP
flock(3C) support does not presently support locking files on remote file systems like NFS (see
F_REMOTELOCK, and comments in
fs_frlock()). In the event that one tries to lock an NFS-backed file,
flock() presently fails with
EINVAL. This is probably not quite right; e.g., in the manual page:
EINVAL The operation argument does not contain one of LOCK_SH, LOCK_EX, or LOCK_UN; or the operation argument contains LOCK_UN and LOCK_NB; or the operation argument contains any bits other than those set by LOCK_SH, LOCK_EX, LOCK_NB, and LOCK_UN. ... EOPNOTSUPP The locking of files of the type indicated by the fildes argument is not supported.
The latter seems more appropriate here.
As an aside, a brief survey of the documentation of other platforms shows:
- FreeBSD and OpenBSD appear to use
EOPNOTSUPPfor this condition
- Mac OS X appears to use
- Linux does not appear to document the possibility of a failure of this kind, but explicitly says
EINVALis for an invalid
It does not seem that
flock() has been standardised.
No data to display