home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.22 / text0014.txt < prev    next >
Encoding:
Text File  |  1991-03-06  |  5.6 KB  |  118 lines

  1. Submitted-by: brnstnd@kramden.acf.nyu.edu (Dan Bernstein)
  2.  
  3. In article <14162@cs.utexas.edu> ske@pkmab.se (Kristoffer Eriksson) writes:
  4. > [ I don't quite understand why the submittor wants to split this from the
  5. > thread of Re: File system name space, but let's give it a try and see what
  6. > happens, eh?  -mod ]
  7.  
  8. It is a different issue. There are objective advantages to eliminating
  9. /dev/tty, kernel controlling terminals, and POSIX sessions: the kernel
  10. becomes noticeably smaller, the POSIX standard becomes several pages
  11. thinner and a lot easier to implement, programmers no longer have to
  12. worry about special system calls to manipulate the tty fd, non-orphaned
  13. processes in orphaned process groups are not killed off unnecessarily,
  14. etc.
  15.  
  16. Neither SunOS 4.1 nor Ultrix 4.0 correctly implements POSIX sessions.
  17. In particular, both systems chop off access to the original /dev/tty
  18. after a process setsid()s and opens a different controlling terminal.
  19. This is clearly contrary to the intent of POSIX, as expressed in
  20. B.7.1.1.4. It can be proven to be a violation of the standard, as this
  21. removal of access is not defined by either implementation. Note that it
  22. happens only with /dev/tty, not with the actual terminal file; so both
  23. systems are also clearly in violation of the ctermid() definition.
  24.  
  25. The bugs I just described are solely responsible for the failure of my
  26. pty program under SunOS 4.1 and Ultrix 4.0. (I will post a stopgap patch
  27. by Friday.) If ctermid(), controlling terminals, and POSIX sessions were
  28. not mandated by P1003.1, the Sun and DEC programmers wouldn't have
  29. introduced these bugs into their latest operating systems. Isn't it
  30. obvious that the tty system is a fruitful source of bugs? Shouldn't we
  31. make every effort to simplify this area of UNIX?
  32.  
  33. v9 could easily adopt fd 3 because it is not a commercial operating
  34. system. It will take a lot more care to introduce similar changes into,
  35. e.g., BSD. I propose the following plan of action:
  36.  
  37.   1. In the next P1003.1 revision, add a feature test macro for cttys.
  38.      Take *every single sentence in the standard* talking about POSIX
  39.      sessions, cttys, or ctermid(), and make it conditional upon the
  40.      system's optional support for cttys.
  41.  
  42.   2. Also change the definitions of ``foreground process group'' and
  43.      ``background process group'' in case cttys are not supported. In
  44.      BSD, those terms are relative to the tty you're trying to access.
  45.      In POSIX, they are constant; a process is either in the foreground
  46.      or in the background, depending only on its controlling terminal.
  47.      The new definition would be the same as the old BSD definition.
  48.  
  49.   3. Add a new device, /dev/stdtty. Opening this device is equivalent to
  50.      dup()ing fd 3. Notice the name ``standard tty''; this is to avoid
  51.      confusion with ``controlling tty.'' stdio should support stdtty as
  52.      well, though (unlike stdin/out/err) stdtty may by convention be
  53.      closed.
  54.  
  55.   4. Change the few necessary programs (e.g., getty) to support the fd 3
  56.      stdtty convention. In fact, my pty program already supports this
  57.      convention, and the pty package includes patches for telnetd to
  58.      support pty. Adding similar support to getty, rlogind, etc. will be
  59.      just as easy. 
  60.  
  61.   5. Add a new device, /dev/ctty, equivalent to the current /dev/tty.
  62.  
  63.   6. Switch /dev/tty to be /dev/stdtty rather than /dev/ctty. See if
  64.      anyone notices.
  65.  
  66.   7. Turn off the ctty feature, to remain compliant with POSIX.
  67.      Eliminate controlling ttys, POSIX sessions, and so on from the
  68.      kernel. Preserve the old behavior of ps by having it glance at fd 3
  69.      inside the process u area---it already looks around enough in
  70.      kernel memory.
  71.  
  72. > In article <14103@cs.utexas.edu> arnold@audiofax.com writes:
  73. > >In general, unless someone went to the trouble, fd 3 will be attached to the
  74. > >terminal, so opening /dev/tty is pretty safe.  Nothing's foolproof; [...]
  75. > >You're no worse off than before when /dev/tty was built into the kernel.
  76. > If you have a program that closes only fd 3, this implementation will behave
  77. > differently from the old /dev/tty device implementation, won't it?
  78.  
  79. Yes, it will. So what?
  80.  
  81. > You will
  82. > not be able to reach the controlling terminal by a guaranteed route, in spite
  83. > of the fact that it is still available on other fd-s.
  84.  
  85. Who cares?
  86.  
  87. There has not been a ``guaranteed route'' to reach the controlling
  88. terminal, ever since BSD introduced TIOCEXCL. Opening /dev/tty and
  89. sending a TIOCNOTTY down it is not reliable, because /dev/tty may not be
  90. openable. That's right: there is *no* guaranteed way to dissociate from
  91. your controlling terminal. close(3) is a better solution.
  92.  
  93. Where is this glaring need for a process to find its controlling tty?
  94. Why shouldn't it be easy for the user to control, using the same fd
  95. mechanisms as any other redirection? The argument that ``passwd needs to
  96. talk to the user's tty, reliably'' has been moot ever since pseudo-ttys
  97. appeared.
  98.  
  99. What is wrong with the concept of a standard tty?
  100.  
  101. > Or is the controlling
  102. > terminal concept implemented in such a way that closing fd 3 is the same as
  103. > disassociating from the controlling terminal (so you won't be bother with
  104. > terminal interrupts and such) ?
  105.  
  106. Well, there's no logical association between closing fd 3 and changing
  107. your process group. Dissociating from the controlling terminal takes two
  108. system calls: close(3) and setpgrp(0,0). Attaching to a new one means
  109. open()ing it into fd 3, and then setting process groups appropriately.
  110. There's simply no reason that the ``controlling terminal'' of a process
  111. (whatever that is) should affect the kernel's normal process group
  112. handling.
  113.  
  114. ---Dan
  115.  
  116. Volume-Number: Volume 22, Number 15
  117.  
  118.