magic numbers

George Rosenberg george at idis.UUCP
Mon Mar 12 02:43:23 AEST 1984


I think that giving the kernel the ability to exec files
that can be interpreted is a good feature.
I don't use a system with this feature.
Since there is a discussion about it, I will bring up some
points that I am curious about.

The programs that perform the most execs, sh and csh,
will also be the interpreters that most scripts employ.
If an exec fails the Bourne shell will interpret
a script via a longjmp.
I assume that a longjmp is much cheaper than completing an exec.
Has anyone compared the two?
Is there a way that an informed program such as a shell interpreter
can tell the kernel to return without completing the exec,
if the old program and new interpreter are the same file and
the setuid and setgid bits of the script are not set?

>From what I understand, execing a file that begins with "#!"
will examine the next two tokens on the first line.
The first token must be a path name of an interpreter.
The tokens are inserted before the old argument list.
The execute bit and the setuid and setgid bits of the script are honored.
The interpreter is responsible for opening the script.
Can the interpreter also have "#!" as its magic number?
It seems to me that a design that also accommodated access modes
in which a file containing a script was executable but not readable
would also have been desirable.
This could have been done by simulating an open for reading (and perhaps
also a deferred FIOCLEX) on a particular file descriptor (such as 19).
I think that simulating an lseek to the beginning of the second line
would also be desirable.
Does anyone know why nothing like this was added at the same time?

	George Rosenberg
	duke!mcnc!idis!george
	decvax!idis!george



More information about the Comp.unix.wizards mailing list