diff options
author | Michael Abbott <michael@araneidae.co.uk> | 2009-12-04 23:03:29 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-04 23:03:29 +0100 |
commit | 359da5e3be3dfb15913c4e76d0b4a27b6400adc5 (patch) | |
tree | 8eef0b4ffa53019e8300f7cf58bcf84621e2f074 | |
parent | 285ad155c4769e4a37a936826ba41e402f7d863b (diff) | |
download | busybox-w32-359da5e3be3dfb15913c4e76d0b4a27b6400adc5.tar.gz busybox-w32-359da5e3be3dfb15913c4e76d0b4a27b6400adc5.tar.bz2 busybox-w32-359da5e3be3dfb15913c4e76d0b4a27b6400adc5.zip |
ash: implement set -o pipefail (conditional on bash compat). +39 bytes
Signed-off-by: Michael Abbott <michael@araneidae.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c index 65d41cc5b..e7cf7975f 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -101,6 +101,9 @@ static const char *const optletters_optnames[] = { | |||
101 | "b" "notify", | 101 | "b" "notify", |
102 | "u" "nounset", | 102 | "u" "nounset", |
103 | "\0" "vi", | 103 | "\0" "vi", |
104 | #if ENABLE_ASH_BASH_COMPAT | ||
105 | "\0" "pipefail" | ||
106 | #endif | ||
104 | #if DEBUG | 107 | #if DEBUG |
105 | ,"\0" "nolog" | 108 | ,"\0" "nolog" |
106 | ,"\0" "debug" | 109 | ,"\0" "debug" |
@@ -178,9 +181,14 @@ struct globals_misc { | |||
178 | #define bflag optlist[11] | 181 | #define bflag optlist[11] |
179 | #define uflag optlist[12] | 182 | #define uflag optlist[12] |
180 | #define viflag optlist[13] | 183 | #define viflag optlist[13] |
184 | #if ENABLE_ASH_BASH_COMPAT | ||
185 | # define pipefail optlist[14] | ||
186 | #else | ||
187 | # define pipefail 0 | ||
188 | #endif | ||
181 | #if DEBUG | 189 | #if DEBUG |
182 | #define nolog optlist[14] | 190 | # define nolog optlist[14 + ENABLE_ASH_BASH_COMPAT] |
183 | #define debug optlist[15] | 191 | # define debug optlist[15 + ENABLE_ASH_BASH_COMPAT] |
184 | #endif | 192 | #endif |
185 | 193 | ||
186 | /* trap handler commands */ | 194 | /* trap handler commands */ |
@@ -3999,13 +4007,23 @@ jobscmd(int argc UNUSED_PARAM, char **argv) | |||
3999 | } | 4007 | } |
4000 | #endif /* JOBS */ | 4008 | #endif /* JOBS */ |
4001 | 4009 | ||
4010 | /* Called only on finished or stopped jobs (no members are running) */ | ||
4002 | static int | 4011 | static int |
4003 | getstatus(struct job *job) | 4012 | getstatus(struct job *job) |
4004 | { | 4013 | { |
4005 | int status; | 4014 | int status; |
4006 | int retval; | 4015 | int retval; |
4016 | struct procstat *ps; | ||
4017 | |||
4018 | /* Fetch last member's status */ | ||
4019 | ps = job->ps + job->nprocs - 1; | ||
4020 | status = ps->ps_status; | ||
4021 | if (pipefail) { | ||
4022 | /* "set -o pipefail" mode: use last _nonzero_ status */ | ||
4023 | while (status == 0 && --ps >= job->ps) | ||
4024 | status = ps->ps_status; | ||
4025 | } | ||
4007 | 4026 | ||
4008 | status = job->ps[job->nprocs - 1].ps_status; | ||
4009 | retval = WEXITSTATUS(status); | 4027 | retval = WEXITSTATUS(status); |
4010 | if (!WIFEXITED(status)) { | 4028 | if (!WIFEXITED(status)) { |
4011 | #if JOBS | 4029 | #if JOBS |