1 | .\" Copyright (c) 1980 Regents of the University of California.
|
---|
2 | .\" All rights reserved. The Berkeley software License Agreement
|
---|
3 | .\" specifies the terms and conditions for redistribution.
|
---|
4 | .\"
|
---|
5 | .\" @(#)execve.2 6.7 (Berkeley) 5/22/86
|
---|
6 | .\"
|
---|
7 | .TH EXECVE 2 "May 22, 1986"
|
---|
8 | .UC 4
|
---|
9 | .SH NAME
|
---|
10 | execve \- execute a file
|
---|
11 | .SH SYNOPSIS
|
---|
12 | .nf
|
---|
13 | .ft B
|
---|
14 | #include <unistd.h>
|
---|
15 |
|
---|
16 | int execve(const char *\fIname\fP, char *const \fIargv\fP[], char *const \fIenvp\fP[])
|
---|
17 | .ft R
|
---|
18 | .fi
|
---|
19 | .SH DESCRIPTION
|
---|
20 | .B Execve
|
---|
21 | transforms the calling process into a new process.
|
---|
22 | The new process is constructed from an ordinary file
|
---|
23 | called the \fInew process file\fP.
|
---|
24 | This file is either an executable object file,
|
---|
25 | or a file of data for an interpreter.
|
---|
26 | An executable object file consists of an identifying header,
|
---|
27 | followed by pages of data representing the initial program (text)
|
---|
28 | and initialized data pages. Additional pages may be specified
|
---|
29 | by the header to be initialized with zero data. See
|
---|
30 | .BR a.out (5).
|
---|
31 | .PP
|
---|
32 | An interpreter file begins with a line of the form ``#! \fIinterpreter\fP''.
|
---|
33 | When an interpreter file is
|
---|
34 | .BR execve\| 'd,
|
---|
35 | the system \fBexecve\fP\|'s the specified \fIinterpreter\fP, giving
|
---|
36 | it the name of the originally exec'd file as an argument and
|
---|
37 | shifting over the rest of the original arguments.
|
---|
38 | .PP
|
---|
39 | There can be no return from a successful \fBexecve\fP because the calling
|
---|
40 | core image is lost.
|
---|
41 | This is the mechanism whereby different process images become active.
|
---|
42 | .PP
|
---|
43 | The argument \fIargv\fP is a null-terminated array of character pointers
|
---|
44 | to null-terminated character strings. These strings constitute
|
---|
45 | the argument list to be made available to the new
|
---|
46 | process. By convention, at least one argument must be present in
|
---|
47 | this array, and the first element of this array should be
|
---|
48 | the name of the executed program (i.e., the last component of \fIname\fP).
|
---|
49 | .PP
|
---|
50 | The argument \fIenvp\fP is also a null-terminated array of character pointers
|
---|
51 | to null-terminated strings. These strings pass information to the
|
---|
52 | new process that is not directly an argument to the command (see
|
---|
53 | .BR environ (7)).
|
---|
54 | .PP
|
---|
55 | Descriptors open in the calling process remain open in
|
---|
56 | the new process, except for those for which the close-on-exec
|
---|
57 | flag is set (see
|
---|
58 | .BR close (2)).
|
---|
59 | Descriptors that remain open are unaffected by
|
---|
60 | .BR execve .
|
---|
61 | .PP
|
---|
62 | Ignored signals remain ignored across an
|
---|
63 | .BR execve ,
|
---|
64 | but signals that are caught are reset to their default values.
|
---|
65 | Blocked signals remain blocked regardless of changes to the signal action.
|
---|
66 | The signal stack is reset to be undefined (see
|
---|
67 | .BR sigaction (2)
|
---|
68 | for more information).
|
---|
69 | .PP
|
---|
70 | Each process has
|
---|
71 | .I real
|
---|
72 | user and group IDs and an
|
---|
73 | .I effective
|
---|
74 | user and group IDs. The
|
---|
75 | .I real
|
---|
76 | ID identifies the person using the system; the
|
---|
77 | .I effective
|
---|
78 | ID determines his access privileges.
|
---|
79 | .B Execve
|
---|
80 | changes the effective user and group ID to
|
---|
81 | the owner of the executed file if the file has the \*(lqset-user-ID\*(rq
|
---|
82 | or \*(lqset-group-ID\*(rq modes. The
|
---|
83 | .I real
|
---|
84 | user ID is not affected.
|
---|
85 | .PP
|
---|
86 | The new process also inherits the following attributes from
|
---|
87 | the calling process:
|
---|
88 | .PP
|
---|
89 | .in +5n
|
---|
90 | .nf
|
---|
91 | .ta +2i
|
---|
92 | process ID see \fBgetpid\fP\|(2)
|
---|
93 | parent process ID see \fBgetppid\fP\|(2)
|
---|
94 | process group ID see \fBgetpgrp\fP\|(2)
|
---|
95 | access groups see \fBgetgroups\fP\|(2)
|
---|
96 | working directory see \fBchdir\fP\|(2)
|
---|
97 | root directory see \fBchroot\fP\|(2)
|
---|
98 | control terminal see \fBtty\fP\|(4)
|
---|
99 | alarm timer see \fBalarm\fP\|(2)
|
---|
100 | file mode mask see \fBumask\fP\|(2)
|
---|
101 | signal mask see \fBsigaction\fP\|(2), \fBsigprocmask\fP\|(2)
|
---|
102 | .in -5n
|
---|
103 | .fi
|
---|
104 | .PP
|
---|
105 | When the executed program begins, it is called as follows:
|
---|
106 | .PP
|
---|
107 | .RS
|
---|
108 | .ft B
|
---|
109 | .nf
|
---|
110 | int main(int \fIargc\fP, char *const \fIargv\fP[], char *const \fIenvp\fP[]);
|
---|
111 |
|
---|
112 | exit(main(\fIargc\fP, \fIargv\fP, \fIenvp\fP));
|
---|
113 | .fi
|
---|
114 | .ft R
|
---|
115 | .RE
|
---|
116 | .PP
|
---|
117 | where
|
---|
118 | .I argc
|
---|
119 | is the number of elements in \fIargv\fP
|
---|
120 | (the ``arg count'')
|
---|
121 | and
|
---|
122 | .I argv
|
---|
123 | is the array of character pointers
|
---|
124 | to the arguments themselves.
|
---|
125 | .PP
|
---|
126 | .I Envp
|
---|
127 | is a pointer to an array of strings that constitute
|
---|
128 | the
|
---|
129 | .I environment
|
---|
130 | of the process.
|
---|
131 | A pointer to this array is also stored in the global variable ``environ''.
|
---|
132 | Each string consists of a name, an \*(lq=\*(rq, and a null-terminated value.
|
---|
133 | The array of pointers is terminated by a null pointer.
|
---|
134 | The shell
|
---|
135 | .BR sh (1)
|
---|
136 | passes an environment entry for each global shell variable
|
---|
137 | defined when the program is called.
|
---|
138 | See
|
---|
139 | .BR environ (7)
|
---|
140 | for some conventionally
|
---|
141 | used names.
|
---|
142 | .SH "RETURN VALUE
|
---|
143 | If
|
---|
144 | .B execve
|
---|
145 | returns to the calling process an error has occurred; the
|
---|
146 | return value will be \-1 and the global variable
|
---|
147 | .B errno
|
---|
148 | will contain an error code.
|
---|
149 | .SH ERRORS
|
---|
150 | .B Execve
|
---|
151 | will fail and return to the calling process if one or more
|
---|
152 | of the following are true:
|
---|
153 | .TP 15
|
---|
154 | [ENOTDIR]
|
---|
155 | A component of the path prefix is not a directory.
|
---|
156 | .TP 15
|
---|
157 | [ENAMETOOLONG]
|
---|
158 | The path name exceeds PATH_MAX characters.
|
---|
159 | .TP 15
|
---|
160 | [ENOENT]
|
---|
161 | The new process file does not exist.
|
---|
162 | .TP 15
|
---|
163 | [ELOOP]
|
---|
164 | Too many symbolic links were encountered in translating the pathname.
|
---|
165 | (Minix-vmd)
|
---|
166 | .TP 15
|
---|
167 | [EACCES]
|
---|
168 | Search permission is denied for a component of the path prefix.
|
---|
169 | .TP 15
|
---|
170 | [EACCES]
|
---|
171 | The new process file is not an ordinary file.
|
---|
172 | .TP 15
|
---|
173 | [EACCES]
|
---|
174 | The new process file mode denies execute permission.
|
---|
175 | .TP 15
|
---|
176 | [ENOEXEC]
|
---|
177 | The new process file has the appropriate access
|
---|
178 | permission, but has an invalid magic number in its header.
|
---|
179 | .TP 15
|
---|
180 | [ENOMEM]
|
---|
181 | The new process requires more (virtual) memory than
|
---|
182 | is currently available.
|
---|
183 | .TP 15
|
---|
184 | [E2BIG]
|
---|
185 | The number of bytes in the new process's argument list
|
---|
186 | is larger than the system-imposed limit ARG_MAX.
|
---|
187 | The limit in the system as released is 4096 bytes for
|
---|
188 | 16-bit MINIX 3, 16384 bytes for 32-bit Minix, and unlimited for Minix-vmd.
|
---|
189 | .TP 15
|
---|
190 | [EFAULT]
|
---|
191 | \fIPath\fP\|, \fIargv\fP\|, or \fIenvp\fP point
|
---|
192 | to an illegal address.
|
---|
193 | .TP 15
|
---|
194 | [EIO]
|
---|
195 | An I/O error occurred while reading from the file system.
|
---|
196 | .SH CAVEATS
|
---|
197 | If a program is
|
---|
198 | .I setuid
|
---|
199 | to a non-super-user, but is executed when
|
---|
200 | the real \fBuid\fP is ``root'', then the program has some of the powers
|
---|
201 | of a super-user as well.
|
---|
202 | .SH "SEE ALSO"
|
---|
203 | .BR exit (2),
|
---|
204 | .BR fork (2),
|
---|
205 | .BR execl (3),
|
---|
206 | .BR environ (7).
|
---|