1 .\" Copyright (c) 2014 Google, Inc., written by David Drysdale
2 .\" and Copyright (c) 2015, Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH EXECVEAT 2 2021-03-22 "Linux" "Linux Programmer's Manual"
28 execveat \- execute program relative to a directory file descriptor
31 .BR "#include <linux/fcntl.h>" " /* Definition of " AT_* " constants */"
32 .B #include <unistd.h>
34 .BI "int execveat(int " dirfd ", const char *" pathname ,
35 .BI " const char *const " argv "[], const char *const " envp [],
39 .\" commit 51f39a1f0cea1cacf8c787f652f26dfee9611874
42 system call executes the program referred to by the combination of
46 It operates in exactly the same way as
48 except for the differences described in this manual page.
50 If the pathname given in
52 is relative, then it is interpreted relative to the directory
53 referred to by the file descriptor
55 (rather than relative to the current working directory of
56 the calling process, as is done by
58 for a relative pathname).
68 is interpreted relative to the current working
69 directory of the calling process (like
80 is an empty string and the
82 flag is specified, then the file descriptor
84 specifies the file to be executed (i.e.,
86 refers to an executable file, rather than a directory).
90 argument is a bit mask that can include zero or more of the following flags:
95 is an empty string, operate on the file referred to by
97 (which may have been obtained using the
102 .B AT_SYMLINK_NOFOLLOW
103 If the file identified by
107 is a symbolic link, then the call fails with the error
113 On error, \-1 is returned, and
115 is set to indicate the error.
117 The same errors that occur for
121 The following additional errors can occur for
126 is not a valid file descriptor.
129 Invalid flag specified in
135 .BR AT_SYMLINK_NOFOLLOW
136 and the file identified by
143 The program identified by
147 requires the use of an interpreter program
148 (such as a script starting with "#!"), but the file descriptor
152 flag, with the result that
153 the program file is inaccessible to the launched interpreter.
160 is a file descriptor referring to a file other than a directory.
163 was added to Linux in kernel 3.19.
164 Library support was added to glibc in version 2.34.
168 system call is Linux-specific.
170 In addition to the reasons explained in
174 system call is also needed to allow
176 to be implemented on systems that do not have the
180 When asked to execute a script file, the
182 that is passed to the script interpreter is a string of the form
188 is the number of the file descriptor passed via the
191 A string of the first form occurs when
194 A string of the second form occurs when the script is specified via both
200 is the value given in
203 For the same reasons described in
205 the natural idiom when using
207 is to set the close-on-exec flag on
213 error described above means that it is not possible to set the
214 close-on-exec flag on the file descriptor given to a call of the form:
216 execveat(fd, "", argv, envp, AT_EMPTY_PATH);
218 However, the inability to set the close-on-exec flag means that a file
219 descriptor referring to the script leaks through to the script itself.
220 As well as wasting a file descriptor,
221 this leakage can lead to file-descriptor exhaustion in scenarios
222 where scripts recursively employ
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):
227 .\" Subject: [PATCHv10 man-pages 5/5] execveat.2: initial man page.\" for execveat(2
228 .\" Date: Mon, 24 Nov 2014 11:53:59 +0000