comparison src/sysdep.c @ 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 1d2f73785d9d
children 03a73693678e
comparison
equal deleted inserted replaced
83034:759de0673597 83035:fcf6fc349e0d
1103 situation, we put ourselves in our own pgroup, forcibly set the 1103 situation, we put ourselves in our own pgroup, forcibly set the
1104 tty's pgroup to our pgroup, and make sure to restore and reinstate 1104 tty's pgroup to our pgroup, and make sure to restore and reinstate
1105 the tty's pgroup just like any other terminal setting. If 1105 the tty's pgroup just like any other terminal setting. If
1106 inherited_group was not the tty's pgroup, then we'll get a 1106 inherited_group was not the tty's pgroup, then we'll get a
1107 SIGTTmumble when we try to change the tty's pgroup, and a CONT if 1107 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1108 it goes foreground in the future, which is what should happen. */ 1108 it goes foreground in the future, which is what should happen.
1109
1110 This variable is initialized in emacs.c. */
1109 int inherited_pgroup; 1111 int inherited_pgroup;
1110 1112
1111 /* Split off the foreground process group to Emacs alone. 1113 /* Split off the foreground process group to Emacs alone. When we are
1112 When we are in the foreground, but not started in our own process 1114 in the foreground, but not started in our own process group,
1113 group, redirect the TTY to point to our own process group. We need 1115 redirect the tty device handle FD to point to our own process
1114 to be in our own process group to receive SIGIO properly. */ 1116 group. We need to be in our own process group to receive SIGIO
1117 properly. */
1115 void 1118 void
1116 narrow_foreground_group (int fd) 1119 narrow_foreground_group (int fd)
1117 { 1120 {
1118 int me = getpid (); 1121 int me = getpid ();
1119 1122
1123 setpgrp (0, inherited_pgroup);
1120 if (! inherited_pgroup) 1124 if (! inherited_pgroup)
1121 inherited_pgroup = getpgid (0); 1125 abort (); /* Should not happen. */
1122 /* XXX This only works on the controlling tty. */
1123 if (inherited_pgroup != me) 1126 if (inherited_pgroup != me)
1124 EMACS_SET_TTY_PGRP (fd, &me); 1127 EMACS_SET_TTY_PGRP (fd, &me); /* XXX This only works on the controlling tty. */
1125 setpgid (0, me); 1128 setpgrp (0, me);
1126 } 1129 }
1127 1130
1128 /* Set the tty to our original foreground group. */ 1131 /* Set the tty to our original foreground group. */
1129 void 1132 void
1130 widen_foreground_group (int fd) 1133 widen_foreground_group (int fd)
1131 { 1134 {
1132 if (inherited_pgroup != getpid ()) 1135 if (inherited_pgroup != getpid ())
1133 EMACS_SET_TTY_PGRP (fd, &inherited_pgroup); 1136 EMACS_SET_TTY_PGRP (fd, &inherited_pgroup);
1134 setpgid (0, inherited_pgroup); 1137 setpgrp (0, inherited_pgroup);
1135 } 1138 }
1136 1139
1137 #endif /* BSD_PGRPS */ 1140 #endif /* BSD_PGRPS */
1138 1141
1139 /* Getting and setting emacs_tty structures. */ 1142 /* Getting and setting emacs_tty structures. */