[PATCH] Remove maybe_give_terminal_to() race

2023-09-10 Thread Earl Chew
parent. Signed-off-by: Earl Chew --- jobs.c | 44 +--- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/jobs.c b/jobs.c index da47cf71..79006e14 100644 --- a/jobs.c +++ b/jobs.c @@ -283,7 +283,6 @@ static void set_current_job (int); static void

Re: give_terminal_to() / maybe_give_terminal_to() race

2023-09-07 Thread Earl Chew
On 2023-09-05 08:46, Chet Ramey wrote: Such as? If the parent doesn't need to change the terminal process group, synchronizes with the pipeline via waitpid(), and doesn't attempt to change the terminal process group back until all children in that process group have stopped or exited, what conseq

Re: give_terminal_to() / maybe_give_terminal_to() race

2023-09-02 Thread Earl Chew
On 2023-09-01 09:07, Chet Ramey wrote: On 9/1/23 11:48 AM, Earl Chew wrote: What remains might be whether there is value in maintaining the present barrier in both parent and child so that it is straightforward to reason about designation of the foreground process in the controlling terminal

Re: give_terminal_to() / maybe_give_terminal_to() race

2023-09-01 Thread Earl Chew
On 2023-09-01 04:58, Martin D Kealey wrote: On Fri, 1 Sep 2023, 15:51 Earl Chew, <mailto:earl_c...@yahoo.com>> wrote: The controlling terminal must be reconfigured before the parent gets to wait() for the job, and before the child gets to exec() the program (or their eq

Re: give_terminal_to() / maybe_give_terminal_to() race

2023-08-31 Thread Earl Chew
On 2023-08-30 07:39, Chet Ramey wrote: OK, so there is a potential race condition here. What do you suggest the right approach might be? It seems to me we can do one of two things: rearrange and extend the PGRP_PIPE code to make sure the child process doesn't proceed until the parent sets the ter

Re: [PATCH] Use SIGCONT to avoid fg tcsetpgrp() SIGTTIN/SIGTTOU race

2023-08-30 Thread Earl Chew
> I applied a fix for that on 7/24 and it's in devel branch commit Oh ... I hadn't realised you had already applied a fix. Thanks. Earl

Re: give_terminal_to() / maybe_give_terminal_to() race

2023-08-27 Thread Earl Chew
> It is possible to demonstrate this with some effort using > a small C program. For completeness this is an example of a program to reproduce the issue: DIE("tcgetpgrp"). The failure window is small, so many iterations and a diverse host workload is required to demonstrate the issue. Alternative

give_terminal_to() / maybe_give_terminal_to() race

2023-08-25 Thread Earl Chew
A newly created process of a foreground job races the parent shell to configure the controlling terminal. This can result in the parent shell stealing the controlling terminal from a grandchild, and giving it to the child. I think stop_pipeline() needs to be fixed to be more cautious. What might

[PATCH] Use SIGCONT to avoid fg tcsetpgrp() SIGTTIN/SIGTTOU race

2023-08-25 Thread Earl Chew
-- ${1%.*} ${2%.*} set -- "$@" $(rand) set -- "$@" $(rand) set -- $1.$3 $2.$4 race "$@" done } main "$@" Signed-off-by: Earl Chew --- jobs.c | 22 ++ 1 file changed, 14 i

fg tcsetpgrp() SIGTTIN/SIGTTOU race

2023-07-19 Thread Earl Chew
Bash uses tcsetpgrp() to move a program to the foreground, and conditionally resumes the program with SIGCONT if the program was stopped. Consider the following script: $ ( cmd1 ; read X ; cmd2 ) & $ ... $ fg When fg is issued, the background program is either stopped, or running. The