Skip to content

Commit 6e45e75

Browse files
author
Chet Ramey
committedAug 1, 2024
Bash-5.2 patch 30: fix bug with marking jobs terminated by signals as notified
1 parent bc3e91d commit 6e45e75

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed
 

‎jobs.c

+36-4
Original file line numberDiff line numberDiff line change
@@ -4274,7 +4274,27 @@ notify_of_job_status ()
42744274
if (startup_state == 0 && WIFSIGNALED (s) == 0 &&
42754275
((DEADJOB (job) && IS_FOREGROUND (job) == 0) || STOPPED (job)))
42764276
continue;
4277-
4277+
4278+
/* Do the same thing and don't print anything or mark as notified
4279+
for the signals we're not going to report on. This is the opposite
4280+
of the first two cases under case JDEAD below. */
4281+
else if (interactive_shell == 0 && DEADJOB (job) && IS_FOREGROUND (job) == 0 &&
4282+
WIFSIGNALED (s) && (termsig == SIGINT
4283+
#if defined (DONT_REPORT_SIGTERM)
4284+
|| termsig == SIGTERM
4285+
#endif
4286+
#if defined (DONT_REPORT_SIGPIPE)
4287+
|| termsig == SIGPIPE
4288+
#endif
4289+
|| signal_is_trapped (termsig)))
4290+
continue;
4291+
4292+
/* hang onto the status if the shell is running -c command */
4293+
else if (startup_state == 2 && subshell_environment == 0 &&
4294+
WIFSIGNALED (s) == 0 &&
4295+
((DEADJOB (job) && IS_FOREGROUND (job) == 0) || STOPPED (job)))
4296+
continue;
4297+
42784298
/* If job control is disabled, don't print the status messages.
42794299
Mark dead jobs as notified so that they get cleaned up. If
42804300
startup_state == 2 and subshell_environment has the
@@ -4297,7 +4317,7 @@ notify_of_job_status ()
42974317

42984318
/* Print info on jobs that are running in the background,
42994319
and on foreground jobs that were killed by anything
4300-
except SIGINT (and possibly SIGPIPE). */
4320+
except SIGINT (and possibly SIGTERM and SIGPIPE). */
43014321
switch (JOBSTATE (job))
43024322
{
43034323
case JDEAD:
@@ -4317,6 +4337,7 @@ notify_of_job_status ()
43174337
}
43184338
else if (IS_FOREGROUND (job))
43194339
{
4340+
/* foreground jobs, interactive and non-interactive shells */
43204341
#if !defined (DONT_REPORT_SIGPIPE)
43214342
if (termsig && WIFSIGNALED (s) && termsig != SIGINT)
43224343
#else
@@ -4330,9 +4351,13 @@ notify_of_job_status ()
43304351

43314352
fprintf (stderr, "\n");
43324353
}
4354+
/* foreground jobs that exit cleanly */
4355+
jobs[job]->flags |= J_NOTIFIED;
43334356
}
4334-
else if (job_control) /* XXX job control test added */
4357+
else if (job_control)
43354358
{
4359+
/* background jobs with job control, interactive and
4360+
non-interactive shells */
43364361
if (dir == 0)
43374362
dir = current_working_directory ();
43384363
pretty_print_job (job, JLIST_STANDARD, stderr);
@@ -4341,7 +4366,14 @@ notify_of_job_status ()
43414366
_("(wd now: %s)\n"), polite_directory_format (dir));
43424367
}
43434368

4344-
jobs[job]->flags |= J_NOTIFIED;
4369+
/* Interactive shells without job control enabled are handled
4370+
above. */
4371+
/* XXX - this is a catch-all in case we missed a state */
4372+
else
4373+
{
4374+
internal_debug("notify_of_job_status: catch-all setting J_NOTIFIED on job %d (%d), startup state = %d", job, jobs[job]->flags, startup_state);
4375+
jobs[job]->flags |= J_NOTIFIED;
4376+
}
43454377
break;
43464378

43474379
case JSTOPPED:

‎patchlevel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
2626
looks for to find the patch level (for the sccs version string). */
2727

28-
#define PATCHLEVEL 29
28+
#define PATCHLEVEL 30
2929

3030
#endif /* _PATCHLEVEL_H_ */

0 commit comments

Comments
 (0)
Please sign in to comment.