]>
Commit | Line | Data |
---|---|---|
5b2abdfb A |
1 | .\" Copyright (c) 1991, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
5b2abdfb A |
12 | .\" 4. Neither the name of the University nor the names of its contributors |
13 | .\" may be used to endorse or promote products derived from this software | |
14 | .\" without specific prior written permission. | |
15 | .\" | |
16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | .\" SUCH DAMAGE. | |
27 | .\" | |
28 | .\" @(#)exec.3 8.3 (Berkeley) 1/24/94 | |
1f2f436a | 29 | .\" $FreeBSD: src/lib/libc/gen/exec.3,v 1.28 2008/06/23 05:22:06 ed Exp $ |
5b2abdfb A |
30 | .\" |
31 | .Dd January 24, 1994 | |
32 | .Dt EXEC 3 | |
33 | .Os | |
34 | .Sh NAME | |
35 | .Nm execl , | |
5b2abdfb | 36 | .Nm execle , |
ad3c9f2a | 37 | .Nm execlp , |
5b2abdfb | 38 | .Nm execv , |
3d9156a7 A |
39 | .Nm execvp , |
40 | .Nm execvP | |
5b2abdfb A |
41 | .Nd execute a file |
42 | .Sh LIBRARY | |
43 | .Lb libc | |
44 | .Sh SYNOPSIS | |
45 | .In unistd.h | |
46 | .Vt extern char **environ ; | |
47 | .Ft int | |
ad3c9f2a A |
48 | .Fo execl |
49 | .Fa "const char *path" | |
50 | .Fa "const char *arg0" | |
51 | .Fa ... /* "(char *)0" */ | |
52 | .Fc | |
5b2abdfb | 53 | .Ft int |
3d9156a7 | 54 | .Fo execle |
ad3c9f2a A |
55 | .Fa "const char *path" |
56 | .Fa "const char *arg0" | |
57 | .Fa ... | |
3d9156a7 A |
58 | .Fa /* |
59 | .Bk -words | |
60 | .Fa "(char *)0" "char *const envp[]" */ | |
61 | .Ek | |
62 | .Fc | |
5b2abdfb | 63 | .Ft int |
ad3c9f2a A |
64 | .Fo execlp |
65 | .Fa "const char *file" | |
66 | .Fa "const char *arg0" | |
67 | .Fa ... /* "(char *)0" */ | |
68 | .Fc | |
5b2abdfb | 69 | .Ft int |
ad3c9f2a A |
70 | .Fo execv |
71 | .Fa "const char *path" | |
72 | .Fa "char *const argv[]" | |
73 | .Fc | |
5b2abdfb | 74 | .Ft int |
ad3c9f2a A |
75 | .Fo execvp |
76 | .Fa "const char *file" | |
77 | .Fa "char *const argv[]" | |
78 | .Fc | |
3d9156a7 | 79 | .Ft int |
ad3c9f2a A |
80 | .Fo execvP |
81 | .Fa "const char *file" | |
82 | .Fa "const char *search_path" | |
83 | .Fa "char *const argv[]" | |
84 | .Fc | |
5b2abdfb A |
85 | .Sh DESCRIPTION |
86 | The | |
87 | .Nm exec | |
88 | family of functions replaces the current process image with a | |
89 | new process image. | |
90 | The functions described in this manual page are front-ends for the function | |
91 | .Xr execve 2 . | |
92 | (See the manual page for | |
93 | .Xr execve 2 | |
94 | for detailed information about the replacement of the current process.) | |
95 | .Pp | |
96 | The initial argument for these functions is the pathname of a file which | |
97 | is to be executed. | |
98 | .Pp | |
99 | The | |
ad3c9f2a | 100 | .Fa "const char *arg0" |
5b2abdfb A |
101 | and subsequent ellipses in the |
102 | .Fn execl , | |
103 | .Fn execlp , | |
104 | and | |
105 | .Fn execle | |
106 | functions can be thought of as | |
107 | .Em arg0 , | |
108 | .Em arg1 , | |
109 | \&..., | |
110 | .Em argn . | |
111 | Together they describe a list of one or more pointers to null-terminated | |
112 | strings that represent the argument list available to the executed program. | |
113 | The first argument, by convention, should point to the file name associated | |
114 | with the file being executed. | |
115 | The list of arguments | |
116 | .Em must | |
117 | be terminated by a | |
118 | .Dv NULL | |
119 | pointer. | |
120 | .Pp | |
121 | The | |
5b2abdfb | 122 | .Fn execv , |
3d9156a7 | 123 | .Fn execvp , |
5b2abdfb | 124 | and |
3d9156a7 | 125 | .Fn execvP |
5b2abdfb A |
126 | functions provide an array of pointers to null-terminated strings that |
127 | represent the argument list available to the new program. | |
128 | The first argument, by convention, should point to the file name associated | |
129 | with the file being executed. | |
130 | The array of pointers | |
131 | .Sy must | |
132 | be terminated by a | |
133 | .Dv NULL | |
134 | pointer. | |
135 | .Pp | |
136 | The | |
137 | .Fn execle | |
ad3c9f2a A |
138 | function also specifies the environment of the executed process |
139 | by following the | |
5b2abdfb | 140 | .Dv NULL |
9385eb3d A |
141 | pointer that terminates the list of arguments in the argument list |
142 | or the pointer to the argv array with an additional argument. | |
143 | This additional argument is an array of pointers to null-terminated strings | |
5b2abdfb A |
144 | and |
145 | .Em must | |
146 | be terminated by a | |
147 | .Dv NULL | |
148 | pointer. | |
149 | The other functions take the environment for the new process image from the | |
150 | external variable | |
151 | .Va environ | |
152 | in the current process. | |
153 | .Pp | |
154 | Some of these functions have special semantics. | |
155 | .Pp | |
156 | The functions | |
3d9156a7 A |
157 | .Fn execlp , |
158 | .Fn execvp , | |
5b2abdfb | 159 | and |
3d9156a7 | 160 | .Fn execvP |
5b2abdfb A |
161 | will duplicate the actions of the shell in searching for an executable file |
162 | if the specified file name does not contain a slash | |
163 | .Dq Li / | |
164 | character. | |
3d9156a7 A |
165 | For |
166 | .Fn execlp | |
167 | and | |
168 | .Fn execvp , | |
169 | search path is the path specified in the environment by | |
5b2abdfb A |
170 | .Dq Ev PATH |
171 | variable. | |
1f2f436a | 172 | If this variable is not specified, |
5b2abdfb A |
173 | the default path is set according to the |
174 | .Dv _PATH_DEFPATH | |
175 | definition in | |
3d9156a7 | 176 | .In paths.h , |
5b2abdfb A |
177 | which is set to |
178 | .Dq Ev /usr/bin:/bin . | |
3d9156a7 A |
179 | For |
180 | .Fn execvP , | |
181 | the search path is specified as an argument to the function. | |
5b2abdfb A |
182 | In addition, certain errors are treated specially. |
183 | .Pp | |
184 | If an error is ambiguous (for simplicity, we shall consider all | |
185 | errors except | |
186 | .Er ENOEXEC | |
187 | as being ambiguous here, although only the critical error | |
188 | .Er EACCES | |
189 | is really ambiguous), | |
190 | then these functions will act as if they stat the file to determine | |
191 | whether the file exists and has suitable execute permissions. | |
192 | If it does, they will return immediately with the global variable | |
193 | .Va errno | |
194 | restored to the value set by | |
195 | .Fn execve . | |
196 | Otherwise, the search will be continued. | |
197 | If the search completes without performing a successful | |
198 | .Fn execve | |
199 | or terminating due to an error, | |
200 | these functions will return with the global variable | |
201 | .Va errno | |
202 | set to | |
203 | .Er EACCES | |
204 | or | |
205 | .Er ENOENT | |
206 | according to whether at least one file with suitable execute permissions | |
207 | was found. | |
208 | .Pp | |
1f2f436a | 209 | If the header of a file is not recognized (the attempted |
5b2abdfb A |
210 | .Fn execve |
211 | returned | |
212 | .Er ENOEXEC ) , | |
213 | these functions will execute the shell with the path of | |
214 | the file as its first argument. | |
215 | (If this attempt fails, no further searching is done.) | |
5b2abdfb A |
216 | .Sh RETURN VALUES |
217 | If any of the | |
218 | .Fn exec | |
219 | functions returns, an error will have occurred. | |
220 | The return value is \-1, and the global variable | |
221 | .Va errno | |
222 | will be set to indicate the error. | |
223 | .Sh FILES | |
224 | .Bl -tag -width /bin/sh -compact | |
225 | .It Pa /bin/sh | |
226 | The shell. | |
227 | .El | |
5b2abdfb A |
228 | .Sh COMPATIBILITY |
229 | Historically, the default path for the | |
230 | .Fn execlp | |
231 | and | |
232 | .Fn execvp | |
233 | functions was | |
234 | .Dq Pa :/bin:/usr/bin . | |
235 | This was changed to place the current directory last to enhance system | |
236 | security. | |
237 | .Pp | |
238 | The behavior of | |
239 | .Fn execlp | |
240 | and | |
241 | .Fn execvp | |
242 | when errors occur while attempting to execute the file is not quite historic | |
243 | practice, and has not traditionally been documented and is not specified | |
244 | by the | |
245 | .Tn POSIX | |
246 | standard. | |
247 | .Pp | |
248 | Traditionally, the functions | |
249 | .Fn execlp | |
250 | and | |
251 | .Fn execvp | |
252 | ignored all errors except for the ones described above and | |
253 | .Er ETXTBSY , | |
254 | upon which they retried after sleeping for several seconds, and | |
255 | .Er ENOMEM | |
256 | and | |
257 | .Er E2BIG , | |
258 | upon which they returned. | |
259 | They now return for | |
260 | .Er ETXTBSY , | |
261 | and determine existence and executability more carefully. | |
262 | In particular, | |
263 | .Er EACCES | |
264 | for inaccessible directories in the path prefix is no longer | |
265 | confused with | |
266 | .Er EACCES | |
267 | for files with unsuitable execute permissions. | |
268 | In | |
269 | .Bx 4.4 , | |
270 | they returned upon all errors except | |
271 | .Er EACCES , | |
272 | .Er ENOENT , | |
273 | .Er ENOEXEC | |
274 | and | |
275 | .Er ETXTBSY . | |
276 | This was inferior to the traditional error handling, | |
277 | since it breaks the ignoring of errors for path prefixes | |
278 | and only improves the handling of the unusual ambiguous error | |
279 | .Er EFAULT | |
280 | and the unusual error | |
281 | .Er EIO . | |
282 | The behaviour was changed to match the behaviour of | |
283 | .Xr sh 1 . | |
1f2f436a A |
284 | .Sh ERRORS |
285 | The | |
286 | .Fn execl , | |
287 | .Fn execle , | |
288 | .Fn execlp , | |
ad3c9f2a | 289 | .Fn execvp , |
1f2f436a A |
290 | and |
291 | .Fn execvP | |
292 | functions | |
293 | may fail and set | |
294 | .Va errno | |
295 | for any of the errors specified for the library functions | |
296 | .Xr execve 2 | |
297 | and | |
298 | .Xr malloc 3 . | |
299 | .Pp | |
300 | The | |
1f2f436a | 301 | .Fn execv |
ad3c9f2a | 302 | function may fail and set |
1f2f436a A |
303 | .Va errno |
304 | for any of the errors specified for the library function | |
305 | .Xr execve 2 . | |
306 | .Sh SEE ALSO | |
307 | .Xr sh 1 , | |
308 | .Xr execve 2 , | |
309 | .Xr fork 2 , | |
1f2f436a A |
310 | .Xr ptrace 2 , |
311 | .Xr environ 7 | |
5b2abdfb | 312 | .Sh STANDARDS |
9385eb3d A |
313 | The |
314 | .Fn execl , | |
5b2abdfb A |
315 | .Fn execv , |
316 | .Fn execle , | |
ad3c9f2a | 317 | .Fn execlp , |
5b2abdfb A |
318 | and |
319 | .Fn execvp | |
9385eb3d | 320 | functions |
5b2abdfb A |
321 | conform to |
322 | .St -p1003.1-88 . | |
3d9156a7 A |
323 | The |
324 | .Fn execvP | |
325 | function first appeared in | |
326 | .Fx 5.2 . |