From 8c25d92e11b57aad056d34af3c2269aad586f659 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 28 Oct 2019 11:56:19 +0000 Subject: 44864: Avoid inifinite loop in tty init. If we can't grab the terminal in interactive mode, give up after 100 goes. This is a completely arbitrary choice; we simply don't know what in the system could change the result of looping further. --- Src/jobs.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Src') diff --git a/Src/jobs.c b/Src/jobs.c index 50751decb..c06cb9c79 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -2933,6 +2933,7 @@ acquire_pgrp(void) sigaddset(&blockset, SIGTTOU); sigaddset(&blockset, SIGTSTP); oldset = signal_block(blockset); + int loop_count = 0; while ((ttpgrp = gettygrp()) != -1 && ttpgrp != mypgrp) { mypgrp = GETPGRP(); if (mypgrp == mypid) { @@ -2948,8 +2949,21 @@ acquire_pgrp(void) if (read(0, NULL, 0) != 0) {} /* Might generate SIGT* */ signal_block(blockset); mypgrp = GETPGRP(); - if (mypgrp == lastpgrp && !interact) - break; /* Unlikely that pgrp will ever change */ + if (mypgrp == lastpgrp) { + if (!interact) + break; /* Unlikely that pgrp will ever change */ + if (++loop_count == 100) + { + /* + * It's time to give up. The count is arbitrary; + * this is just to fix up unusual cases, so it's + * left large in an attempt not to break normal + * cases where there's some delay in the system + * setting up the terminal. + */ + break; + } + } lastpgrp = mypgrp; } if (mypgrp != mypid) { -- cgit 1.4.1