home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
LIB
/
unix.zoo
/
execl.c
< prev
next >
Wrap
Text File
|
2009-11-06
|
9KB
|
204 lines
/***************************************************************************/
/* */
/* execl() : Unix library (OS9/68000) */
/* ======= */
/* */
/* Author: K. Schmitt */
/* Compiler: Microware C Vers. 3.0 */
/* OS: OS9/68000 Vers. 2.2 */
/* */
/* Edition History */
/* =============== */
/* */
/* Ed. 0.00 Date 11/16/88 */
/* First version */
/* */
/***************************************************************************/
/* */
/* Description */
/*
SYNOPSIS
int execl (path, arg0, arg1, ..., argn, (char *)0)
char *path, *arg0, *arg1, ..., *argn;
DESCRIPTION
Exec in all its forms transforms the calling process into a
new process. The new process is constructed from an
ordinary, executable file called the new process file. This
file consists of a header, a text segment,
and a data segment. The data segment contains an
initialized portion and an uninitialized portion (bss).
There can be no return from a successful exec because the
calling process is overlaid by the new process.
When a C program is executed, it is called as follows:
main (argc, argv, envp)
int argc;
char **argv, **envp;
where argc is the argument count and argv is an array of
character pointers to the arguments themselves. As
indicated, argc is conventionally at least one and the first
member of the array points to a string containing the name
of the file.
Path points to a path name that identifies the new process
file.
File points to the new process file. The path prefix for
this file is obtained by a search of the directories passed
as the environment line "PATH =". The
environment is supplied by the shell.
Arg0, arg1, ..., argn are pointers to null-terminated
character strings. These strings constitute the argument
list available to the new process. By convention, at least
arg0 must be present and point to a string that is the same
as path (or its last component).
Argv is an array of character pointers to null-terminated
strings. These strings constitute the argument list
available to the new process. By convention, argv must have
at least one member, and it must point to a string that is
the same as path (or its last component). Argv is
terminated by a null pointer.
Envp is an array of character pointers to null-terminated
strings. These strings constitute the environment for the
new process. Envp is terminated by a null pointer. For
execl and execv, the C run-time start-off routine places a
pointer to the environment of the calling process in the
global cell:
extern char **environ;
and it is used to pass the environment of the calling
process to the new process.
File descriptors open in the calling process remain open in
the new process, except for those whose close-on-exec flag
is set; see fcntl(2). For those file descriptors that
remain open, the file pointer is unchanged.
Signals set to terminate the calling process will be set to
terminate the new process. Signals set to be ignored by the
calling process will be set to be ignored by the new
process. Signals set to be caught by the calling process
will be set to terminate new process.
If the set-user-ID mode bit of the new process file is set,
exec sets the effective user ID of the new
process to the owner ID of the new process file. Similarly,
if the set-group-ID mode bit of the new process file is set,
the effective group ID of the new process is set to the
group ID of the new process file. The real user ID and real
group ID of the new process remain the same as those of the
calling process.
The shared memory segments attached to the calling process
will not be attached to the new process.
The new process also inherits the following attributes from
the calling process:
process ID
parent process ID
process group ID
tty group ID
trace flag
time left until an alarm clock signal
current working directory
root directory
file mode creation mask
file size limit
utime, stime, cutime and cstime
Exec will fail and return to the calling process if one or
more of the following are true:
[ENOENT] One or more components of the new process
path name of the file do not exist.
[ENOTDIR] A component of the new process path of the
file prefix is not a directory.
[EACCES] Search permission is denied for a directory
listed in the new process file's path prefix.
[EACCES] The new process file is not an ordinary file.
[EACCES] The new process file mode denies execution
permission.
[ENOEXEC] The exec is not an execlp or execvp, and the
new process file has the appropriate access
permission but an invalid magic number in its
header.
[ETXTBSY] The new process file is a pure procedure
(shared text) file that is currently open for
writing by some process.
[ENOMEM] The new process requires more memory than is
allowed by the system-imposed maximum MAXMEM.
[E2BIG] The number of bytes in the new process's
argument list is greater than the system-
imposed limit of 5120 bytes.
[EFAULT] The new process file is not as long as
indicated by the size values in its header.
[EFAULT] Path, argv, or envp point to an illegal
address.
RETURN VALUE
If exec returns to the calling process an error has
occurred; the return value will be -1 and errno will be set
to indicate the error.
*/
/* VARARGS */
int execl (path, arg0, argn)
char *path, *arg0, *argn;
{
register long *argp;
register char **argv;
register int nargs;
extern char **malloc();
extern int errno, chainc(), os9exec(), modload();
extern char **environ;
argp = (long *) &argn;
nargs = 1;
while (*argp)
{
nargs++;
argp++;
}
modload(path,0); /* load module (use 'path') */
if ((argv=malloc(sizeof(char *) * (nargs+1))) == (char **) 0)
{
exit(errno);
}
argv[0] = arg0;
argp = (long *) &argn;
nargs = 1;
while (*argp)
{
argv[nargs++] = (char *) *argp++;
}
argv[nargs] = (char *) 0;
exit(os9exec(chainc,arg0,argv,environ,0,0,32));
} /* end of execl */