home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / emacs / bug / 1695 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  2.7 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!elf.tn.cornell.edu!eirik
  2. From: eirik@elf.tn.cornell.edu (Eirik Fuller)
  3. Newsgroups: gnu.emacs.bug
  4. Subject: stdout and stderr
  5. Date: 25 Jan 1993 20:28:31 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 57
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-gnu-emacs@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <199301240523.AA02120@EARACHE.TC.CORNELL.EDU>
  12.  
  13. In emacs 18.59, correct behavior of child processes depends on emacs
  14. having file descriptors 1 and 2 open.  Otherwise, child_setup closes
  15. one or more of the file descriptors passed to it.
  16.  
  17. One consequence is that child processes do not work properly in an
  18. emacs process started as "emacs >&- 2>&-".  A shell buffer, for
  19. example, exits immediately because of its input being closed.  If only
  20. one of the file descriptors is closed, as in "emacs >&-", the shell
  21. doesn't exit, but none of its output is visible.
  22.  
  23. If emacs is running on an ordinary terminal, it is unreasonable to
  24. expect it to work with file descriptors 1 and 2 closed.  However, if
  25. it is running as an X client, it seems reasonable that it should work
  26. properly even if file descriptors 1 and 2 are closed.  As a point of
  27. comparison, xterm works just fine if file descriptors 0, 1, and 2 are
  28. all closed.  The child code xterm uses to map its tty into the
  29. standard file descriptors looks like this:
  30.  
  31.  
  32.             for (i = 0; i <= 2; i++)
  33.             if (i != tty) {
  34.                 (void) close(i);
  35.                 (void) dup(tty);
  36.             }
  37.  
  38.  
  39. I don't have a patch which allows emacs child processes to work when
  40. file descriptors 1 and 2 are closed.  I see a few likely alternatives.
  41.  
  42.  
  43. 1)  Leave it as is, and don't worry about whether it is reasonable to
  44. run emacs with file descriptors 1 and 2 closed.
  45.  
  46. 2)  In the code that allocates a pty or pipe for a child process, check
  47. whether the file descriptors are bigger than 2; if not, dup them until
  48. they are.
  49.  
  50. 3)  Complicate the code in child_setup to handle file descriptors for
  51. in, out, and err which are less than 3.
  52.  
  53. 4)  In the emacs initialization, open file descriptors 1 and 2 if they
  54. are not already open.  Perhaps they could be opened as /dev/null if
  55. they are not already open, or dup'd to something else.
  56.  
  57.  
  58. Of these alternatives, the third and fourth seem the most robust.  The
  59. first one doesn't fix the problem, and the second one probably leaves
  60. some cases unfixed.  The problem, in essence, is that child_setup
  61. assumes its arguments never overlap the standard file descriptors.  It
  62. is both possible and (in my opinion) reasonable to violate this
  63. assumption.
  64.  
  65. If the fourth alternative is chosen, it might be reasonable to
  66. implement it in x_init_1 (which initializes X keyboard input), since
  67. it only seems reasonable to close file descriptors 1 and 2 when emacs
  68. is running as an X client.
  69.  
  70.