fix “set -o pipefail” w/o PIPESTATUS, and PIPESTATUS inside COMSUBs and other sequences

This commit is contained in:
tg
2014-06-10 22:17:10 +00:00
parent 7330970bfa
commit 73edeaa8ec
4 changed files with 20 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.651 2014/06/09 13:25:50 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.652 2014/06/10 22:17:07 tg Exp $
# OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44 # OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44
#- #-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -27,7 +27,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R50 2014/06/09 @(#)MIRBSD KSH R50 2014/06/10
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -36,7 +36,7 @@ name: KSH_VERSION
category: shell:legacy-no category: shell:legacy-no
--- ---
expected-stdout: expected-stdout:
@(#)LEGACY KSH R50 2014/06/09 @(#)LEGACY KSH R50 2014/06/10
description: description:
Check version of legacy shell. Check version of legacy shell.
stdin: stdin:
@ -6513,6 +6513,7 @@ stdin:
echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" . echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" . echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" . echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
expected-stdout: expected-stdout:
1 42 . 1 42 .
2 0 . 2 0 .
@ -6522,6 +6523,7 @@ expected-stdout:
6 1 . 6 1 .
7 42 . 7 42 .
8 0 . 8 0 .
9 42 .
--- ---
name: persist-history-1 name: persist-history-1
description: description:

4
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.130 2014/05/27 13:22:43 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.131 2014/06/10 22:17:08 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL #ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh" #define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@ -462,7 +462,7 @@ execute(struct op * volatile t,
if (vp_pipest->flag & INT_L) { if (vp_pipest->flag & INT_L) {
unset(vp_pipest, 1); unset(vp_pipest, 1);
vp_pipest->flag = DEFINED | ISSET | INTEGER | RDONLY | vp_pipest->flag = DEFINED | ISSET | INTEGER | RDONLY |
ARRAY | INT_U; ARRAY | INT_U | INT_L;
vp_pipest->val.i = rv; vp_pipest->val.i = rv;
} }

13
jobs.c
View File

@ -2,7 +2,7 @@
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
* 2012, 2013 * 2012, 2013, 2014
* Thorsten Glaser <tg@mirbsd.org> * Thorsten Glaser <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.103 2013/11/30 17:41:35 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.104 2014/06/10 22:17:09 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
#define mksh_killpg killpg #define mksh_killpg killpg
@ -1270,6 +1270,15 @@ j_waitj(Job *j,
rv = vp->val.i; rv = vp->val.i;
p = p->next; p = p->next;
} }
} else if (Flag(FPIPEFAIL) && (j->proc_list != NULL)) {
Proc *p = j->proc_list;
int i;
while (p != NULL) {
if ((i = proc_errorlevel(p)))
rv = i;
p = p->next;
}
} }
if (!(flags & JW_ASYNCNOTIFY) if (!(flags & JW_ASYNCNOTIFY)

4
sh.h
View File

@ -169,9 +169,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.687 2014/06/09 13:25:53 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.688 2014/06/10 22:17:10 tg Exp $");
#endif #endif
#define MKSH_VERSION "R50 2014/06/09" #define MKSH_VERSION "R50 2014/06/10"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES