about summary refs log tree commit diff
path: root/Src/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/init.c')
-rw-r--r--Src/init.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Src/init.c b/Src/init.c
index 08fd2a4c4..5a6139438 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -401,7 +401,10 @@ init_io(void)
     if (opts[MONITOR] && interact && (SHTTY != -1)) {
 	if ((mypgrp = GETPGRP()) > 0) {
 	    while ((ttpgrp = gettygrp()) != -1 && ttpgrp != mypgrp) {
+		sleep(1);	/* give parent time to change pgrp */
 		mypgrp = GETPGRP();
+		if (mypgrp == mypid)
+		    attachtty(mypgrp);
 		if (mypgrp == gettygrp())
 		    break;
 		killpg(mypgrp, SIGTTIN);
@@ -411,7 +414,6 @@ init_io(void)
 	    opts[MONITOR] = 0;
     } else
 	opts[MONITOR] = 0;
-    attachtty(GETPGRP());
 #else
     opts[MONITOR] = 0;
 #endif