diff --git a/jobs.c b/jobs.c index cef3c79..4cabf12 100644 --- a/jobs.c +++ b/jobs.c @@ -3619,9 +3619,45 @@ itrace("waitchld: waitpid returns %d block = %d children_exited = %d", pid, bloc if (asynchronous_notification && interactive) notify_of_job_status (); + remember_job_exit_status(); + return (children_exited); } +void remember_job_exit_status() +{ + register int job; + PROCESS *pipe; + SHELL_VAR *v; + ARRAY *a; + ARRAY_ELEMENT *ae; + register int i; + char *t, tbuf[INT_STRLEN_BOUND(int) + 1]; + + v = find_variable ("JOB_PIPESTATUS"); + if (v == 0) + v = make_new_array_variable ("JOB_PIPESTATUS"); + if (array_p (v) == 0) + return; /* Do nothing if not an array variable. */ + a = array_cell (v); + t = &tbuf; + + for (job = 0; job < js.j_jobslots; job++) + { + if(jobs[job] && IS_FOREGROUND (job) == 0) + { + for(pipe = jobs[job]->pipe; ; pipe = pipe->next) + { + if(pipe->running){ t += sprintf(t, "-"); } + else{ t += sprintf(t, "%d", WSTATUS(pipe->status)); } + if(pipe->next == jobs[job]->pipe) break; + t += sprintf(t, " "); + } + array_insert (a, pipe->pid, tbuf); + } + } +} + /* Set the status of JOB and perform any necessary cleanup if the job is marked as JDEAD.