summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys/flock.2
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/sys/flock.2')
-rw-r--r--lib/libc/sys/flock.240
1 files changed, 33 insertions, 7 deletions
diff --git a/lib/libc/sys/flock.2 b/lib/libc/sys/flock.2
index bb6abb7..466e347 100644
--- a/lib/libc/sys/flock.2
+++ b/lib/libc/sys/flock.2
@@ -39,10 +39,10 @@
.Nd "apply or remove an advisory lock on an open file"
.Sh SYNOPSIS
.Fd #include <sys/file.h>
-.Fd #define LOCK_SH 1 /* shared lock */
-.Fd #define LOCK_EX 2 /* exclusive lock */
-.Fd #define LOCK_NB 4 /* don't block when locking */
-.Fd #define LOCK_UN 8 /* unlock */
+.Fd #define LOCK_SH 0x01 /* shared file lock */
+.Fd #define LOCK_EX 0x02 /* exclusive file lock */
+.Fd #define LOCK_NB 0x04 /* don't block when locking */
+.Fd #define LOCK_UN 0x08 /* unlock file */
.Ft int
.Fn flock "int fd" "int operation"
.Sh DESCRIPTION
@@ -109,6 +109,28 @@ forks and the child explicitly unlocks the file, the parent will
lose its lock.
.Pp
Processes blocked awaiting a lock may be awakened by signals.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn flock
+is implemented as the
+.Va flock
+syscall.
+.Pp
+In the threaded library, the
+.Va flock
+syscall is assembled to
+.Fn _thread_sys_flock
+and
+.Fn flock
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_flock .
+Before returning,
+.Fn flock
+unlocks
+.Va fd .
.Sh RETURN VALUES
Zero is returned if the operation was successful;
on an error a -1 is returned and an error code is left in
@@ -131,15 +153,19 @@ is an invalid descriptor.
The argument
.Fa fd
refers to an object other than a file.
+.It Bq Er EOPNOTSUPP
+The argument
+.Fa fd
+refers to an object that does not support file locking.
.El
.Sh SEE ALSO
-.Xr open 2 ,
.Xr close 2 ,
.Xr dup 2 ,
.Xr execve 2 ,
-.Xr fork 2
+.Xr fork 2 ,
+.Xr open 2
.Sh HISTORY
The
-.Nm
+.Fn flock
function call appeared in
.Bx 4.2 .
OpenPOWER on IntegriCloud