From 6609fa34057edfb842b2ca234db488fe4da982cc Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 7 Sep 2025 10:16:54 +0100 Subject: ash: jobs: Block signals during tcsetpgrp Merge upstream commit 4ce8afe6b. This has no effect on Windows. --- shell/ash.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 09e9ef605..408027305 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -4712,7 +4712,22 @@ freejob(struct job *jp) static void xtcsetpgrp(int fd, pid_t pgrp) { - if (tcsetpgrp(fd, pgrp)) + int err; + + sigblockall(NULL); + err = tcsetpgrp(fd, pgrp); + sigclearmask(); + // Unmasking signals would cause any arrived signal to trigger, so why? + // Generally yes, but there are exceptions. Such as: + // """ + // Attempts to use tcsetpgrp() from a process which is a member of + // a background process group on a fd associated with its controlling + // terminal shall cause the process group to be sent a SIGTTOU signal. + // If the calling thread is blocking SIGTTOU signals or the process + // is ignoring SIGTTOU signals, the process shall be allowed + // to perform the operation, and no signal is sent.""" + + if (err) ash_msg_and_raise_perror("can't set tty process group"); } -- cgit v1.2.3-55-g6feb