mirror of https://github.com/mkerrisk/man-pages
Substantial rewrite of NOTES; minor changes elsewhere.
This commit is contained in:
parent
7fe3091da4
commit
64603adfb7
|
@ -28,8 +28,6 @@
|
||||||
openat \- open a file at a relative location
|
openat \- open a file at a relative location
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.nf
|
.nf
|
||||||
.B #include <sys/types.h>
|
|
||||||
.B #include <sys/stat.h>
|
|
||||||
.B #include <fcntl.h>
|
.B #include <fcntl.h>
|
||||||
.sp
|
.sp
|
||||||
.BI "int openat(int " dirfd ", const char *" pathname ", int " flags );
|
.BI "int openat(int " dirfd ", const char *" pathname ", int " flags );
|
||||||
|
@ -59,7 +57,9 @@ is relative and
|
||||||
.I dirfd
|
.I dirfd
|
||||||
is the special value
|
is the special value
|
||||||
.BR AT_FDCWD ,
|
.BR AT_FDCWD ,
|
||||||
then pathname is interpreted relative to the current working
|
then
|
||||||
|
.I pathname
|
||||||
|
is interpreted relative to the current working
|
||||||
directory of the calling process (like
|
directory of the calling process (like
|
||||||
.BR open (2)).
|
.BR open (2)).
|
||||||
|
|
||||||
|
@ -69,16 +69,17 @@ is absolute, then
|
||||||
.I dirfd
|
.I dirfd
|
||||||
is ignored.
|
is ignored.
|
||||||
.SH "RETURN VALUE"
|
.SH "RETURN VALUE"
|
||||||
|
On success,
|
||||||
.BR openat ()
|
.BR openat ()
|
||||||
returns a new file descriptor, or \-1 if an error occurred
|
returns a new file descriptor.
|
||||||
(in which case,
|
On error, \-1 is returned and
|
||||||
.I errno
|
.I errno
|
||||||
is set appropriately).
|
is set to indicate the error.
|
||||||
.SH ERRORS
|
.SH ERRORS
|
||||||
The same errors that occur for
|
The same errors that occur for
|
||||||
.BR open (2)
|
.BR open (2)
|
||||||
can also occur for
|
can also occur for
|
||||||
.BR openat (2).
|
.BR openat ().
|
||||||
The following additional errors can occur for
|
The following additional errors can occur for
|
||||||
.BR openat ():
|
.BR openat ():
|
||||||
.TP
|
.TP
|
||||||
|
@ -90,29 +91,46 @@ is not a valid file descriptor.
|
||||||
.I dirfd
|
.I dirfd
|
||||||
is a file descriptor referring to a file other than a directory.
|
is a file descriptor referring to a file other than a directory.
|
||||||
.SH NOTES
|
.SH NOTES
|
||||||
The
|
|
||||||
.BR openat ()
|
.BR openat ()
|
||||||
system call (and similar system calls suffixed "at")
|
and other similar system calls suffixed "at" are supported
|
||||||
provides functionality that can otherwise only be obtained
|
for two reasons.
|
||||||
less efficiently or at the risk of races in user applications.
|
|
||||||
It allows the implementation of a per-thread "current working
|
First,
|
||||||
|
.BR openat ()
|
||||||
|
allows an application to avoid race conditions that could
|
||||||
|
occur when using
|
||||||
|
.BR open (2)
|
||||||
|
to open files in directories other than the current working directory.
|
||||||
|
These race conditions result from the fact that some component
|
||||||
|
of the directory prefix given to
|
||||||
|
.BR open ()
|
||||||
|
could be changed in parallel with the call to
|
||||||
|
.BR open ().
|
||||||
|
Such races can be avoided by
|
||||||
|
opening a file descriptor for the target directory,
|
||||||
|
and then specifying that file descriptor as the
|
||||||
|
.I dirfd
|
||||||
|
argument of
|
||||||
|
.BR openat ().
|
||||||
|
|
||||||
|
Second,
|
||||||
|
.BR openat ()
|
||||||
|
allows the implementation of a per-thread "current working
|
||||||
directory", via file descriptor(s) maintained by the application.
|
directory", via file descriptor(s) maintained by the application.
|
||||||
(This functionality can also be obtained by tricks based
|
(This functionality can also be obtained by tricks based
|
||||||
on the use of
|
on the use of
|
||||||
.IR /proc/self/fd/ dirfd,
|
.IR /proc/self/fd/ dirfd,
|
||||||
but less efficiently.)
|
but less efficiently.)
|
||||||
It also allows the avoidance of various kinds of races that can occur
|
|
||||||
as a result of directory deletions that may occur while an application
|
|
||||||
is traversing a file system.
|
|
||||||
.SH "CONFORMING TO"
|
.SH "CONFORMING TO"
|
||||||
This system call is non-standard.
|
This system call is non-standard but is proposed
|
||||||
|
for inclusion in a future revision of POSIX.1.
|
||||||
A similar system call exists on Solaris.
|
A similar system call exists on Solaris.
|
||||||
.\" The 'at' suffix in Solaris is actually double sensed. It
|
.\" The 'at' suffix in Solaris is actually double sensed. It
|
||||||
.\" primarily referred to "extended *at*tributes", which are
|
.\" primarily referred to "extended *at*tributes", which are
|
||||||
.\" handled by Solaris' O_XATTR flag, but was also intended
|
.\" handled by Solaris' O_XATTR flag, but was also intended
|
||||||
.\" to refer to the notion of "at a relative location".
|
.\" to refer to the notion of "at a relative location".
|
||||||
.\"
|
.\"
|
||||||
.\" See also the following for a discussion of the inconsistent
|
.\" See the following for a discussion of the inconsistent
|
||||||
.\" naming of the *at() functions:
|
.\" naming of the *at() functions:
|
||||||
.\" http://www.opengroup.org/austin/mailarchives/ag/msg09103.html
|
.\" http://www.opengroup.org/austin/mailarchives/ag/msg09103.html
|
||||||
.\" Subject: RE: The naming of at()s is a difficult matter
|
.\" Subject: RE: The naming of at()s is a difficult matter
|
||||||
|
@ -123,5 +141,9 @@ A similar system call exists on Solaris.
|
||||||
.BR openat ()
|
.BR openat ()
|
||||||
was added to Linux in kernel 2.6.16.
|
was added to Linux in kernel 2.6.16.
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
|
.BR mkdirat (2),
|
||||||
|
.BR mknodat (2),
|
||||||
.BR open (2),
|
.BR open (2),
|
||||||
.BR path_resolution (2)
|
.BR path_resolution (2),
|
||||||
|
.BR mkfifoat (3).
|
||||||
|
.\" FIXME . eventually list other *at.2 pages here?
|
||||||
|
|
Loading…
Reference in New Issue