PWB1/usr/man/man3/pexec.3

.th PEXEC III 5/31/77
.sh NAME
pexec \*- path search and execute a file
.sh SYNOPSIS
.bd "char pathstr[128];
.br
.bd "char shellnam[16];
.br
.bd "pexec(name, argv)
.br
.bd "char *name, *argv[];"
.br
.bd "pexinit( )"
.sh DESCRIPTION
.it Pexec
provides an interface to
the
.it execv
function
that duplicates the shell's actions in searching for
an executable file in a list of directories,
as specified in the user's `.path' file.
.s3
.it Pexinit
investigates the external arrays
.it pathstr
and
.it shellnam.
If either array is non-null,
it leaves that array alone.
If
.it pathstr
is null,
it attempts to open the user's `.path' file and
place the first line found there into
.it pathstr,
to be used later as a list of directories to be searched.
If `.path' cannot be opened, it uses:
.s3
/bin:/etc:/	for super-user
.br
:/bin:/usr/bin	for anyone else
.s3
If a second line is found in the `.path' file,
it is taken as the name of the shell to be executed to
interpret a shell procedure.
If none is found,
`/bin/sh' is used.
.it Pexinit
returns 0 to show successful completion,
guaranteeing both arrays filled,
and \*-1 otherwise.
.s3
.it Pexec
first calls
.it pexinit,
then searches for the named file and executes it.
The existence of two functions
permits
.it pexinit
to be called once,
followed by many
.it fork/pexec
pairs.
.s3
This function is kept in the
.bd \-lPW
library.
.sh "SEE ALSO"
sh(I), exec(II), fork(II)
.sh DIAGNOSTICS
Items in parentheses refer to error names in
.it intro\^\c
(II).
.br
``cannot read .path''
.br
``.path too long'' (more than 128+16 = 144 bytes long)
.br
``No shell!'' (real trouble, cannot execute shell)
.br
``too large'' (ENOMEM)
.br
``arg list too long'' (E2BIG)
.br
``file not executable'' (EACCES, no x bits set in file mode)
.br
``not found'' (name could not be found at all)
.br
``text busy'' (ETXTBSY, should be very rare)
.sh BUGS
A pathname generated by the search mechanism may not exceed
47 characters in length.