home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.26 / text0048.txt < prev    next >
Encoding:
Text File  |  1992-02-21  |  4.6 KB  |  92 lines

  1. Submitted-by: brnstnd@KRAMDEN.ACF.NYU.EDU (Dan Bernstein)
  2.  
  3. Jason Zions writes:
  4. > There is an expectation that one can open() a local
  5. > file, a remote file, a real-time message queue, a secure file, and a named
  6. > network connection, all with a function whose name is open() and has some
  7. > common parameters.
  8.  
  9. *Why*?
  10.  
  11. Many people share this ``expectation.'' I don't understand why. Is it
  12. because of ``the UNIX philosophy''? Or because a super-open() is
  13. supposed to be easier for programmers? Or for users?
  14.  
  15. Let me dispose of these myths, one by one. First of all, ``the UNIX
  16. philosophy'' is not ``everything's a file.'' Nor is it ``everything
  17. has a name in the filesystem.'' It never was. In v7, pipes were not
  18. files. Pipes still aren't files. Streams and sockets aren't in the
  19. filesystem either.
  20.  
  21. The UNIX philosophy is that everything is a *file descriptor*. This is
  22. why pipes are so useful---programs are written to use the *file
  23. descriptors* 0, 1, and 2. File descriptors---and, most importantly, the
  24. way that descriptors are inherited across fork() and exec()---are the
  25. whole reason that tools work together better in UNIX than in any other
  26. operating system. Input and output---read() and write()---work on file
  27. descriptors uniformly. That's why tools work the same way whether
  28. they're talking to a tty, a file, a pipe, a socket, or what have you.
  29. *That's* the UNIX philosophy.
  30.  
  31. The UNIX philosophy doesn't give a damn how many syscalls there are to
  32. create descriptors in the first place---as long as they all work with
  33. read(), write(), dup(), close(), fork(), exec(), and so on. If it's so
  34. important for UNIX that there be a single syscall to create new file
  35. descriptors, how come v7 had *three* syscalls---not just open(), but
  36. also pipe() and creat()? If you want to get rid of socket(), accept(),
  37. socketpair(), connect(), and any other non-open() way of creating a
  38. descriptor, all in the name of ``the UNIX philosophy,'' then why don't
  39. you include pipe() in your super-open() too?
  40.  
  41. Let's move on to the supposed simplicity of super-open() for programmers.
  42. Since when was it difficult to create, e.g., network connections with the
  43. BSD syscalls? You can take any program you want---any program which uses
  44. *file descriptors*, that is---and offer it as a service under inetd. Or
  45. use any number of available packages (example: my clientserver package)
  46. which let you do the same thing from shell scripts or inside programs.
  47. Once you have a single utility which opens a network connection and passes
  48. the *file descriptor* to the program of your choice, you can forget about
  49. the details of network code and simply stick to read() and write(). Why
  50. would a super-complex super-open() be any easier than this?
  51.  
  52. Or to take your example of ``a secure file''---there's a utility running
  53. around which implements access control lists on any UNIX system. It works
  54. the same way as the network utilities: it does the appropriate checks,
  55. creates the *file descriptor*, and passes it to any program you specify.
  56. There you have it: ACLs without super-open() and without any kernel mods!
  57. Is it really supposed to be simpler to have even more flags and arguments
  58. to open()?
  59.  
  60. Competent UNIX programmers write tools which stick to stdin, stdout, and
  61. stderr. Only a few specialized tools---cat, sh, inetd---have to worry
  62. about open() or pipe() or socket(). By adding a super-open() you might
  63. make it a tiny bit easier to write those specialized tools, but you're
  64. also bloating the kernel for something which the vast majority of
  65. programs will never use. Why do you think the market hasn't even
  66. considered a similar syscall?
  67.  
  68. Finally, let's consider super-open()'s advantages for users. Certainly
  69. it'd be nice for a user to be able to type something like, say,
  70.  
  71.    % cat #13@athena.mit.edu
  72.  
  73. (disclaimer: I haven't given any thought to a good notation for this)
  74. and have cat read from a TCP socket connected to port 13 on athena. Does
  75. this mean that open() should support such notation? No! By kludging that
  76. into the kernel you're taking control away from the user. The UNIX way
  77. is much better for all concerned: *Let the shell worry about it*. Let the
  78. shell parse #13@athena.mit.edu and invoke the right programs to set up a
  79. network connection. Give users the freedom to choose shells which offer
  80. the notations they like. Should I point out that several existing shells,
  81. ksh for example, already provide such constructs?
  82.  
  83. ``There is an expectation that one can open() a local file, a remote
  84. file, a real-time message queue, a secure file, and a named network
  85. connection, all with a function whose name is open() and has some common
  86. parameters.'' Once again I ask: Why?
  87.  
  88. ---Dan
  89.  
  90. Volume-Number: Volume 26, Number 50
  91.  
  92.