BSD 4_4_Lite1 release
[unix-history] / usr / src / lib / libc / sys / execve.2
index e8e826a..ba47e6d 100644 (file)
-.\" Copyright (c) 1980 Regents of the University of California.
-.\" All rights reserved.  The Berkeley software License Agreement
-.\" specifies the terms and conditions for redistribution.
+.\" Copyright (c) 1980, 1991, 1993
+.\"    The Regents of the University of California.  All rights reserved.
 .\"
 .\"
-.\"    @(#)execve.2    6.4 (Berkeley) %G%
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"    This product includes software developed by the University of
+.\"    California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
 .\"
 .\"
-.TH EXECVE 2 ""
-.UC 4
-.SH NAME
-execve \- execute a file
-.SH SYNOPSIS
-.ft B
-execve(name, argv, envp)
-.br
-char *name, *argv[], *envp[];
-.fi
-.SH DESCRIPTION
-.I Execve
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)execve.2   8.3 (Berkeley) 1/24/94
+.\"
+.Dd January 24, 1994
+.Dt EXECVE 2
+.Os BSD 4
+.Sh NAME
+.Nm execve
+.Nd execute a file
+.Sh SYNOPSIS
+.Fd #include <unistd.h>
+.Ft int
+.Fn execve "const char *path" "char *const argv[]" "char *const envp[]"
+.Sh DESCRIPTION
+.Fn Execve
 transforms the calling process into a new process.
 transforms the calling process into a new process.
-The new process is constructed from an ordinary file
-called the \fInew process file\fP.
+The new process is constructed from an ordinary file,
+whose name is pointed to by
+.Fa path ,
+called the
+.Em new process file .
 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
 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 initialize with zero data.  See
-.IR a.out (5).
-.PP
-An interpreter file begins with a line of the form ``#! \fIinterpreter\fP'';
+by the header to be initialized with zero data;  see
+.Xr a.out 5 .
+.Pp
+An interpreter file begins with a line of the form:
+.Pp
+.Bd -filled -offset indent -compact
+.Sy \&#!
+.Em interpreter
+.Bq Em arg
+.Ed
+.Pp
 When an interpreter file is
 When an interpreter file is
-.IR execve\| 'd,
-the system \fIexecve\fP\|'s the specified \fIinterpreter\fP, giving
-it the name of the originally exec'd file as an argument,
-shifting over the rest of the original arguments.
-.PP
-There can be no return from a successful \fIexecve\fP because the calling
-core image is lost.
-This is the mechanism whereby different process images become active.
-.PP
-The argument \fIargv\fP is an 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 \fIname\fP).
-.PP
-The argument \fIenvp\fP is also an 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
-.IR environ (7).
-.PP
-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
-.IR close (2).
+.Fn execve Ap d ,
+the system
+.Fn execve Ap s
+runs the specified
+.Em interpreter .
+If the optional
+.Em arg
+is specified, it becomes the first argument to the
+.Em interpreter ,
+and the name of the originally
+.Fn execve Ap d
+file becomes the second argument;
+otherwise, the name of the originally
+.Fn execve Ap d
+file becomes the first argument.  The original arguments are shifted over to
+become the subsequent arguments.  The zeroth argument, normally the name of the
+.Fn execve Ap d
+file, is left unchanged.
+.Pp
+The argument
+.Fa argv
+is a pointer to a null-terminated array of
+character pointers to null-terminated character strings.
+These strings construct the argument list to be made available to the new
+process.  At least one argument must be present in
+the array; by custom, the first element should be
+the name of the executed program (for example, the last component of
+.Fa path ) .
+.Pp
+The argument
+.Fa envp
+is also a pointer to a null-terminated array of
+character pointers to null-terminated strings.
+A pointer to this array is normally stored in the global variable
+.Va environ.
+These strings pass information to the
+new process that is not directly an argument to the command (see
+.Xr environ 7 ) .
+.Pp
+File descriptors open in the calling process image remain open in
+the new process image, except for those for which the close-on-exec
+flag is set (see
+.Xr close 2
+and
+.Xr fcntl 2 ) .
 Descriptors that remain open are unaffected by
 Descriptors that remain open are unaffected by
-.IR execve .
-.PP
-Ignored signals remain ignored across an
-.IR execve ,
-but signals that are caught are reset to their default values.
-The signal stack is reset to be undefined; see
-.IR sigvec (2)
-for more information.
-.PP
-Each process has
-.I real
-user and group IDs and a
-.I effective
-user and group IDs.  The
-.I real
-ID identifies the person using the system; the
-.I effective
-ID determines his access privileges.
-.I Execve
-changes the effective user and group ID to
-the owner of the executed file if the file has the \*(lqset-user-ID\*(rq
-or \*(lqset-group-ID\*(rq modes.  The
-.I real
-user ID is not affected.
-.PP
+.Fn execve .
+.Pp
+Signals set to be ignored in the calling process are set to be ignored in
+the
+new process. Signals which are set to be caught in the calling process image
+are set to default action in the new process image.
+Blocked signals remain blocked regardless of changes to the signal action.
+The signal stack is reset to be undefined (see
+.Xr sigaction 2
+for more information).
+.Pp
+If the set-user-ID mode bit of the new process image file is set
+(see
+.Xr chmod 2 ) ,
+the effective user ID of the new process image is set to the owner ID
+of the new process image file.
+If the set-group-ID mode bit of the new process image file is set,
+the effective group ID of the new process image is set to the group ID
+of the new process image file.
+(The effective group ID is the first element of the group list.)
+The real user ID, real group ID and
+other group IDs of the new process image remain the same as the calling
+process image.
+After any set-user-ID and set-group-ID processing,
+the effective user ID is recorded as the saved set-user-ID,
+and the effective group ID is recorded as the saved set-group-ID.
+These values may be used in changing the effective IDs later (see
+.Xr setuid 2 ) .
+.Pp
 The new process also inherits the following attributes from
 the calling process:
 The new process also inherits the following attributes from
 the calling process:
-.PP
-.in +5n
-.nf
-.ta +2i
-process ID     see \fIgetpid\fP\|(2)
-parent process ID      see \fIgetppid\fP\|(2)
-process group ID       see \fIgetpgrp\fP\|(2)
-access groups  see \fIgetgroups\fP\|(2)
-working directory      see \fIchdir\fP\|(2)
-root directory see \fIchroot\fP\|(2)
-control terminal       see \fItty\fP\|(4)
-resource usages        see \fIgetrusage\fP\|(2)
-interval timers        see \fIgetitimer\fP\|(2)
-resource limits        see \fIgetrlimit\fP\|(2)
-file mode mask see \fIumask\fP\|(2)
-signal mask    see \fIsigvec\fP\|(2)
-.in -5n
-.fi
-.PP
-When the executed program begins, it is called as follows:
-.PP
-.DT
-.nf
-       main(argc, argv, envp)
-       int argc;
-       char **argv, **envp;
-.fi
-.PP
+.Pp
+.Bl -column parent_process_ID -offset indent -compact
+.It process ID Ta see Xr getpid 2
+.It parent process ID Ta see Xr getppid 2
+.It process group ID Ta see Xr getpgrp 2
+.It access groups Ta see Xr getgroups 2
+.It working directory Ta see Xr chdir 2
+.It root directory Ta see Xr chroot 2
+.It control terminal Ta see Xr termios 4
+.It resource usages Ta see Xr getrusage 2
+.It interval timers Ta see Xr getitimer 2
+.It resource limits Ta see Xr getrlimit 2
+.It file mode mask Ta see Xr umask 2
+.It signal mask Ta see Xr sigvec 2 ,
+.Xr sigsetmask 2
+.El
+.Pp
+When a program is executed as a result of an
+.Fn execve
+call, it is entered as follows:
+.Bd -literal -offset indent
+main(argc, argv, envp)
+int argc;
+char **argv, **envp;
+.Ed
+.Pp
 where
 where
-.I argc
-is the number of elements in \fIargv\fP
+.Fa argc
+is the number of elements in
+.Fa argv
 (the ``arg count'')
 and
 (the ``arg count'')
 and
-.I argv
-is the array of character pointers
+.Fa argv
+points to the array of character pointers
 to the arguments themselves.
 to the arguments themselves.
-.PP
-.I Envp
-is a pointer to an array of strings that constitute
-the
-.I environment
-of the process.
-A pointer to this array is also stored in the global variable ``environ''.
-Each string consists of a name, an \*(lq=\*(rq, and a null-terminated value.
-The array of pointers is terminated by a null pointer.
-The shell
-.IR sh (1)
-passes an environment entry for each global shell variable
-defined when the program is called.
-See
-.IR environ (7)
-for some conventionally
-used names.
-.SH "RETURN VALUE
+.Sh RETURN VALUES
+As the
+.Fn execve
+function overlays the current process image 
+with a new process image the successful call
+has no process to return to.
 If
 If
-.I execve
-returns to the calling process an error has occurred; the
-return value will be \-1 and the global variable
-.I errno
-will contain an error code.
-.SH ERRORS
-.I Execve
-will fail and return to the calling process if one or more
-of the following are true:
-.TP 15
-[ENOTDIR]
+.Fn execve
+does return to the calling process an error has occurred; the
+return value will be -1 and the global variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+.Fn Execve
+will fail and return to the calling process if:
+.Bl -tag -width [ENAMETOOLONG]
+.It Bq Er ENOTDIR
 A component of the path prefix is not a directory.
 A component of the path prefix is not a directory.
-.TP 15
-[EINVAL]
+.It Bq Er EINVAL
 The pathname contains a character with the high-order bit set.
 The pathname contains a character with the high-order bit set.
-.TP 15
-[ENAMETOOLONG]
+.It Bq Er ENAMETOOLONG
 A component of a pathname exceeded 255 characters,
 or an entire path name exceeded 1023 characters.
 A component of a pathname exceeded 255 characters,
 or an entire path name exceeded 1023 characters.
-.TP 15
-[ENOENT]
+.It Bq Er ENOENT
 The new process file does not exist.
 The new process file does not exist.
-.TP 15
-[ELOOP]
+.It Bq Er ELOOP
 Too many symbolic links were encountered in translating the pathname.
 Too many symbolic links were encountered in translating the pathname.
-.TP 15
-[EACCES]
+.It Bq Er EACCES
 Search permission is denied for a component of the path prefix.
 Search permission is denied for a component of the path prefix.
-.TP 15
-[EACCES]
+.It Bq Er EACCES
 The new process file is not an ordinary file.
 The new process file is not an ordinary file.
-.TP 15
-[EACCES]
+.It Bq Er EACCES
 The new process file mode denies execute permission.
 The new process file mode denies execute permission.
-.TP 15
-[ENOEXEC]
+.It Bq Er ENOEXEC
 The new process file has the appropriate access
 permission, but has an invalid magic number in its header.
 The new process file has the appropriate access
 permission, but has an invalid magic number in its header.
-.TP 15
-[ETXTBSY]
+.It Bq Er ETXTBSY
 The new process file is a pure procedure (shared text)
 file that is currently open for writing or reading by some process.
 The new process file is a pure procedure (shared text)
 file that is currently open for writing or reading by some process.
-.TP 15
-[ENOMEM]
+.It Bq Er ENOMEM
 The new process requires more virtual memory than
 is allowed by the imposed maximum
 The new process requires more virtual memory than
 is allowed by the imposed maximum
-.RI ( getrlimit (2)).
-.TP 15
-[E2BIG]
+.Pq Xr getrlimit 2 .
+.It Bq Er E2BIG
 The number of bytes in the new process's argument list
 The number of bytes in the new process's argument list
-is larger than the system-imposed limit of {ARG_MAX} bytes.
-.TP 15
-[EFAULT]
+is larger than the system-imposed limit.
+The limit in the system as released is 20480 bytes
+.Pf ( Dv NCARGS
+in
+.Ao Pa sys/param.h Ac .
+.It Bq Er EFAULT
 The new process file is not as long as indicated by
 the size values in its header.
 The new process file is not as long as indicated by
 the size values in its header.
-.TP 15
-[EFAULT]
-\fIPath\fP\|, \fIargv\fP\|, or \fIenvp\fP point
+.It Bq Er EFAULT
+.Fa Path ,
+.Fa argv ,
+or
+.Fa envp
+point
 to an illegal address.
 to an illegal address.
-.TP 15
-[EIO]
+.It Bq Er EIO
 An I/O error occurred while reading from the file system.
 An I/O error occurred while reading from the file system.
-.SH CAVEATS
+.El
+.Sh CAVEAT
 If a program is
 If a program is
-.I setuid
+.Em setuid
 to a non-super-user, but is executed when
 to a non-super-user, but is executed when
-the real \fIuid\fP is ``root'', then the program has the powers
+the real
+.Em uid
+is ``root'', then the program has some of the powers
 of a super-user as well.
 of a super-user as well.
-.SH "SEE ALSO"
-exit(2), fork(2), execl(3), environ(7)
+.Sh SEE ALSO
+.Xr exit 2 ,
+.Xr fork 2 ,
+.Xr execl 3 ,
+.Xr environ 7
+.Sh HISTORY
+The
+.Nm
+function call appeared in
+.Bx 4.2 .