Files
oldlinux-files/Minix/2.0.0/wwwman/man2/execve.2.html
2024-02-19 00:21:39 -05:00

176 lines
8.2 KiB
HTML

<HTML>
<HEAD>
<TITLE>execve(2)</TITLE>
</HEAD>
<BODY>
<H1>execve(2)</H1>
<HR>
<PRE>
</PRE>
<H2>NAME</H2><PRE>
execve - execute a file
</PRE>
<H2>SYNOPSIS</H2><PRE>
<STRONG>#include</STRONG> <STRONG>&lt;unistd.h&gt;</STRONG>
<STRONG>int</STRONG> <STRONG>execve(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>name</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <EM>argv</EM><STRONG>[],</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <EM>envp</EM><STRONG>[])</STRONG>
</PRE>
<H2>DESCRIPTION</H2><PRE>
<STRONG>Execve</STRONG> transforms the calling process into a new process. The new
process is constructed from an ordinary file called the <EM>new</EM> <EM>process</EM> <EM>file</EM>.
This file is either an executable object file, or a file of data for an
interpreter. An executable object file consists of an identifying
header, followed by pages of data representing the initial program (text)
and initialized data pages. Additional pages may be specified by the
header to be initialized with zero data. See <STRONG><A HREF="../man5/a.out.5.html">a.out(5)</A></STRONG>.
An interpreter file begins with a line of the form ``#! <EM>interpreter</EM>''.
(Minix-vmd only.) When an interpreter file is <STRONG>execve</STRONG>'d, the system
<STRONG>execve</STRONG>'s the specified <EM>interpreter</EM>, giving it the name of the originally
exec'd file as an argument and shifting over the rest of the original
arguments.
There can be no return from a successful <STRONG>execve</STRONG> because the calling core
image is lost. This is the mechanism whereby different process images
become active.
The argument <EM>argv</EM> is a null-terminated array of character pointers to
null-terminated character strings. These strings constitute the argument
list to be made available to the new process. By convention, at least
one argument must be present in this array, and the first element of this
array should be the name of the executed program (i.e., the last
component of <EM>name</EM>).
The argument <EM>envp</EM> is also a null-terminated array of character pointers
to null-terminated strings. These strings pass information to the new
process that is not directly an argument to the command (see <STRONG><A HREF="../man7/environ.7.html">environ(7)</A></STRONG>).
Descriptors open in the calling process remain open in the new process,
except for those for which the close-on-exec flag is set (see <STRONG><A HREF="../man2/close.2.html">close(2)</A></STRONG>).
Descriptors that remain open are unaffected by <STRONG>execve</STRONG>.
Ignored signals remain ignored across an <STRONG>execve</STRONG>, but signals that are
caught are reset to their default values. Blocked signals remain blocked
regardless of changes to the signal action. The signal stack is reset to
be undefined (see <STRONG><A HREF="../man2/sigaction.2.html">sigaction(2)</A></STRONG> for more information).
Each process has <EM>real</EM> user and group IDs and an <EM>effective</EM> user and group
IDs. The <EM>real</EM> ID identifies the person using the system; the <EM>effective</EM>
ID determines his access privileges. <STRONG>Execve</STRONG> changes the effective user
and group ID to the owner of the executed file if the file has the "set-
user-ID" or "set-group-ID" modes. The <EM>real</EM> user ID is not affected.
The new process also inherits the following attributes from the calling
process:
process ID see <STRONG><A HREF="../man2/getpid.2.html">getpid(2)</A></STRONG>
parent process ID see <STRONG><A HREF="../man2/getppid.2.html">getppid(2)</A></STRONG>
process group ID see <STRONG><A HREF="../man2/getpgrp.2.html">getpgrp(2)</A></STRONG>
access groups see <STRONG><A HREF="../man2/getgroups.2.html">getgroups(2)</A></STRONG>
working directory see <STRONG><A HREF="../man2/chdir.2.html">chdir(2)</A></STRONG>
root directory see <STRONG><A HREF="../man2/chroot.2.html">chroot(2)</A></STRONG>
control terminal see <STRONG><A HREF="../man4/tty.4.html">tty(4)</A></STRONG>
alarm timer see <STRONG><A HREF="../man2/alarm.2.html">alarm(2)</A></STRONG>
file mode mask see <STRONG><A HREF="../man2/umask.2.html">umask(2)</A></STRONG>
signal mask see <STRONG><A HREF="../man2/sigaction.2.html">sigaction(2)</A></STRONG>, <STRONG><A HREF="../man2/sigprocmask.2.html">sigprocmask(2)</A></STRONG>
When the executed program begins, it is called as follows:
<STRONG>int</STRONG> <STRONG>main(int</STRONG> <EM>argc</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <EM>argv</EM><STRONG>[],</STRONG> <STRONG>char</STRONG> <STRONG>*const</STRONG> <EM>envp</EM><STRONG>[]);</STRONG>
<STRONG>exit(main(</STRONG><EM>argc</EM><STRONG>,</STRONG> <EM>argv</EM><STRONG>,</STRONG> <EM>envp</EM><STRONG>));</STRONG>
where <EM>argc</EM> is the number of elements in <EM>argv</EM> (the ``arg count'') and <EM>argv</EM>
is the array of character pointers to the arguments themselves.
<EM>Envp</EM> is a pointer to an array of strings that constitute the <EM>environment</EM>
of the process. A pointer to this array is also stored in the global
variable ``environ''. Each string consists of a name, an "=", and a
null-terminated value. The array of pointers is terminated by a null
pointer. The shell <STRONG><A HREF="../man1/sh.1.html">sh(1)</A></STRONG> passes an environment entry for each global
shell variable defined when the program is called. See <STRONG><A HREF="../man7/environ.7.html">environ(7)</A></STRONG> for
some conventionally used names.
</PRE>
<H2>RETURN VALUE</H2><PRE>
If <STRONG>execve</STRONG> returns to the calling process an error has occurred; the
return value will be -1 and the global variable <STRONG>errno</STRONG> will contain an
error code.
</PRE>
<H2>ERRORS</H2><PRE>
<STRONG>Execve</STRONG> will fail and return to the calling process if one or more of the
following are true:
[ENOTDIR] A component of the path prefix is not a directory.
[ENAMETOOLONG] The path name exceeds PATH_MAX characters.
[ENOENT] The new process file does not exist.
[ELOOP] Too many symbolic links were encountered in translating
the pathname. (Minix-vmd)
[EACCES] Search permission is denied for a component of the path
prefix.
[EACCES] The new process file is not an ordinary file.
[EACCES] The new process file mode denies execute permission.
[ENOEXEC] The new process file has the appropriate access
permission, but has an invalid magic number in its header.
[ENOMEM] The new process requires more (virtual) memory than is
currently available.
[E2BIG] The number of bytes in the new process's argument list is
larger than the system-imposed limit ARG_MAX. The limit
in the system as released is 4096 bytes for 16-bit Minix,
16384 bytes for 32-bit Minix, and unlimited for Minix-vmd.
[EFAULT] <EM>Path</EM>, <EM>argv</EM>, or <EM>envp</EM> point to an illegal address.
[EIO] An I/O error occurred while reading from the file system.
</PRE>
<H2>CAVEATS</H2><PRE>
If a program is <EM>setuid</EM> to a non-super-user, but is executed when the real
<STRONG>uid</STRONG> is ``root'', then the program has some of the powers of a super-user
as well.
</PRE>
<H2>SEE ALSO</H2><PRE>
<STRONG><A HREF="../man2/exit.2.html">exit(2)</A></STRONG>, <STRONG><A HREF="../man2/fork.2.html">fork(2)</A></STRONG>, <STRONG><A HREF="../man3/execl.3.html">execl(3)</A></STRONG>, <STRONG><A HREF="../man7/environ.7.html">environ(7)</A></STRONG>.
</PRE>
</BODY>
</HTML>