]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/execveat.2
sched_setattr.2: tfix
[thirdparty/man-pages.git] / man2 / execveat.2
CommitLineData
20889818
MK
1.\" Copyright (c) 2014 Google, Inc., written by David Drysdale
2.\" and Copyright (c) 2015, Michael Kerrisk <mtk.manpages@gmail.com>
53652782
DD
3.\"
4.\" %%%LICENSE_START(VERBATIM)
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
24.\" %%%LICENSE_END
25.\"
4b8c67d9 26.TH EXECVEAT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
53652782
DD
27.SH NAME
28execveat \- execute program relative to a directory file descriptor
29.SH SYNOPSIS
30.B #include <unistd.h>
68e4db0a 31.PP
2dd8ff89 32.BI "int execveat(int " dirfd ", const char *" pathname ","
53652782 33.br
2dd8ff89 34.BI " char *const " argv "[], char *const " envp "[],"
53652782 35.br
2dd8ff89 36.BI " int " flags );
53652782 37.SH DESCRIPTION
2dd8ff89 38.\" commit 51f39a1f0cea1cacf8c787f652f26dfee9611874
53652782
DD
39The
40.BR execveat ()
2dd8ff89
MK
41system call executes the program referred to by the combination of
42.I dirfd
43and
44.IR pathname .
45It operates in exactly the same way as
53652782
DD
46.BR execve (2),
47except for the differences described in this manual page.
efeece04 48.PP
53652782
DD
49If the pathname given in
50.I pathname
51is relative, then it is interpreted relative to the directory
52referred to by the file descriptor
2dd8ff89 53.I dirfd
53652782
DD
54(rather than relative to the current working directory of
55the calling process, as is done by
56.BR execve (2)
57for a relative pathname).
efeece04 58.PP
53652782
DD
59If
60.I pathname
61is relative and
2dd8ff89 62.I dirfd
53652782
DD
63is the special value
64.BR AT_FDCWD ,
65then
66.I pathname
67is interpreted relative to the current working
68directory of the calling process (like
69.BR execve (2)).
efeece04 70.PP
53652782
DD
71If
72.I pathname
73is absolute, then
2dd8ff89 74.I dirfd
53652782 75is ignored.
efeece04 76.PP
53652782
DD
77If
78.I pathname
79is an empty string and the
80.BR AT_EMPTY_PATH
81flag is specified, then the file descriptor
2dd8ff89
MK
82.I dirfd
83specifies the file to be executed (i.e.,
84.IR dirfd
85refers to an executable file, rather than a directory).
efeece04 86.PP
2dd8ff89 87The
53652782 88.I flags
2dd8ff89 89argument is a bit mask that can include zero or more of the following flags:
53652782
DD
90.TP
91.BR AT_EMPTY_PATH
92If
93.I pathname
94is an empty string, operate on the file referred to by
2dd8ff89 95.IR dirfd
53652782
DD
96(which may have been obtained using the
97.BR open (2)
98.B O_PATH
99flag).
100.TP
101.B AT_SYMLINK_NOFOLLOW
102If the file identified by
2dd8ff89 103.I dirfd
53652782
DD
104and a non-NULL
105.I pathname
106is a symbolic link, then the call fails with the error
b1724c3d 107.BR ELOOP .
d282bb24 108.SH RETURN VALUE
53652782
DD
109On success,
110.BR execveat ()
2dd8ff89
MK
111does not return.
112On error, \-1 is returned, and
53652782
DD
113.I errno
114is set appropriately.
115.SH ERRORS
116The same errors that occur for
117.BR execve (2)
118can also occur for
119.BR execveat ().
120The following additional errors can occur for
121.BR execveat ():
122.TP
123.B EBADF
2dd8ff89 124.I dirfd
53652782
DD
125is not a valid file descriptor.
126.TP
53652782 127.B EINVAL
b1724c3d
MK
128Invalid flag specified in
129.IR flags .
130.TP
131.B ELOOP
b36bbd10
MK
132.I flags
133includes
134.BR AT_SYMLINK_NOFOLLOW
135and the file identified by
136.I dirfd
137and a non-NULL
138.I pathname
139is a symbolic link.
140.TP
2dd8ff89
MK
141.B ENOENT
142The program identified by
143.I dirfd
144and
145.I pathname
146requires the use of an interpreter program
147(such as a script starting with "#!"), but the file descriptor
148.I dirfd
149was opened with the
150.B O_CLOEXEC
151flag, with the result that
152the program file is inaccessible to the launched interpreter.
7ef75421 153See BUGS.
2dd8ff89 154.TP
53652782
DD
155.B ENOTDIR
156.I pathname
157is relative and
2dd8ff89 158.I dirfd
53652782
DD
159is a file descriptor referring to a file other than a directory.
160.SH VERSIONS
161.BR execveat ()
2dd8ff89 162was added to Linux in kernel 3.19.
c40eae38
MK
163GNU C library support is pending.
164.\" FIXME . check for glibc support in a future release
bc9f7981
MK
165.SH CONFORMING TO
166The
167.BR execveat ()
168system call is Linux-specific.
53652782
DD
169.SH NOTES
170In addition to the reasons explained in
171.BR openat (2),
172the
173.BR execveat ()
174system call is also needed to allow
175.BR fexecve (3)
176to be implemented on systems that do not have the
177.I /proc
178filesystem mounted.
efeece04 179.PP
18650061
MK
180When asked to execute a script file, the
181.IR argv[0]
182that is passed to the script interpreter is a string of the form
183.IR /dev/fd/N
184or
185.IR /dev/fd/N/P ,
186where
187.I N
188is the number of the file descriptor passed via the
189.IR dirfd
190argument.
191A string of the first form occurs when
192.BR AT_EMPTY_PATH
193is employed.
194A string of the second form occurs when the script is specified via both
195.IR dirfd
196and
197.IR pathname ;
198in this case,
199.IR P
200is the value given in
201.IR pathname .
efeece04 202.PP
f946944d
MK
203For the same reasons described in
204.BR fexecve (3),
205the natural idiom when using
bf7bc8b8 206.BR execveat ()
f946944d
MK
207is to set the close-on-exec flag on
208.IR dirfd .
209(But see BUGS.)
7ef75421
MK
210.SH BUGS
211The
212.B ENOENT
213error described above means that it is not possible to set the
214close-on-exec flag on the file descriptor given to a call of the form:
efeece04 215.PP
7ef75421 216 execveat(fd, "", argv, envp, AT_EMPTY_PATH);
efeece04 217.PP
7ef75421
MK
218However, the inability to set the close-on-exec flag means that a file
219descriptor referring to the script leaks through to the script itself.
220As well as wasting a file descriptor,
221this leakage can lead to file-descriptor exhaustion in scenarios
222where scripts recursively employ
9ee7f40f 223.BR execveat ().
7ef75421
MK
224.\" For an example, see Michael Kerrisk's 2015-01-10 reply in this LKML
225.\" thread (http://thread.gmane.org/gmane.linux.kernel/1836105/focus=20229):
226.\"
9ee7f40f 227.\" Subject: [PATCHv10 man-pages 5/5] execveat.2: initial man page.\" for execveat(2
7ef75421 228.\" Date: Mon, 24 Nov 2014 11:53:59 +0000
53652782
DD
229.SH SEE ALSO
230.BR execve (2),
2dd8ff89 231.BR openat (2),
53652782 232.BR fexecve (3)