home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3588 / README < prev   
Encoding:
Text File  |  1991-07-04  |  2.4 KB  |  52 lines

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