]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/execve.2
ffix
[thirdparty/man-pages.git] / man2 / execve.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\" and Copyright (c) 2006 Michael Kerrisk <mtk-manpages@gmx.net>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Modified by Michael Haardt <michael@moria.de>
27 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21 by Michael Chastain <mec@shell.portal.com>:
29 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1999-11-12 by Urs Thuermann <urs@isnogud.escape.de>
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net>
32 .\" 2006-09-04 Michael Kerrisk <mtk-manpages@gmx.net>
33 .\" Added list of process attributes that are not preserved on exec().
34 .\"
35 .TH EXECVE 2 2006-09-04 "Linux 2.6.17" "Linux Programmer's Manual"
36 .SH NAME
37 execve \- execute program
38 .SH SYNOPSIS
39 .B #include <unistd.h>
40 .sp
41 .BI "int execve(const char *" filename ", char *const " argv "[], "
42 .br
43 .BI " char *const " envp []);
44 .SH DESCRIPTION
45 \fBexecve\fP() executes the program pointed to by \fIfilename\fP.
46 \fIfilename\fP must be either a binary executable, or a script
47 starting with a line of the form "\fB#! \fIinterpreter \fR[arg]".
48 In the latter case, the interpreter must be a valid pathname for an
49 executable which is not itself a script, which will be invoked as
50 \fBinterpreter\fR [arg] \fIfilename\fR.
51
52 \fIargv\fP is an array of argument strings passed to the new program.
53 \fIenvp\fP is an array of strings, conventionally of the form
54 \fBkey=value\fR, which are passed as environment to the new
55 program. Both \fIargv\fP and \fIenvp\fP must be terminated by a null
56 pointer. The argument vector and environment can be accessed by the
57 called program's main function, when it is defined as \fBint main(int
58 argc, char *argv[], char *envp[])\fR.
59
60 \fBexecve\fP() does not return on success, and the text, data, bss, and
61 stack of the calling process are overwritten by that of the program
62 loaded.
63
64 If the current program is being ptraced, a \fBSIGTRAP\fP is sent to it
65 after a successful \fBexecve\fP().
66
67 If the set-user-ID bit is set on the program file pointed to by
68 \fIfilename\fP, and the calling process is not being ptraced,
69 then the effective user ID of the calling process is changed
70 to that of the owner of the program file.
71 Similarly, when the set-group-ID
72 bit of the program file is set the effective group ID of the calling
73 process is set to the group of the program file.
74
75 The effective user ID of the process is copied to the saved set-user-ID;
76 similarly, the effective group ID is copied to the saved set-group-ID.
77 This copying takes place after any effective ID changes that occur
78 because of the set-user-ID and set-group-ID permission bits.
79
80 If the executable is an a.out dynamically-linked
81 binary executable containing
82 shared-library stubs, the Linux dynamic linker
83 .BR ld.so (8)
84 is called at the start of execution to bring
85 needed shared libraries into memory
86 and link the executable with them.
87
88 If the executable is a dynamically-linked ELF executable, the
89 interpreter named in the PT_INTERP segment is used to load the needed
90 shared libraries. This interpreter is typically
91 \fI/lib/ld-linux.so.1\fR for binaries linked with the Linux libc
92 version 5, or \fI/lib/ld-linux.so.2\fR for binaries linked with the
93 GNU libc version 2.
94
95 All process attributes are preserved during an
96 .BR execve (),
97 except the following:
98 .IP * 4
99 File descriptors that are marked close-on-exec are closed
100 (see the description of
101 .BR FD_CLOEXEC
102 in
103 .BR fcntl (2)).
104 .\" FIXME add some statement about the effect on record locks (fcntl()).
105 .IP * 4
106 The set of pending signals is cleared
107 .RB ( sigpending (2)).
108 .IP * 4
109 The dispositions of any signals that are being caught are
110 reset to being ignored.
111 .IP * 4
112 Any alternate signal stack is not preserved
113 .RB ( sigaltstack (2)).
114 .IP * 4
115 Memory mappings are not preserved
116 .RB ( mmap (2)).
117 .IP * 4
118 Attached System V shared memory segments are detached
119 .RB ( shmat (2)).
120 .IP * 4
121 POSIX shared memory regions are unmapped
122 .RB ( shm_open (3)).
123 .IP * 4
124 Open POSIX message queue descriptors are closed
125 .RB ( mq_overview (7)).
126 .IP * 4
127 Any open POSIX named semaphores are closed
128 .RB ( sem_overview (7)).
129 .IP * 4
130 POSIX timers are not preserved
131 .RB ( timer_create (3)).
132 .IP * 4
133 Any open directory streams are closed
134 .RB ( opendir (3)).
135 .IP * 4
136 Memory locks are not preserved
137 .RB ( mlock (2),
138 .BR mlockall (2)).
139 .IP * 4
140 Exit handlers are not preserved
141 .RB ( atexit (3),
142 .BR on_exit (3)).
143 .PP
144 The process attributes in the preceding list are all specified
145 in POSIX.1-2001.
146 The following Linux-specific process attributes are also
147 not preserved during an
148 .BR execve ():
149 .IP * 4
150 The
151 .BR prctl (2)
152 .B PR_SET_DUMPABLE
153 flag is set,
154 unless a set-user-ID or set-group ID program is being executed,
155 in which case it is cleared.
156 .IP * 4
157 The
158 .BR prctl (2)
159 .B PR_SET_KEEPCAPS
160 flag is cleared.
161 .IP * 4
162 The process name, as set by
163 .BR prctl (2)
164 .BR PR_SET_NAME
165 (and displayed by
166 .IR "ps -o comm" ),
167 is reset to the name of the new executable file.
168 .IP * 4
169 The termination signal is reset to SIGCHLD
170 (see
171 .BR clone (2)).
172 .PP
173 Note the following further points:
174 .IP * 4
175 All threads other than calling thread are destroyed during an
176 .BR execve ().
177 Mutexes, condition variables, and other pthreads objects are not preserved.
178 .IP * 4
179 The equivalent of \fIsetlocale(LC_ALL, "C")\fP
180 is executed at program start-up.
181 .IP * 4
182 POSIX.1-2001 specifies that the dispositions of any signals that
183 are ignored or set to the default are left unchanged.
184 POSIX.1-2001 specifies one exception: if SIGCHLD is being ignored,
185 then an implementation may leave the disposition unchanged or
186 reset it to the default; Linux does the former.
187 .IP * 4
188 Any outstanding asynchronous I/O operations are cancelled
189 .RB ( aio_read (3),
190 .BR aio_write (3)).
191 .IP * 4
192 For the handling of capabilities during
193 .BR execve (2),
194 see
195 .BR capabilities (7).
196 .SH "RETURN VALUE"
197 On success, \fBexecve\fP() does not return, on error \-1 is returned, and
198 .I errno
199 is set appropriately.
200 .SH ERRORS
201 .TP
202 .B E2BIG
203 The total number of bytes in the environment
204 .RI ( envp )
205 and argument list
206 .RI ( argv )
207 is too large.
208 .TP
209 .B EACCES
210 Search permission is denied on a component of the path prefix of
211 .I filename
212 or the name of a script interpreter.
213 (See also
214 .BR path_resolution (2).)
215 .TP
216 .B EACCES
217 The file or a script interpreter is not a regular file.
218 .TP
219 .B EACCES
220 Execute permission is denied for the file or a script or ELF interpreter.
221 .TP
222 .B EACCES
223 The file system is mounted
224 .IR noexec .
225 .TP
226 .B EFAULT
227 .I filename
228 points outside your accessible address space.
229 .TP
230 .B EINVAL
231 An ELF executable had more than one PT_INTERP segment (i.e., tried to
232 name more than one interpreter).
233 .TP
234 .B EIO
235 An I/O error occurred.
236 .TP
237 .B EISDIR
238 An ELF interpreter was a directory.
239 .TP
240 .B ELIBBAD
241 An ELF interpreter was not in a recognised format.
242 .TP
243 .B ELOOP
244 Too many symbolic links were encountered in resolving
245 .I filename
246 or the name of a script or ELF interpreter.
247 .TP
248 .B EMFILE
249 The process has the maximum number of files open.
250 .TP
251 .B ENAMETOOLONG
252 .I filename
253 is too long.
254 .TP
255 .B ENFILE
256 The system limit on the total number of open files has been reached.
257 .TP
258 .B ENOENT
259 The file
260 .I filename
261 or a script or ELF interpreter does not exist, or a shared library
262 needed for file or interpreter cannot be found.
263 .TP
264 .B ENOEXEC
265 An executable is not in a recognised format, is for the wrong
266 architecture, or has some other format error that means it cannot be
267 executed.
268 .TP
269 .B ENOMEM
270 Insufficient kernel memory was available.
271 .TP
272 .B ENOTDIR
273 A component of the path prefix of
274 .I filename
275 or a script or ELF interpreter is not a directory.
276 .TP
277 .B EPERM
278 The file system is mounted
279 .IR nosuid ,
280 the user is not the superuser,
281 and the file has the set-user-ID or set-group-ID bit set.
282 .TP
283 .B EPERM
284 The process is being traced, the user is not the superuser and the
285 file has the set-user-ID or set-group-ID bit set.
286 .TP
287 .B ETXTBSY
288 Executable was open for writing by one or more processes.
289 .SH "CONFORMING TO"
290 SVr4, 4.3BSD, POSIX.1-2001.
291 POSIX.1-2001 does not document the #! behavior
292 but is otherwise compatible.
293 .\" SVr4 documents additional error
294 .\" conditions EAGAIN, EINTR, ELIBACC, ENOLINK, EMULTIHOP; POSIX does not
295 .\" document ETXTBSY, EPERM, EFAULT, ELOOP, EIO, ENFILE, EMFILE, EINVAL,
296 .\" EISDIR or ELIBBAD error conditions.
297 .SH NOTES
298 Set-user-ID and set-group-ID processes can not be \fBptrace\fP()d.
299
300 Linux ignores the set-user-ID and set-group-ID bits on scripts.
301
302 The result of mounting a filesystem
303 .I nosuid
304 vary between Linux kernel versions:
305 some will refuse execution of set-user-ID and set-group-ID
306 executables when this would
307 give the user powers she did not have already (and return EPERM),
308 some will just ignore the set-user-ID and set-group-ID bits and
309 .BR exec ()
310 successfully.
311
312 A maximum line length of 127 characters is allowed for the first line in
313 a #! executable shell script.
314 .\" .SH BUGS
315 .\" Some Linux versions have failed to check permissions on ELF
316 .\" interpreters. This is a security hole, because it allows users to
317 .\" open any file, such as a rewinding tape device, for reading. Some
318 .\" Linux versions have also had other security holes in \fBexecve\fP(),
319 .\" that could be exploited for denial of service by a suitably crafted
320 .\" ELF binary. There are no known problems with 2.0.34 or 2.2.15.
321 .SH HISTORICAL
322 With Unix V6 the argument list of an
323 .BR exec ()
324 call was ended by 0,
325 while the argument list of
326 .I main
327 was ended by \-1. Thus, this
328 argument list was not directly usable in a further
329 .BR exec ()
330 call.
331 Since Unix V7 both are NULL.
332 .SH "SEE ALSO"
333 .BR chmod (2),
334 .BR fork (2),
335 .BR path_resolution (2),
336 .BR ptrace (2),
337 .BR execl (3),
338 .BR fexecve (3),
339 .BR environ (7),
340 .BR ld.so (8)