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>
This commit is contained in:
parent
285ad155c4
commit
359da5e3be
24
shell/ash.c
24
shell/ash.c
@ -101,6 +101,9 @@ static const char *const optletters_optnames[] = {
|
|||||||
"b" "notify",
|
"b" "notify",
|
||||||
"u" "nounset",
|
"u" "nounset",
|
||||||
"\0" "vi",
|
"\0" "vi",
|
||||||
|
#if ENABLE_ASH_BASH_COMPAT
|
||||||
|
"\0" "pipefail"
|
||||||
|
#endif
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
,"\0" "nolog"
|
,"\0" "nolog"
|
||||||
,"\0" "debug"
|
,"\0" "debug"
|
||||||
@ -178,9 +181,14 @@ struct globals_misc {
|
|||||||
#define bflag optlist[11]
|
#define bflag optlist[11]
|
||||||
#define uflag optlist[12]
|
#define uflag optlist[12]
|
||||||
#define viflag optlist[13]
|
#define viflag optlist[13]
|
||||||
|
#if ENABLE_ASH_BASH_COMPAT
|
||||||
|
# define pipefail optlist[14]
|
||||||
|
#else
|
||||||
|
# define pipefail 0
|
||||||
|
#endif
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define nolog optlist[14]
|
# define nolog optlist[14 + ENABLE_ASH_BASH_COMPAT]
|
||||||
#define debug optlist[15]
|
# define debug optlist[15 + ENABLE_ASH_BASH_COMPAT]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* trap handler commands */
|
/* trap handler commands */
|
||||||
@ -3999,13 +4007,23 @@ jobscmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
#endif /* JOBS */
|
#endif /* JOBS */
|
||||||
|
|
||||||
|
/* Called only on finished or stopped jobs (no members are running) */
|
||||||
static int
|
static int
|
||||||
getstatus(struct job *job)
|
getstatus(struct job *job)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
int retval;
|
int retval;
|
||||||
|
struct procstat *ps;
|
||||||
|
|
||||||
|
/* Fetch last member's status */
|
||||||
|
ps = job->ps + job->nprocs - 1;
|
||||||
|
status = ps->ps_status;
|
||||||
|
if (pipefail) {
|
||||||
|
/* "set -o pipefail" mode: use last _nonzero_ status */
|
||||||
|
while (status == 0 && --ps >= job->ps)
|
||||||
|
status = ps->ps_status;
|
||||||
|
}
|
||||||
|
|
||||||
status = job->ps[job->nprocs - 1].ps_status;
|
|
||||||
retval = WEXITSTATUS(status);
|
retval = WEXITSTATUS(status);
|
||||||
if (!WIFEXITED(status)) {
|
if (!WIFEXITED(status)) {
|
||||||
#if JOBS
|
#if JOBS
|
||||||
|
Loading…
Reference in New Issue
Block a user