summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys/fcntl.2
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/sys/fcntl.2')
-rw-r--r--lib/libc/sys/fcntl.281
1 files changed, 59 insertions, 22 deletions
diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2
index f53c02f..877e830 100644
--- a/lib/libc/sys/fcntl.2
+++ b/lib/libc/sys/fcntl.2
@@ -70,7 +70,7 @@ share the same file status flags).
.It
The close-on-exec flag associated with the new file descriptor
is set to remain open across
-.Xr execv 2
+.Xr execve 2
system calls.
.El
.It Dv F_GETFD
@@ -128,9 +128,9 @@ flags are as follows:
.Bl -tag -width O_NONBLOCKX
.It Dv O_NONBLOCK
Non-blocking I/O; if no data is available to a
-.Xr read
+.Xr read 2
call, or if a
-.Xr write
+.Xr write 2
operation would block,
the read or write call returns -1 with the error
.Er EAGAIN .
@@ -170,7 +170,7 @@ taken as a pointer to a
.Fa "struct flock"
(see above).
The information retrieved overwrites the information passed to
-.Nm fcntl
+.Fn fcntl
in the
.Fa flock
structure.
@@ -193,18 +193,18 @@ or exclusive (or write) locks,
as well as remove either type of lock
.Dv (F_UNLCK) .
If a shared or exclusive lock cannot be set,
-.Nm fcntl
+.Fn fcntl
returns immediately with
-.Er EACCES .
+.Er EAGAIN .
.It Dv F_SETLKW
This command is the same as
.Dv F_SETLK
except that if a shared or exclusive lock is blocked by other locks,
the process waits until the request can be satisfied.
If a signal that is to be caught is received while
-.Nm fcntl
+.Fn fcntl
is waiting for a region, the
-.Nm fcntl
+.Fn fcntl
will be interrupted if the signal handler has not specified the
.Dv SA_RESTART
(see
@@ -290,15 +290,17 @@ locks conflicts with the type specified in the request.
This interface follows the completely stupid semantics of System V and
.St -p1003.1-88
that require that all locks associated with a file for a given process are
-removed when \fIany\fP file descriptor for that file is closed by that process.
+removed when
+.Em any
+file descriptor for that file is closed by that process.
This semantic means that applications must be aware of any files that
a subroutine library may access.
For example if an application for updating the password file locks the
password file database while making the update, and then calls
-.Xr getpwname 3
+.Xr getpwnam 3
to retrieve a record,
the lock will be lost because
-.Xr getpwname 3
+.Xr getpwnam 3
opens, reads, and closes the password database.
The database close will release all locks that the process has
associated with the database, even if the library routine never
@@ -330,6 +332,29 @@ This implementation detects that sleeping until a locked region is unlocked
would cause a deadlock and fails with an
.Er EDEADLK
error.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn fcntl
+is implemented as the
+.Va fcntl
+syscall.
+.Pp
+In the threaded library, the
+.Va fcntl
+syscall is assembled to
+.Fn _thread_sys_fcntl
+and
+.Fn fcntl
+is implemented as a function which disables thread rescheduling, locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_fcntl .
+Before returning,
+.Fn fcntl
+unlocks
+.Va fd
+and enables thread rescheduling.
.Sh RETURN VALUES
Upon successful completion, the value returned depends on
.Fa cmd
@@ -354,9 +379,9 @@ is set to indicate the error.
.Fn Fcntl
will fail if:
.Bl -tag -width Er
-.It Bq Er EACCES
+.It Bq Er EAGAIN
The argument
-.Fa arg
+.Fa cmd
is
.Dv F_SETLK ,
the type of lock
@@ -401,12 +426,6 @@ is an exclusive lock
and
.Fa fildes
is not a valid file descriptor open for writing.
-.It Bq Er EMFILE
-.Fa Cmd
-is
-.Dv F_DUPFD
-and the maximum allowed number of file descriptors are currently
-open.
.It Bq Er EDEADLK
The argument
.Fa cmd
@@ -445,7 +464,7 @@ refers to a file that does not support locking.
The argument
.Fa cmd
is
-.Dv F_DUPED
+.Dv F_DUPFD
and the maximum number of file descriptors permitted for the
process are already in use,
or no file descriptors greater than or equal to
@@ -467,15 +486,33 @@ is
and
the process ID given as argument is not in use.
.El
+.Pp
+In addition, if
+.Fa fd
+refers to a descriptor open on a terminal device (as opposed to a
+descriptor open on a socket), a
+.Fa cmd
+of
+.Dv F_SETOWN
+can fail for the same reasons as in
+.Xr tcsetpgrp 3 ,
+and a
+.Fa cmd
+of
+.Dv F_GETOWN
+for the reasons as stated in
+.Xr tcgetpgrp 3 .
.Sh SEE ALSO
.Xr close 2 ,
.Xr execve 2 ,
.Xr flock 2 ,
.Xr getdtablesize 2 ,
.Xr open 2 ,
-.Xr sigvec 2
+.Xr sigvec 2 ,
+.Xr tcgetpgrp 3 ,
+.Xr tcsetpgrp 3
.Sh HISTORY
The
-.Nm
+.Fn fcntl
function call appeared in
.Bx 4.2 .
OpenPOWER on IntegriCloud