changeset 83035:fcf6fc349e0d

Don't hang on the tty if called from a shell script. src/sysdep.c (narrow_foreground_group): Set the process group to inherited_pgroup before calling EMACS_SET_TTY_PGRP. Removed confusing inherited_pgroup initialization (it is done in emacs.c). (Reported by Istvan Marko <mi-mtty at kismala dot com>.) git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-75
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 08 Feb 2004 15:44:33 +0000
parents 759de0673597
children fc638739c70f
files README.multi-tty src/sysdep.c
diffstat 2 files changed, 27 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/README.multi-tty	Tue Feb 03 11:25:07 2004 +0000
+++ b/README.multi-tty	Sun Feb 08 15:44:33 2004 +0000
@@ -164,11 +164,11 @@
 Robert J. Chassel <bob at rattlesnake dot com>
 Romain Francoise <romain at orekobech dot com>
 Ami Fischman <ami at fischman dot org>
+Istvan Marko <mi-mtty ar kismala dot com>
 Dan Nicolaescu <dann at ics dot uci dot edu>
 
 Richard Stallman was kind enough to review my patches.
 
-
 CHANGELOG
 ---------
 
@@ -176,6 +176,12 @@
 
 THINGS TO DO
 ------------
+
+** There is a flicker during the startup of `emacs -nw'; it's as if
+   the terminal is initialized, reset and then initialialized again.
+   Debug this.  (Hint: narrow_foreground_group is called twice during
+   startup.)
+
 ** Dan Nicolaescu (dann at ics dot uci dot edu) suggests that -nw
    should be added as an alias for -t in emacsclient.  Good idea.
    (Alas, implementing this is not trivial, getopt_long does not seem
@@ -649,4 +655,11 @@
 
    (Fixed.)
 
+-- Istvan Marko reported that Emacs hang on ttys if it was started
+   from a shell script.
+
+   (Fixed.  There was a bug in the multi-tty version of
+   narrow_foreground_group.  tcsetpgrp blocks if it is called from a
+   process that is not in the same process group as the tty.)
+
 ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d
--- a/src/sysdep.c	Tue Feb 03 11:25:07 2004 +0000
+++ b/src/sysdep.c	Sun Feb 08 15:44:33 2004 +0000
@@ -1105,24 +1105,27 @@
    the tty's pgroup just like any other terminal setting.  If
    inherited_group was not the tty's pgroup, then we'll get a
    SIGTTmumble when we try to change the tty's pgroup, and a CONT if
-   it goes foreground in the future, which is what should happen.  */
+   it goes foreground in the future, which is what should happen.
+
+   This variable is initialized in emacs.c.  */
 int inherited_pgroup;
 
-/* Split off the foreground process group to Emacs alone.
-   When we are in the foreground, but not started in our own process
-   group, redirect the TTY to point to our own process group.  We need
-   to be in our own process group to receive SIGIO properly.  */
+/* Split off the foreground process group to Emacs alone.  When we are
+   in the foreground, but not started in our own process group,
+   redirect the tty device handle FD to point to our own process
+   group.  We need to be in our own process group to receive SIGIO
+   properly.  */
 void
 narrow_foreground_group (int fd)
 {
   int me = getpid ();
 
+  setpgrp (0, inherited_pgroup);
   if (! inherited_pgroup)
-    inherited_pgroup = getpgid (0);
-  /* XXX This only works on the controlling tty. */
+    abort ();                   /* Should not happen. */
   if (inherited_pgroup != me)
-    EMACS_SET_TTY_PGRP (fd, &me);
-  setpgid (0, me);
+      EMACS_SET_TTY_PGRP (fd, &me); /* XXX This only works on the controlling tty. */
+  setpgrp (0, me);
 }
 
 /* Set the tty to our original foreground group.  */
@@ -1131,7 +1134,7 @@
 {
   if (inherited_pgroup != getpid ())
     EMACS_SET_TTY_PGRP (fd, &inherited_pgroup);
-  setpgid (0, inherited_pgroup);
+  setpgrp (0, inherited_pgroup);
 }
 
 #endif /* BSD_PGRPS */