home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / libiexec / part01 / README < prev   
Text File  |  1991-07-25  |  3KB  |  67 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 "#!", execlp and execvp try 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.  It is a library of replacement functions for execl, execvp,
  25. et al. that have an "i" (for "interpreter support") prepended to the
  26. names.  This means that you don't have to change your system libraries
  27. in order to use them.  To compile programs using them, add these to
  28. the flags you pass cc:
  29.  
  30. -Dexecl=iexecl -Dexecle=iexecle -Dexeclp=iexeclp -Dexecv=iexecv
  31. -Dexecve=iexecve -Dexecvp=iexecvp
  32.  
  33. Or, just pass the ones redefining the functions the program you are
  34. compiling actually uses.
  35.  
  36. Then add libiexec.a to the list of files passed to the linking phase.
  37.  
  38. A limitation of this implementation is that you can't add "#!" support
  39. to programs you don't have the source code to, probably including sh
  40. and csh (unless you have some kind of shared libraries, perhaps).  A
  41. solution for the shells is to get free shells such as bash and tcsh
  42. (version 6.00 or later) and install them as /bin/sh or /bin/csh
  43. instead.  bash itself supports "#!" on systems where the exec
  44. functions don't, except that versions 1.08 and previous don't do it
  45. for programs you run with the "exec" command.  Because bash uses
  46. execve, "exec scriptname" will fail if the script does not start with
  47. "#!interpreter-path" even if you link it with this library (and even
  48. if you run bash on a BSD system).  If you want to fix that problem, at
  49. the loss of some BSD compatibility in the functions, change the ", 0"
  50. to ", 1" in iexecve in iexec.c.  bash doesn't have the getopts builtin
  51. or some of ksh's esoteric features, but as of release 1.08 it's in
  52. reasonably good shape otherwise.
  53.  
  54. If you want to make linking with these functions transparent, the
  55. following procedure will probably work, though I have not tried it.
  56. Using some program that can edit binary files, such as GNU emacs,
  57. change every "execv" or "execl" in your libc.a to "oxecv" or "oxecl"
  58. ("o" for "old").  Change iexec.c so that script_execve, iexecve and
  59. iexecvp call oxecve instead of execve; then rename the functions
  60. defined in iexec.c so that they do not have the initial "i" in their
  61. names.  Compile iexec.c and use ar to add iexec.o to libc.a.
  62.  
  63. ietest.c is a test program that is linked with libiexec.a and runs
  64. cshscript to make sure the library works.
  65.  
  66. David MacKenzie <djm@eng.umd.edu>
  67.