]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
Bash-5.2 patch 30: fix bug with marking jobs terminated by signals as notified
authorChet Ramey <chet.ramey@case.edu>
Thu, 1 Aug 2024 15:36:07 +0000 (11:36 -0400)
committerChet Ramey <chet.ramey@case.edu>
Thu, 1 Aug 2024 15:36:07 +0000 (11:36 -0400)
jobs.c
patchlevel.h

diff --git a/jobs.c b/jobs.c
index b96230fa7226a0683684d61d82ba07c9da343db6..d3e4ab05e362e06453843c6f291346a7d8033b51 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -4274,7 +4274,27 @@ notify_of_job_status ()
          if (startup_state == 0 && WIFSIGNALED (s) == 0 &&
                ((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
             startup_state == 2 and subshell_environment has the
@@ -4297,7 +4317,7 @@ notify_of_job_status ()
 
          /* Print info on jobs that are running in the background,
             and on foreground jobs that were killed by anything
-            except SIGINT (and possibly SIGPIPE). */
+            except SIGINT (and possibly SIGTERM and SIGPIPE). */
          switch (JOBSTATE (job))
            {
            case JDEAD:
@@ -4317,6 +4337,7 @@ notify_of_job_status ()
                }
              else if (IS_FOREGROUND (job))
                {
+                 /* foreground jobs, interactive and non-interactive shells */
 #if !defined (DONT_REPORT_SIGPIPE)
                  if (termsig && WIFSIGNALED (s) && termsig != SIGINT)
 #else
@@ -4330,9 +4351,13 @@ notify_of_job_status ()
 
                      fprintf (stderr, "\n");
                    }
+                 /* foreground jobs that exit cleanly */
+                 jobs[job]->flags |= J_NOTIFIED;
                }
-             else if (job_control)     /* XXX job control test added */
+             else if (job_control)
                {
+                 /* background jobs with job control, interactive and
+                    non-interactive shells */
                  if (dir == 0)
                    dir = current_working_directory ();
                  pretty_print_job (job, JLIST_STANDARD, stderr);
@@ -4341,7 +4366,14 @@ notify_of_job_status ()
                             _("(wd now: %s)\n"), polite_directory_format (dir));
                }
 
-             jobs[job]->flags |= J_NOTIFIED;
+             /* 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;
 
            case JSTOPPED:
index 386e1197b00d4e9bebf152f4d6d8928aaee2b6ad..5998c62ff41cccc94a7107ba17442e3d3fa5ee0a 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 29
+#define PATCHLEVEL 30
 
 #endif /* _PATCHLEVEL_H_ */