"#!" scripts, kernel patches, and Xenix

The Beach Bum haugj at pigs.UUCP
Wed Sep 14 00:57:30 AEST 1988


In article <858 at viscous> rosso at sco.COM (Ross Oliver) writes:
>In article <161 at tessera.UUCP> jtc at tessera.UUCP (J.T. Conklin) writes:
>>Has anyone patched the kernel exec routine to execute interpreter
>>files ("#!" scripts)?
>
>The exec() function executes binaries only.  If exec() fails (which
>it does on a shell script), then it is up to your shell to decide
>what to do.

[ this process has been described in the past.  it was something
  which ken thompson (?) added to the research kernel years ago. ]

there are unix systems where exec() in the kernel knows about shell
scripts.  the magic number #! (one of 021441 or 020443) is trapped by
the kernel, which then scans the rest of the line from the executable
file.

the remainder of the line (which is going to be a binary executable)
is then used in place of the first argument to exec.  an exec call
of the form

	execlp ("myscript", "myscript", "arg", 0);

gets converted internally, after seeing '#! /usr/lbin/perl' say, to

	execlp ("/usr/lbin/perl", "myscript", "myscript", "arg", 0);

[ this is from faulty memory.  the second argument may become the
  interpreter name as well. ]

the first block of the executable is read in and checked for magic
numbers so all of this can be dealt with before the argument list
is constructed for the new task.

it really would be best if sco added this feature.  fork(), exit()
and sbrk() are in the same file (os/sys1.c) [ run nm(1) on your
libraries for more information ] as exec().  you do not want to
disassemble that much code and then expect the result to work ;-)
-- 
=-=-=-=-=-=-=-The Beach Bum at The Big "D" Home for Wayward Hackers-=-=-=-=-=-=
               Very Long Address: John.F.Haugh at rpp386.dallas.tx.us
                         Very Short Address: jfh at rpp386
                           "ANSI C: Just say no" -- Me



More information about the Comp.unix.xenix mailing list