UNIX source vs. binary (NOT A LEGAL ARGUMENT)
Rob Warnock
rpw3 at redwood.UUCP
Wed Feb 20 20:47:20 AEST 1985
+---------------
| Sorry, that won't work on v7 systems, where you can't execute a shell
| file with exec(2), which is what login uses (execlp, actually).
| Dave Sherman | {utzoo pesnta nrcaero utcs}!lsuc!dave
| {allegra decvax ihnp4 linus}!utcsri!lsuc!dave
+---------------
Well, I know that in 4.1bsd "execlp" will run a shell script
(and on my F-box here, too), but where is it documented? A look
at "exec(2)" in a V.7 manual reveals:
Execlp and execvp are called with the same arguments as
execl and execv, but duplicate the shell's actions in
searching for an executable file in a list of directories.
I have always read this to mean that in addition to using "$PATH",
execlp/execvp also duplicates the shell's check for legal "magic
numbers" (see "a.out(5)") and assumes anything else is a shell
script (the 4.?bsd "#!" cookie is treated as a magic number).
Checking "sh(1)" we see:
Execution
...If the file has execute permission but is not an "a.out"
file, it is assumed to be a file containing shell commands.
But having my curiosity aroused, I went back to "exec(2)", read further
on and found:
BUGS
If execvp is called to execute a file that turns out to be
a shell command file, and if it is impossible to execute the
shell, the values of argv[0] and argv[-1] will be modified
before return.
To be sure, there are clearer ways to say it explicitly (rather than
as a side effect of describing a bug), but that pretty much settles it --
Version 7 "execlp/execvp" DOES work (exec a shell) for shell scripts.
(Additional minor quibble: given the amount of diddling around it does,
execlp/execvp should probably be with the other library routines as
"exec(3)", rather than with the "pure" system calls in "exec(2)".)
Rob Warnock
Systems Architecture Consultant
UUCP: {ihnp4,ucbvax!dual}!fortune!redwood!rpw3
DDD: (415)572-2607
USPS: 510 Trinidad Lane, Foster City, CA 94404
More information about the Comp.unix.wizards
mailing list