Path: utzoo!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mailrus!ames!killer!vector!rpp386!pigs!haugj From: haugj@pigs.UUCP (The Beach Bum) Newsgroups: comp.unix.xenix Subject: Re: "#!" scripts, kernel patches, and Xenix Summary: ah! sco speaks up ... Message-ID: <405@pigs.UUCP> Date: 13 Sep 88 14:57:30 GMT References: <161@tessera.UUCP> <858@viscous> Reply-To: haugj@pigs.UUCP (The Beach Bum) Organization: The Big "D" Home for Wayward Hackers Lines: 43 In article <858@viscous> rosso@sco.COM (Ross Oliver) writes: >In article <161@tessera.UUCP> jtc@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@rpp386.dallas.tx.us Very Short Address: jfh@rpp386 "ANSI C: Just say no" -- Me