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