fix small race condition when using lastpipe and adding the last process to the pipeline; fix bug that could cause the shell to exit even if execfail' is enabled if errexit' is enabled and the pathname to exec doesn't exist

This commit is contained in:
Chet Ramey
2026-10-07 10:36:29 -04:00
parent 1c20880e16
commit 7cfdb340d2
10 changed files with 5854 additions and 21 deletions
+6 -2
View File
@@ -2769,6 +2769,7 @@ execute_pipeline (COMMAND *command, int asynchronous, int pipe_in, int pipe_out,
begin_unwind_frame ("lastpipe-exec");
lstdin = -2; /* -1 is special, meaning fd 0 is closed */
lastpipe_jid = NO_JOB;
/* If the `lastpipe' option is set with shopt, and job control is not
enabled, execute the last element of non-async pipelines in the
current shell environment. */
@@ -2807,7 +2808,8 @@ execute_pipeline (COMMAND *command, int asynchronous, int pipe_in, int pipe_out,
restore_stdin (lstdin);
#if defined (JOB_CONTROL)
UNBLOCK_CHILD (oset);
if (lastpipe_jid == NO_JOB) /* already unblocked above */
UNBLOCK_CHILD (oset);
#endif
QUIT;
@@ -2817,7 +2819,9 @@ execute_pipeline (COMMAND *command, int asynchronous, int pipe_in, int pipe_out,
#if defined (JOB_CONTROL)
if (INVALID_JOB (lastpipe_jid) == 0)
{
BLOCK_CHILD (set, oset);
append_process (savestring (the_printed_command_except_trap), dollar_dollar_pid, exec_result, lastpipe_jid);
UNBLOCK_CHILD (oset);
lstdin = wait_for (lastpid, 0);
}
else
@@ -2893,7 +2897,7 @@ execute_list (COMMAND *command, int asynchronous, int pipe_in, int pipe_out, str
QUIT;
n = count_nodes (command);
/*itrace("execute_list: count_nodes returns %d", n);*/
/*itrace("execute_list: count_nodes returns %d", n);*/
csind = cssize = n + 1;
cstack = (COMMAND **) xreallocarray (NULL, cssize, sizeof (COMMAND *));