HP-UX Reference (11i v1 00/12) - 2 System Calls (vol 5)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man2/!!!intro.2
________________________________________________________________
___ ___
l
lockf(2) lockf(2)
A potential for deadlock occurs if a process controlling a locked resource is put to sleep by accessing the
locked resource of another process. Thus, calls to fcntl(), lockf(), read(),orwrite() (see
fcntl(2), lockf(2), read(2), and write(2)) scan for a deadlock prior to sleeping on a locked resource. Deadlock
is not checked for the wait() and pause() system calls (see wait(2) and pause(2)), so potential for
deadlock is not eliminated. A creat() call or an open() call with the O_CREATE and O_TRUNC flags
set on a regular file returns error EAGAIN if another process has locked part of the file and the file is
currently in enforcement mode.
NETWORKING FEATURES
NFS
The advisory record-locking capabilitiesof lockf() are implemented throughout the network by the ‘‘net-
work lock daemon (see lockd(1M)). If the file server crashes and is rebooted, the lock daemon attempts to
recover all locks associated with the crashed server. If a lock cannot be reclaimed, the process that held
the lock is issued a SIGLOST signal.
Only advisory record locking is implemented for NFS files.
RETURN VALUE
Upon successful completion, a value of 0 is returned. Otherwise, a value of
1 is returned and errno is
set to indicate the error.
ERRORS
lockf() fails if any of the following occur:
[EACCES] function is F_TLOCK or F_TEST and the region is already locked by another process.
[EBADF] fildes is not a valid, open file descriptor.
[EDEADLK] A deadlock would occur or the number of entries in the system lock table would
exceed a system-dependent maximum. HP-UX guarantees this value to be at least 50.
[EINTR] A signal was caught during the lockf() system call.
[EINVAL] Either function is not one of the functions specified above, or size plus current offset
produces a negative offset into the file.
[EINVAL] size plus current offset cannot be represented correctly by an object of size
off_t.
[ENOLCK] Either function is F_TLOCK or
F_LOCK and the file is an NFS file with access bits
set for enforcement mode, or the file is an NFS file and a system error occurred on the
remote node.
WARNINGS
Deadlock conditions may arise when either the
wait() or pause() system calls are used in conjunction
with enforced locking (see wait(2) and pause(2) for details).
When a file descriptor is closed, all locks on the file from the calling process are deleted, even if other file
descriptors for that file (obtained through dup() or open(), for example) still exist.
Unexpected results may occur in processes that use buffers in the user address space. The process may
later read or write data which is or was locked. The standard I/O package, stdio(3S), is the most common
source of unexpected buffering.
In a hostile environment, locking can be misused by holding key public resources locked. This is particu-
larly true with public read files that have enforcement enabled.
It is not recommended that the
PRIV_LOCKRDONLY
capability be used because it is provided for back-
ward compatibility only. This feature may be modified or dropped from future HP-UX releases.
Locks default to advisory mode unless the
setgid bit of the file permissions is set.
Section 2134 2 HP-UX Release 11i: December 2000
___
___