home *** CD-ROM | disk | FTP | other *** search
- libiexec
-
- BSD-derived Unixes have a very useful kernel hack that most System V
- (R<4) Unixes don't, which makes it easy to run scripts for various
- interpreters such as perl, ksh, csh, and awk.
-
- If an exec-family function finds that a file it has been told to run
- does not have a valid magic number for a binary, it tries to run the
- file as a script. To do this, it checks to see whether the file
- starts with the characters "#!". If it does, the kernel takes the
- word following the "#!" to be the pathname of the program to run
- instead, with the path of the script file given as an argument, and if
- there is another word in the "#!" line following the program pathname,
- that is also passed to the program as an argument, before the script
- name. As a special case, if the file is neither a binary nor a script
- starting with "#!", it tries to run it as a /bin/sh script.
-
- In comp.unix.wizards, john@sco.COM (John R. MacMillan) argued recently
- that there is no good reason why the "#!" interpretation must be done
- in the kernel; it can easily be done in the exec library functions
- instead.
-
- So here is an attempt to retrofit "#!" support onto systems that don't
- have it. To make it portable (so that it doesn't have to contain
- assembly language to make system calls directly), it is a library of
- wrapper functions for execl, execv, et al. that have an "i" (for
- interpreter support) prepended to the names. This also means that you
- don't have to change your system libraries in order to use them.
- To compile programs using them, add these to the flags you pass cc:
-
- -Dexecl=iexecl -Dexecle=iexecle -Dexeclp=iexeclp -Dexecv=iexecv
- -Dexecve=iexecve -Dexecvp=iexecvp
-
- Or, just pass the ones defining the functions the program you are
- compiling actually uses.
-
- Then add libiexec.a to the list of files passed to the linking phase.
-
- The downside of this implementation is that you can't add "#!" support
- to programs you don't have the source code to, probably including
- /bin/sh (unless you have some kind of shared libraries, perhaps). A
- plausible workaround is to get a free Bourne-compatible shell, such as
- GNU bash, and install that as /bin/sh instead, linked with this
- library. bash doesn't have the getopts builtin or some of ksh's
- esoteric features, but as of release 1.08 it's in reasonably good
- shape otherwise.
-
- I have tested this library lightly on SCO Unix 3.2.2 using gcc.
- For other systems, I welcome suggestions, fixes, improvements, ports, etc.
-
- David MacKenzie <djm@eng.umd.edu>
-