]>
Commit | Line | Data |
---|---|---|
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 |
27 | execveat \- 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 |
38 | The |
39 | .BR execveat () | |
2dd8ff89 MK |
40 | system call executes the program referred to by the combination of |
41 | .I dirfd | |
42 | and | |
43 | .IR pathname . | |
44 | It operates in exactly the same way as | |
53652782 DD |
45 | .BR execve (2), |
46 | except for the differences described in this manual page. | |
47 | ||
48 | If the pathname given in | |
49 | .I pathname | |
50 | is relative, then it is interpreted relative to the directory | |
51 | referred to by the file descriptor | |
2dd8ff89 | 52 | .I dirfd |
53652782 DD |
53 | (rather than relative to the current working directory of |
54 | the calling process, as is done by | |
55 | .BR execve (2) | |
56 | for a relative pathname). | |
57 | ||
58 | If | |
59 | .I pathname | |
60 | is relative and | |
2dd8ff89 | 61 | .I dirfd |
53652782 DD |
62 | is the special value |
63 | .BR AT_FDCWD , | |
64 | then | |
65 | .I pathname | |
66 | is interpreted relative to the current working | |
67 | directory of the calling process (like | |
68 | .BR execve (2)). | |
69 | ||
70 | If | |
71 | .I pathname | |
72 | is absolute, then | |
2dd8ff89 | 73 | .I dirfd |
53652782 DD |
74 | is ignored. |
75 | ||
76 | If | |
77 | .I pathname | |
78 | is an empty string and the | |
79 | .BR AT_EMPTY_PATH | |
80 | flag is specified, then the file descriptor | |
2dd8ff89 MK |
81 | .I dirfd |
82 | specifies the file to be executed (i.e., | |
83 | .IR dirfd | |
84 | refers to an executable file, rather than a directory). | |
53652782 | 85 | |
2dd8ff89 | 86 | The |
53652782 | 87 | .I flags |
2dd8ff89 | 88 | argument is a bit mask that can include zero or more of the following flags: |
53652782 DD |
89 | .TP |
90 | .BR AT_EMPTY_PATH | |
91 | If | |
92 | .I pathname | |
93 | is 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 | |
98 | flag). | |
99 | .TP | |
100 | .B AT_SYMLINK_NOFOLLOW | |
101 | If the file identified by | |
2dd8ff89 | 102 | .I dirfd |
53652782 DD |
103 | and a non-NULL |
104 | .I pathname | |
105 | is a symbolic link, then the call fails with the error | |
b1724c3d | 106 | .BR ELOOP . |
53652782 DD |
107 | .SH "RETURN VALUE" |
108 | On success, | |
109 | .BR execveat () | |
2dd8ff89 MK |
110 | does not return. |
111 | On error, \-1 is returned, and | |
53652782 DD |
112 | .I errno |
113 | is set appropriately. | |
114 | .SH ERRORS | |
115 | The same errors that occur for | |
116 | .BR execve (2) | |
117 | can also occur for | |
118 | .BR execveat (). | |
119 | The following additional errors can occur for | |
120 | .BR execveat (): | |
121 | .TP | |
122 | .B EBADF | |
2dd8ff89 | 123 | .I dirfd |
53652782 DD |
124 | is not a valid file descriptor. |
125 | .TP | |
53652782 | 126 | .B EINVAL |
b1724c3d MK |
127 | Invalid flag specified in |
128 | .IR flags . | |
129 | .TP | |
130 | .B ELOOP | |
b36bbd10 MK |
131 | .I flags |
132 | includes | |
133 | .BR AT_SYMLINK_NOFOLLOW | |
134 | and the file identified by | |
135 | .I dirfd | |
136 | and a non-NULL | |
137 | .I pathname | |
138 | is a symbolic link. | |
139 | .TP | |
2dd8ff89 MK |
140 | .B ENOENT |
141 | The program identified by | |
142 | .I dirfd | |
143 | and | |
144 | .I pathname | |
145 | requires the use of an interpreter program | |
146 | (such as a script starting with "#!"), but the file descriptor | |
147 | .I dirfd | |
148 | was opened with the | |
149 | .B O_CLOEXEC | |
150 | flag, with the result that | |
151 | the program file is inaccessible to the launched interpreter. | |
7ef75421 | 152 | See BUGS. |
2dd8ff89 | 153 | .TP |
53652782 DD |
154 | .B ENOTDIR |
155 | .I pathname | |
156 | is relative and | |
2dd8ff89 | 157 | .I dirfd |
53652782 DD |
158 | is a file descriptor referring to a file other than a directory. |
159 | .SH VERSIONS | |
160 | .BR execveat () | |
2dd8ff89 | 161 | was added to Linux in kernel 3.19. |
c40eae38 MK |
162 | GNU C library support is pending. |
163 | .\" FIXME . check for glibc support in a future release | |
bc9f7981 MK |
164 | .SH CONFORMING TO |
165 | The | |
166 | .BR execveat () | |
167 | system call is Linux-specific. | |
53652782 DD |
168 | .SH NOTES |
169 | In addition to the reasons explained in | |
170 | .BR openat (2), | |
171 | the | |
172 | .BR execveat () | |
173 | system call is also needed to allow | |
174 | .BR fexecve (3) | |
175 | to be implemented on systems that do not have the | |
176 | .I /proc | |
177 | filesystem mounted. | |
18650061 MK |
178 | |
179 | When asked to execute a script file, the | |
180 | .IR argv[0] | |
181 | that is passed to the script interpreter is a string of the form | |
182 | .IR /dev/fd/N | |
183 | or | |
184 | .IR /dev/fd/N/P , | |
185 | where | |
186 | .I N | |
187 | is the number of the file descriptor passed via the | |
188 | .IR dirfd | |
189 | argument. | |
190 | A string of the first form occurs when | |
191 | .BR AT_EMPTY_PATH | |
192 | is employed. | |
193 | A string of the second form occurs when the script is specified via both | |
194 | .IR dirfd | |
195 | and | |
196 | .IR pathname ; | |
197 | in this case, | |
198 | .IR P | |
199 | is the value given in | |
200 | .IR pathname . | |
f946944d MK |
201 | |
202 | For the same reasons described in | |
203 | .BR fexecve (3), | |
204 | the natural idiom when using | |
205 | .BR execveat (2) | |
206 | is to set the close-on-exec flag on | |
207 | .IR dirfd . | |
208 | (But see BUGS.) | |
7ef75421 MK |
209 | .SH BUGS |
210 | The | |
211 | .B ENOENT | |
212 | error described above means that it is not possible to set the | |
213 | close-on-exec flag on the file descriptor given to a call of the form: | |
214 | ||
215 | execveat(fd, "", argv, envp, AT_EMPTY_PATH); | |
216 | ||
217 | However, the inability to set the close-on-exec flag means that a file | |
218 | descriptor referring to the script leaks through to the script itself. | |
219 | As well as wasting a file descriptor, | |
220 | this leakage can lead to file-descriptor exhaustion in scenarios | |
221 | where 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) |