]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix for background jobs killed by SIGTERM being marked as notified
authorChet Ramey <chet.ramey@case.edu>
Fri, 9 Feb 2024 15:56:43 +0000 (10:56 -0500)
committerChet Ramey <chet.ramey@case.edu>
Fri, 9 Feb 2024 15:56:43 +0000 (10:56 -0500)
CWRU/CWRU.chlog
config-top.h
jobs.c
tests/printf6.sub

index 41ab1e4489a82b2d4a19d4490f32ee9185b5ff38..9498c76290ba291b023d8dc4f7226dc1e408b2a3 100644 (file)
@@ -1,4 +1,4 @@
-
+\
                                 12/6/2020
                                 ---------
 
@@ -8561,3 +8561,13 @@ bashline.c
 doc/bash.1,lib/readline/doc/readline.3
        - minor updates to handle old versions of troff and groff warnings
          Fixes from G. Branden Robinson <g.branden.robinson@gmail.com>
+
+                                   2/7
+                                   ---
+jobs.c
+       - notify_of_job_status: in non-interactive shells, if we're not going
+         to print information about a terminated background job
+         (SIGINT/SIGTERM/SIGPIPE), don't mark it as notified, in the same
+         way that we don't mark background jobs that exit cleanly as notified
+         Inspired by a discussion with Robert Elz <kre@munnari.oz.au> and
+         https://lists.gnu.org/archive/html/bug-bash/2024-01/msg00189.html
index 62b67096f43f9facccd698a7b0e4d41b8865a7cd..eaf9337b7c42d4658e669fdb9be288796451b5ab 100644 (file)
@@ -45,7 +45,7 @@
    when a job like `cat jobs.c | exit 1' terminates due to a SIGPIPE. */
 #define DONT_REPORT_SIGPIPE
 
-/* Define DONT_REPORT_SIGTERM if you don't want to see `Terminates' message
+/* Define DONT_REPORT_SIGTERM if you don't want to see `Terminated' message
    when a job exits due to SIGTERM, since that's the default signal sent
    by the kill builtin. */
 #define DONT_REPORT_SIGTERM
diff --git a/jobs.c b/jobs.c
index c0569c2e148cdd5c4701f1dddb1cf8644a11cfbe..caafa734a5b7157c221b3c0728b2da251939aa2f 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -4282,6 +4282,19 @@ notify_of_job_status (void)
                ((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 */
+         else if (startup_state == 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
+               ))
+           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
@@ -4304,7 +4317,7 @@ notify_of_job_status (void)
 
          /* 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:
@@ -4324,6 +4337,7 @@ notify_of_job_status (void)
                }
              else if (IS_FOREGROUND (job))
                {
+                 /* foreground jobs, interactive and non-interactive shells */
 #if !defined (DONT_REPORT_SIGPIPE)
                  if (termsig && WIFSIGNALED (s) && termsig != SIGINT)
 #else
@@ -4337,10 +4351,13 @@ notify_of_job_status (void)
 
                      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 ();
                  pretty_print_job (job, JLIST_STANDARD, stderr);
@@ -4349,16 +4366,9 @@ notify_of_job_status (void)
                             _("(wd now: %s)\n"), polite_directory_format (dir));
                }
 
-             /* This is where we set J_NOTIFIED for background jobs in
-                non-interactive shells without job control enabled that are
-                killed by SIGINT or SIGTERM (DONT_REPORT_SIGTERM) or SIGPIPE
-                (DONT_REPORT_SIGPIPE) as long as those signals are not
-                trapped, or that exit cleanly. 
-                Interactive shells without job control enabled are handled
+             /* Interactive shells without job control enabled are handled
                 above. */
-             /* XXX - if we want to arrange to keep these jobs in the jobs
-                list, instead of making them eligible to move to bgpids,
-                this is where to change things. */
+             /* XXX - this is a catch-all in case we missed a state */
              jobs[job]->flags |= J_NOTIFIED;
              break;
 
index fbacd4d53003b4c40978b1bafb335e1ce8dd17df..8a0af30078ce0996a118b4562038ff0d257ee5ca 100644 (file)
@@ -11,6 +11,8 @@
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
+LC_ALL=en_US.UTF-8
+
 # this should echo nothing
 printf '%ls'
 # this should echo a null byte