]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
Bash-5.2 patch 19: fix case where background job set the terminal process group
authorChet Ramey <chet.ramey@case.edu>
Thu, 9 Nov 2023 21:45:56 +0000 (16:45 -0500)
committerChet Ramey <chet.ramey@case.edu>
Thu, 9 Nov 2023 21:45:56 +0000 (16:45 -0500)
jobs.c
patchlevel.h

diff --git a/jobs.c b/jobs.c
index 45869dd8193f04986fa0f3c2db33f6ae78a6e408..b96230fa7226a0683684d61d82ba07c9da343db6 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -3077,9 +3077,13 @@ if (job == NO_JOB)
       /* Don't modify terminal pgrp if we are running in background or a
         subshell.  Make sure subst.c:command_substitute uses the same
         conditions to determine whether or not it should undo this and
-        give the terminal to pipeline_pgrp. */
-      
+        give the terminal to pipeline_pgrp. We don't give the terminal
+        back to shell_pgrp if an async job in the background exits because
+        we never gave it to that job in the first place. An async job in
+        the foreground is one we started in the background and foregrounded
+        with `fg', and gave it the terminal. */
       if ((flags & JWAIT_NOTERM) == 0 && running_in_background == 0 &&
+         (job == NO_JOB || IS_ASYNC (job) == 0 || IS_FOREGROUND (job)) &&
          (subshell_environment & (SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0)
        give_terminal_to (shell_pgrp, 0);
     }
@@ -3623,6 +3627,7 @@ start_job (job, foreground)
     {
       get_tty_state ();
       save_stty = shell_tty_info;
+      jobs[job]->flags &= ~J_ASYNC;    /* no longer async */
       /* Give the terminal to this job. */
       if (IS_JOBCONTROL (job))
        give_terminal_to (jobs[job]->pgrp, 0);
index d4b06906b54df62b6c069b471e32f2631414a404..88059dee098f668b331a7309ad05c93431a29fe1 100644 (file)
@@ -25,6 +25,6 @@
    regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
    looks for to find the patch level (for the sccs version string). */
 
-#define PATCHLEVEL 18
+#define PATCHLEVEL 19
 
 #endif /* _PATCHLEVEL_H_ */