Example: $ true | true | true | false | true | false $ echo $PIPESTAT 0 0 0 256 0 256
Signed-off-by: Tomas Mudrunka <[email protected]> --- shell/ash.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index bbd730770..a379f8b16 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -4602,6 +4602,8 @@ getstatus(struct job *job) int status; int retval; struct procstat *ps; + char pipestat[job->nprocs*24] = {}; + size_t pipestat_offset = 0; /* Fetch last member's status */ ps = job->ps + job->nprocs - 1; @@ -4612,6 +4614,14 @@ getstatus(struct job *job) status = ps->ps_status; } + /* Set $PIPESTAT */ + ps = job->ps; + for (ps = job->ps ; ps < job->ps+job->nprocs; ps++) { + pipestat_offset += sprintf(pipestat+pipestat_offset, "%d%c", + ps->ps_status, *(ifsset() ? ifsval() : defifs)); + } + setvar0("PIPESTAT", pipestat); + retval = WEXITSTATUS(status); if (!WIFEXITED(status)) { #if JOBS @@ -4628,8 +4638,8 @@ getstatus(struct job *job) } retval |= 128; } - TRACE(("getstatus: job %d, nproc %d, status 0x%x, retval 0x%x\n", - jobno(job), job->nprocs, status, retval)); + TRACE(("getstatus: job %d, nproc %d, status 0x%x, retval 0x%x, pipestat %s\n", + jobno(job), job->nprocs, status, retval, pipestat)); return retval; } @@ -5407,6 +5417,7 @@ waitforjob(struct job *jp) * $ _ */ dowait(jp ? DOWAIT_BLOCK : DOWAIT_NONBLOCK, jp); + setvar0("PIPESTAT", NULL); if (!jp) return exitstatus; -- 2.48.1 _______________________________________________ busybox mailing list [email protected] https://lists.busybox.net/mailman/listinfo/busybox
