BASH PATCH REPORT
			     =================

Bash-Release:	5.2
Patch-ID:	bash52-030

Bug-Reported-by:	Steven Pelley <stevenpelley@gmail.com>
Bug-Reference-ID:	<CAGOYURh6CKaE-D0Z8puP-tQknavCQNRHo02vpvgMQqaTG3_cRw@mail.gmail.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2024-01/msg00104.html

Bug-Description:

`wait -n' can fail to return some jobs if they exit due to signals the shell
does not report to the user.

Patch (apply with `patch -p0'):

*** ../bash-5.2-patched/jobs.c	Thu Nov  9 14:59:14 2023
--- jobs.c	Tue Jul 30 15:27:44 2024
***************
*** 4275,4279 ****
  		((DEADJOB (job) && IS_FOREGROUND (job) == 0) || STOPPED (job)))
  	    continue;
! 	  
  	  /* If job control is disabled, don't print the status messages.
  	     Mark dead jobs as notified so that they get cleaned up.  If
--- 4288,4312 ----
  		((DEADJOB (job) && IS_FOREGROUND (job) == 0) || STOPPED (job)))
  	    continue;
! 
! 	  /* Do the same thing and don't print anything or mark as notified
! 	     for the signals we're not going to report on. This is the opposite
! 	     of the first two cases under case JDEAD below. */
! 	  else if (interactive_shell == 0 && DEADJOB (job) && IS_FOREGROUND (job) == 0 &&
! 		WIFSIGNALED (s) && (termsig == SIGINT
! #if defined (DONT_REPORT_SIGTERM)
! 		|| termsig == SIGTERM
! #endif
! #if defined (DONT_REPORT_SIGPIPE)
! 		|| termsig == SIGPIPE
! #endif
! 		|| signal_is_trapped (termsig)))
! 	    continue;
! 
! 	  /* hang onto the status if the shell is running -c command */
! 	  else if (startup_state == 2 && subshell_environment == 0 &&
! 		WIFSIGNALED (s) == 0 &&
! 		((DEADJOB (job) && IS_FOREGROUND (job) == 0) || STOPPED (job)))
! 	    continue;
! 
  	  /* If job control is disabled, don't print the status messages.
  	     Mark dead jobs as notified so that they get cleaned up.  If
***************
*** 4298,4302 ****
  	  /* Print info on jobs that are running in the background,
  	     and on foreground jobs that were killed by anything
! 	     except SIGINT (and possibly SIGPIPE). */
  	  switch (JOBSTATE (job))
  	    {
--- 4331,4335 ----
  	  /* Print info on jobs that are running in the background,
  	     and on foreground jobs that were killed by anything
! 	     except SIGINT (and possibly SIGTERM and SIGPIPE). */
  	  switch (JOBSTATE (job))
  	    {
***************
*** 4318,4321 ****
--- 4351,4355 ----
  	      else if (IS_FOREGROUND (job))
  		{
+ 		  /* foreground jobs, interactive and non-interactive shells */
  #if !defined (DONT_REPORT_SIGPIPE)
  		  if (termsig && WIFSIGNALED (s) && termsig != SIGINT)
***************
*** 4331,4337 ****
  		      fprintf (stderr, "\n");
  		    }
  		}
! 	      else if (job_control)	/* XXX job control test added */
  		{
  		  if (dir == 0)
  		    dir = current_working_directory ();
--- 4365,4375 ----
  		      fprintf (stderr, "\n");
  		    }
+ 		  /* foreground jobs that exit cleanly */
+ 		  jobs[job]->flags |= J_NOTIFIED;
  		}
! 	      else if (job_control)
  		{
+ 		  /* background jobs with job control, interactive and
+ 		     non-interactive shells */
  		  if (dir == 0)
  		    dir = current_working_directory ();
***************
*** 4342,4346 ****
  		}
  
! 	      jobs[job]->flags |= J_NOTIFIED;
  	      break;
  
--- 4380,4391 ----
  		}
  
! 	      /* Interactive shells without job control enabled are handled
! 		 above. */
! 	      /* XXX - this is a catch-all in case we missed a state */
! 	      else
! {
! internal_debug("notify_of_job_status: catch-all setting J_NOTIFIED on job %d (%d), startup state = %d", job, jobs[job]->flags, startup_state);
! 		jobs[job]->flags |= J_NOTIFIED;
! }
  	      break;
  

*** ../bash-5.2/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 29
  
  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 30
  
  #endif /* _PATCHLEVEL_H_ */