summaryrefslogtreecommitdiff
path: root/lib/libc/sys/close.2
diff options
context:
space:
mode:
authorJared Yanovich <jaredy@cvs.openbsd.org>2005-08-10 01:25:52 +0000
committerJared Yanovich <jaredy@cvs.openbsd.org>2005-08-10 01:25:52 +0000
commitb8127b3c3d0b0c4d9d9db5b2ef392833ae30d6f2 (patch)
tree73e89c8c0b68ab75ebc9ac517241d8021c7b5a6c /lib/libc/sys/close.2
parent4e4b6ed7029cc96cdfc9b2fc7c8ead67078c26f5 (diff)
- macros, punctuation, wording, and rewording
- fix issue from -r 1.5 about a reference to flock(2) being moved to the wrong place - use FD_CLOEXEC instead of 1 to fcntl() - refer to formal parameters consistently ok jmc
Diffstat (limited to 'lib/libc/sys/close.2')
-rw-r--r--lib/libc/sys/close.238
1 files changed, 21 insertions, 17 deletions
diff --git a/lib/libc/sys/close.2 b/lib/libc/sys/close.2
index c6811b34015..d136f39cd7b 100644
--- a/lib/libc/sys/close.2
+++ b/lib/libc/sys/close.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: close.2,v 1.11 2004/01/14 09:30:19 tedu Exp $
+.\" $OpenBSD: close.2,v 1.12 2005/08/10 01:25:51 jaredy Exp $
.\" $NetBSD: close.2,v 1.5 1995/02/27 12:32:14 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993, 1994
@@ -47,15 +47,16 @@ call deletes a descriptor from the per-process object
reference table.
If this is the last reference to the underlying object, the
object will be deactivated.
-For example, on the last close of a file
+For example, on the last close of a file,
the current
.Em seek
pointer associated with the file is lost;
on the last close of a
-.Xr socket 2
+.Xr socket 2 ,
associated naming information and queued data are discarded;
-on the last close of a file holding an advisory lock
-the lock is released.
+and on the last close of a file holding an advisory lock,
+the lock is released (see further
+.Xr flock 2 ) .
However, the semantics of System V and
.St -p1003.1-88
dictate that all
@@ -63,13 +64,11 @@ dictate that all
advisory record locks associated with a file for a given process
are removed when
.Em any
-file descriptor for that file is closed by that process (see
-further
-.Xr flock 2 ) .
+file descriptor for that file is closed by that process.
.Pp
When a process exits,
all associated file descriptors are freed, but since there is
-a limit on active descriptors per processes, the
+a limit on active descriptors per process, the
.Fn close
function call
is useful when a large quantity of file descriptors are being handled.
@@ -78,7 +77,7 @@ When a process forks (see
.Xr fork 2 ) ,
all descriptors for the new child process reference the same
objects as they did in the parent before the fork.
-If a new process is then to be run using
+If a new process image is to then be run using
.Xr execve 2 ,
the process would normally inherit these descriptors.
Most of the descriptors can be rearranged with
@@ -87,15 +86,20 @@ or deleted with
.Fn close
before the
.Xr execve 2
-is attempted, but if some of these descriptors will still
-be needed if the execve fails, it is necessary to arrange for them
-to be closed if the execve succeeds.
+is attempted, but since some of these descriptors may still
+be needed should the
+.Xr execve 2
+fail, it is necessary to arrange for them
+to be closed when the
+.Xr execve 2
+succeeds.
For this reason, the call
-.Dq Li fcntl(d, F_SETFD, 1)
+.Fn fcntl d F_SETFD FD_CLOEXEC
is provided,
which arranges that a descriptor will be closed after a successful
-execve; the call
-.Dq Li fcntl(d, F_SETFD, 0)
+.Xr execve 2 ;
+the call
+.Fn fcntl d F_SETFD 0
restores the default,
which is to not close the descriptor.
.Sh RETURN VALUES
@@ -108,7 +112,7 @@ is set to indicate the error.
will fail if:
.Bl -tag -width Er
.It Bq Er EBADF
-.Fa D
+.Fa d
is not an active descriptor.
.It Bq Er EINTR
An interrupt was received.