From 1126b096320937914bf78806218127aa275bc56f Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Fri, 8 Dec 2017 07:43:45 -0500 Subject: [PATCH] commit bash-20171205 snapshot --- CWRU/CWRU.chlog | 4 --- execute_cmd.c | 6 +--- jobs.c | 8 +++++ nojobs.c | 6 ++++ subst.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-- subst.h | 5 +++ tests/RUN-ONE-TEST | 2 +- 7 files changed, 100 insertions(+), 12 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 249b443d..d9750117 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -14545,7 +14545,3 @@ execute_cmd.c and a status and mark the coproc as dead and having been reaped with that status. Used by child processes who want to invalidate the coproc's pid - - coproc_closeall,cpl_closeall: call coproc_setstatus (to invalidate - pid) after closing a coproc (invalidating FDs). Fixes issue with - spurious warning reported by Tobias Hoffmann - diff --git a/execute_cmd.c b/execute_cmd.c index b22d6d6c..45bb8758 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -1848,10 +1848,7 @@ cpl_closeall () struct cpelement *cpe; for (cpe = coproc_list.head; cpe; cpe = cpe->next) - { - coproc_close (cpe->coproc); - coproc_setstatus (cpe->coproc, 0); /* fake zero status */ - } + coproc_close (cpe->coproc); } static void @@ -2052,7 +2049,6 @@ coproc_closeall () cpl_closeall (); #else coproc_close (&sh_coproc); /* XXX - will require changes for multiple coprocs */ - coproc_setstatus (&sh_coproc, 0); /* fake zero status */ #endif } diff --git a/jobs.c b/jobs.c index 079e096f..82e48034 100644 --- a/jobs.c +++ b/jobs.c @@ -3536,6 +3536,7 @@ waitchld (wpid, block) WAIT status; PROCESS *child; pid_t pid; + int ind; int call_set_current, last_stopped_job, job, children_exited, waitpid_flags; static int wcontinued = WCONTINUED; /* run-time fix for glibc problem */ @@ -3642,6 +3643,13 @@ itrace("waitchld: waitpid returns %d block = %d children_exited = %d", pid, bloc coproc_pidchk (pid, WSTATUS(status)); #endif +#if defined (PROCESS_SUBSTITUTION) + if ((ind = find_procsub_child (pid)) >= 0) + set_procsub_status (ind, pid, WSTATUS (status)); + /* XXX - save in bgpids list? */ +#endif + + /* It is not an error to have a child terminate that we did not have a record of. This child could have been part of a pipeline in backquote substitution. Even so, I'm not diff --git a/nojobs.c b/nojobs.c index 9ea33e88..1d00fc96 100644 --- a/nojobs.c +++ b/nojobs.c @@ -269,6 +269,12 @@ set_pid_status (pid, status) coproc_pidchk (pid, status); #endif +#if defined (PROCESS_SUBSTITUTION) + if ((ind = find_procsub_child (pid)) >= 0) + set_procsub_status (ind, pid, WSTATUS (status)); + /* XXX - also saving in list below */ +#endif + slot = find_index_by_pid (pid); if (slot == NO_PID) return; diff --git a/subst.c b/subst.c index da6c46ae..ca9e66a9 100644 --- a/subst.c +++ b/subst.c @@ -5365,6 +5365,43 @@ close_new_fifos (list, lsize) unlink_fifo (i); } +int +find_procsub_child (pid) + pid_t pid; +{ + int i; + + for (i = 0; i < nfifo; i++) + if ((fifo_list[i].proc == pid) + return i; + return -1; +} + +void +set_procsub_status (ind, pid, status) + int ind; + pid_t pid; + int status; +{ + if (ind >= 0 && ind < nfifo) + fifo_list[ind].proc = -2; /* sentinel */ +} + +/* If we've marked the process for this procsub as dead, close the + associated file descriptor and delete the FIFO. */ +void +reap_procsubs () +{ + int i; + + for (i = 0; i < nfifo; i++) + if (fifo_list[i].proc == -2) /* reaped */ + { + fifo_list[i].proc = -1; + unlink_fifo (ind); + } +} + int fifos_pending () { @@ -5502,7 +5539,7 @@ unlink_fifo_list () if (nfds == 0) return; - for (i = 0; nfds && i < totfds; i++) + for (i = totfds-1; nfds && i >= 0; i--) unlink_fifo (i); nfds = 0; @@ -5534,6 +5571,44 @@ close_new_fifos (list, lsize) unlink_fifo (i); } +int +find_procsub_child (pid) + pid_t pid; +{ + int i; + + if (nfds == 0) + return -1; + + for (i = 0; i < totfds; i++) + if (dev_fd_list[i] == pid) + return i; + + return -1; +} + +void +set_procsub_status (ind, pid, status) + int ind; + pid_t pid; + int status; +{ + if (ind >= 0 && ind < totfds) + dev_fd_list[ind] = -2; /* sentinel */ +} + +/* If we've marked the process for this procsub as dead, close the + associated file descriptor. */ +void +reap_procsubs () +{ + int i; + + for (i = 0; nfds > 0 && i < totfds; i++) + if (dev_fd_list[i] == -2) + unlink_fifo (i); +} + #if defined (NOTDEF) print_dev_fd_list () { @@ -5687,7 +5762,9 @@ process_substitute (string, open_for_read_in_child) last_procsub_child = restore_pipeline (0); #endif -#if !defined (HAVE_DEV_FD) +#if defined (HAVE_DEV_FD) + dev_fd_list[parent_pipe_fd] = pid; +#else fifo_list[nfifo-1].proc = pid; #endif diff --git a/subst.h b/subst.h index f1f1ccd9..97de442d 100644 --- a/subst.h +++ b/subst.h @@ -265,6 +265,7 @@ extern WORD_LIST *expand_words_shellexp __P((WORD_LIST *)); extern WORD_DESC *command_substitute __P((char *, int, int)); extern char *pat_subst __P((char *, char *, char *, int)); +#if defined (PROCESS_SUBSTITUTION) extern int fifos_pending __P((void)); extern int num_fifos __P((void)); extern void unlink_fifo_list __P((void)); @@ -276,6 +277,10 @@ extern void close_new_fifos __P((char *, int)); extern void clear_fifo_list __P((void)); +extern int find_procsub_child __P((pid_t)); +extern void set_procsub_status __P((int, pid_t, int)); +#endif + extern WORD_LIST *list_string_with_quotes __P((char *)); #if defined (ARRAY_VARS) diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 58c375b7..554f3d6e 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -BUILD_DIR=/usr/local/build/chet/bash/bash-current +BUILD_DIR=/usr/local/build/bash/bash-current THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR