*** ../bash-20190517/jobs.c 2019-04-12 15:15:10.000000000 -0400 --- jobs.c 2019-05-25 18:03:47.000000000 -0400 *************** *** 244,247 **** --- 244,248 ---- static int waitchld __P((pid_t, int)); + static PROCESS *find_pid_in_pipeline __P((pid_t, PROCESS *, int)); static PROCESS *find_pipeline __P((pid_t, int, int *)); static PROCESS *find_process __P((pid_t, int, int *)); *************** *** 1493,1496 **** --- 1494,1518 ---- } + static PROCESS * + find_pid_in_pipeline (pid, pipeline, alive_only) + pid_t pid; + PROCESS *pipeline; + int alive_only; + { + PROCESS *p; + + p = pipeline; + do + { + /* Return it if we found it. Don't ever return a recycled pid. */ + if (p->pid == pid && ((alive_only == 0 && PRECYCLED(p) == 0) || PALIVE(p))) + return (p); + + p = p->next; + } + while (p != pipeline); + return ((PROCESS *)NULL); + } + /* Return the pipeline that PID belongs to. Note that the pipeline doesn't have to belong to a job. Must be called with SIGCHLD blocked. *************** *** 1504,1538 **** int job; PROCESS *p; /* See if this process is in the pipeline that we are building. */ if (jobp) *jobp = NO_JOB; ! if (the_pipeline) ! { ! p = the_pipeline; ! do ! { ! /* Return it if we found it. Don't ever return a recycled pid. */ ! if (p->pid == pid && ((alive_only == 0 && PRECYCLED(p) == 0) || PALIVE(p))) ! return (p); ! p = p->next; ! } ! while (p != the_pipeline); ! } /* Now look in the last process substitution pipeline, since that sets $! */ ! if (last_procsub_child) ! { ! p = last_procsub_child; ! do ! { ! /* Return it if we found it. Don't ever return a recycled pid. */ ! if (p->pid == pid && ((alive_only == 0 && PRECYCLED(p) == 0) || PALIVE(p))) ! return (p); ! ! p = p->next; ! } ! while (p != last_procsub_child); ! } job = find_job (pid, alive_only, &p); --- 1526,1546 ---- int job; PROCESS *p; + struct pipeline_saver *save; /* See if this process is in the pipeline that we are building. */ + p = (PROCESS *)NULL; if (jobp) *jobp = NO_JOB; ! if (the_pipeline && (p = find_pid_in_pipeline (pid, the_pipeline, alive_only))) ! return (p); ! /* Is this process in a saved pipeline? */ ! for (save = saved_pipeline; save; save = save->next) ! if (save->pipeline && (p = find_pid_in_pipeline (pid, save->pipeline, alive_only))) ! return (p); ! /* Now look in the last process substitution pipeline, since that sets $! */ ! if (last_procsub_child && (p = find_pid_in_pipeline (pid, last_procsub_child, alive_only))) ! return (p); job = find_job (pid, alive_only, &p);