Fix most “set -x” problems (LP#1179287)
• “set -x” manually (cmdline too) snapshots fd#2 now • “set -o inherit-xtrace” introduced; default still enabled • reverted iodup printing to pre-R45 behaviour • made Flag(FXTRACE) a proper state machine
This commit is contained in:
parent
dd7b17e704
commit
ead77623d3
6
Build.sh
6
Build.sh
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.639 2013/07/08 10:12:45 tg Exp $'
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.640 2013/07/21 18:47:14 tg Exp $'
|
||||
#-
|
||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
# 2011, 2012, 2013
|
||||
|
@ -1544,7 +1544,7 @@ else
|
|||
#define EXTERN
|
||||
#define MKSH_INCLUDES_ONLY
|
||||
#include "sh.h"
|
||||
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.639 2013/07/08 10:12:45 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.640 2013/07/21 18:47:14 tg Exp $");
|
||||
int main(void) { printf("Hello, World!\n"); return (0); }
|
||||
EOF
|
||||
case $cm in
|
||||
|
@ -2059,7 +2059,7 @@ addsrcs USE_PRINTF_BUILTIN printf.c
|
|||
test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
|
||||
test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
|
||||
test -n "$LDSTATIC" && add_cppflags -DMKSH_OPTSTATIC
|
||||
add_cppflags -DMKSH_BUILD_R=469
|
||||
add_cppflags -DMKSH_BUILD_R=471
|
||||
|
||||
$e $bi$me: Finished configuration testing, now producing output.$ao
|
||||
|
||||
|
|
4
Makefile
4
Makefile
|
@ -1,4 +1,4 @@
|
|||
# $MirOS: src/bin/mksh/Makefile,v 1.122 2013/05/31 23:27:13 tg Exp $
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.123 2013/07/21 18:47:15 tg Exp $
|
||||
#-
|
||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
# 2011, 2012, 2013
|
||||
|
@ -54,7 +54,7 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
|
|||
-DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \
|
||||
-DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
|
||||
-DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
|
||||
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=469
|
||||
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=471
|
||||
CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
|
||||
COPTS+= -std=c99 -Wall
|
||||
.endif
|
||||
|
|
22
check.t
22
check.t
|
@ -1,4 +1,4 @@
|
|||
# $MirOS: src/bin/mksh/check.t,v 1.618 2013/07/21 18:38:53 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.619 2013/07/21 18:47:16 tg Exp $
|
||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||
|
@ -31,7 +31,7 @@
|
|||
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R46 2013/06/03
|
||||
@(#)MIRBSD KSH R47 2013/07/21
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
|
@ -40,7 +40,7 @@ name: KSH_VERSION
|
|||
category: shell:legacy-no
|
||||
---
|
||||
expected-stdout:
|
||||
@(#)LEGACY KSH R46 2013/06/03
|
||||
@(#)LEGACY KSH R47 2013/07/21
|
||||
description:
|
||||
Check version of legacy shell.
|
||||
stdin:
|
||||
|
@ -11107,3 +11107,19 @@ stdin:
|
|||
done
|
||||
Lb64decode $s >/dev/null
|
||||
---
|
||||
name: xtrace-1
|
||||
description:
|
||||
Check that "set -x" doesn't redirect too quickly
|
||||
stdin:
|
||||
print '#!'"$__progname" >bash
|
||||
cat >>bash <<'EOF'
|
||||
echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.'
|
||||
EOF
|
||||
chmod +x bash
|
||||
"$__progname" -xc 'foo=$(./bash --version 2>&1 | head -1); echo "=$foo="'
|
||||
expected-stdout:
|
||||
=GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
|
||||
expected-stderr-pattern:
|
||||
/.*/
|
||||
---
|
||||
|
|
41
exec.c
41
exec.c
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.123 2013/07/21 18:36:00 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.124 2013/07/21 18:47:18 tg Exp $");
|
||||
|
||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||
|
@ -138,11 +138,6 @@ execute(struct op * volatile t,
|
|||
/* Allow option parsing (bizarre, but POSIX) */
|
||||
timex_hook(t, &up);
|
||||
ap = (const char **)up;
|
||||
if (Flag(FXTRACE)) {
|
||||
shf_puts(substitute(str_val(global("PS4")), 0),
|
||||
shl_out);
|
||||
Flag(FXTRACE) = 2;
|
||||
}
|
||||
if (ap[0])
|
||||
tp = findcom(ap[0], FC_BI|FC_FUNC);
|
||||
}
|
||||
|
@ -639,6 +634,8 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
|||
l_assign = e->loc;
|
||||
if (Flag(FEXPORT))
|
||||
type_flags |= EXPORT;
|
||||
if (Flag(FXTRACE))
|
||||
change_xtrace(2, false);
|
||||
for (i = 0; t->vars[i]; i++) {
|
||||
/* do NOT lookup in the new var/fn block just created */
|
||||
e->loc = l_expand;
|
||||
|
@ -652,9 +649,9 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
|||
++ccp;
|
||||
if (*ccp == '=')
|
||||
++ccp;
|
||||
shf_write(cp, ccp - cp, shl_out);
|
||||
print_value_quoted(shl_out, ccp);
|
||||
shf_putc(' ', shl_out);
|
||||
shf_write(cp, ccp - cp, shl_xtrace);
|
||||
print_value_quoted(shl_xtrace, ccp);
|
||||
shf_putc(' ', shl_xtrace);
|
||||
}
|
||||
/* but assign in there as usual */
|
||||
typeset(cp, type_flags, 0, 0, 0);
|
||||
|
@ -663,17 +660,16 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
|||
}
|
||||
|
||||
if (Flag(FXTRACE)) {
|
||||
change_xtrace(2, false);
|
||||
if (ap[rv = 0]) {
|
||||
xtrace_ap_loop:
|
||||
print_value_quoted(shl_out, ap[rv]);
|
||||
print_value_quoted(shl_xtrace, ap[rv]);
|
||||
if (ap[++rv]) {
|
||||
shf_putc(' ', shl_out);
|
||||
shf_putc(' ', shl_xtrace);
|
||||
goto xtrace_ap_loop;
|
||||
}
|
||||
}
|
||||
shf_putc('\n', shl_out);
|
||||
Flag(FXTRACE) = 1;
|
||||
shf_flush(shl_out);
|
||||
change_xtrace(1, false);
|
||||
}
|
||||
|
||||
if ((cp = *ap) == NULL) {
|
||||
|
@ -756,9 +752,9 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
|||
getopts_reset(1);
|
||||
}
|
||||
|
||||
old_xflag = Flag(FXTRACE);
|
||||
Flag(FXTRACE) |= tp->flag & TRACE ? 1 : 0;
|
||||
|
||||
old_xflag = Flag(FXTRACE) ? 1 : 0;
|
||||
change_xtrace((Flag(FXTRACEREC) ? old_xflag : 0) |
|
||||
((tp->flag & TRACE) ? 1 : 0), false);
|
||||
old_inuse = tp->flag & FINUSE;
|
||||
tp->flag |= FINUSE;
|
||||
|
||||
|
@ -767,9 +763,11 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
|||
execute(tp->val.t, flags & XERROK, NULL);
|
||||
i = LRETURN;
|
||||
}
|
||||
|
||||
kshname = old_kshname;
|
||||
Flag(FXTRACE) = old_xflag;
|
||||
change_xtrace(old_xflag, false);
|
||||
tp->flag = (tp->flag & ~FINUSE) | old_inuse;
|
||||
|
||||
/*
|
||||
* Were we deleted while executing? If so, free the
|
||||
* execution tree. TODO: Unfortunately, the table entry
|
||||
|
@ -1310,8 +1308,11 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
|||
iotmp.name = (iotype == IOHERE) ? NULL : cp;
|
||||
iotmp.flag |= IONAMEXP;
|
||||
|
||||
if (Flag(FXTRACE) == 2)
|
||||
fptreef(shl_out, 0, "%R", &iotmp);
|
||||
if (Flag(FXTRACE)) {
|
||||
change_xtrace(2, false);
|
||||
fptreef(shl_xtrace, 0, "%R", &iotmp);
|
||||
change_xtrace(1, false);
|
||||
}
|
||||
|
||||
switch (iotype) {
|
||||
case IOREAD:
|
||||
|
|
9
main.c
9
main.c
|
@ -34,7 +34,7 @@
|
|||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.267 2013/07/21 18:36:01 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.268 2013/07/21 18:47:19 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
|
@ -343,6 +343,11 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
|
|||
*/
|
||||
Flag(FBRACEEXPAND) = 1;
|
||||
|
||||
/*
|
||||
* Turn on "set -x" inheritance by default.
|
||||
*/
|
||||
Flag(FXTRACEREC) = 1;
|
||||
|
||||
#ifndef MKSH_NO_CMDLINE_EDITING
|
||||
/*
|
||||
* Set edit mode to emacs by default, may be overridden
|
||||
|
@ -1388,7 +1393,7 @@ initio(void)
|
|||
/* force buffer allocation */
|
||||
shf_fdopen(1, SHF_WR, shl_stdout);
|
||||
shf_fdopen(2, SHF_WR, shl_out);
|
||||
shf_fdopen(2, SHF_WR, shl_spare);
|
||||
shf_fdopen(2, SHF_WR, shl_xtrace);
|
||||
#ifdef DF
|
||||
if ((lfp = getenv("SDMKSH_PATH")) == NULL) {
|
||||
if ((lfp = getenv("HOME")) == NULL || *lfp != '/')
|
||||
|
|
45
misc.c
45
misc.c
|
@ -30,7 +30,7 @@
|
|||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.212 2013/06/03 22:28:05 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.213 2013/07/21 18:47:20 tg Exp $");
|
||||
|
||||
#define KSH_CHVT_FLAG
|
||||
#ifdef MKSH_SMALL
|
||||
|
@ -229,8 +229,12 @@ void
|
|||
change_flag(enum sh_flag f, int what, bool newset)
|
||||
{
|
||||
unsigned char oldval;
|
||||
unsigned char newval;
|
||||
unsigned char newval = (newset ? 1 : 0);
|
||||
|
||||
if (f == FXTRACE) {
|
||||
change_xtrace(newval, true);
|
||||
return;
|
||||
}
|
||||
oldval = Flag(f);
|
||||
Flag(f) = newval = (newset ? 1 : 0);
|
||||
#ifndef MKSH_UNEMPLOYED
|
||||
|
@ -286,6 +290,37 @@ change_flag(enum sh_flag f, int what, bool newset)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
change_xtrace(unsigned char newval, bool dosnapshot)
|
||||
{
|
||||
if (!dosnapshot && newval == Flag(FXTRACE))
|
||||
return;
|
||||
|
||||
if (Flag(FXTRACE) == 2) {
|
||||
shf_putc('\n', shl_xtrace);
|
||||
Flag(FXTRACE) = 1;
|
||||
shf_flush(shl_xtrace);
|
||||
}
|
||||
|
||||
if (!dosnapshot && Flag(FXTRACE) == 1)
|
||||
switch (newval) {
|
||||
case 1:
|
||||
return;
|
||||
case 2:
|
||||
goto changed_xtrace;
|
||||
}
|
||||
|
||||
shf_flush(shl_xtrace);
|
||||
if (shl_xtrace->fd != 2)
|
||||
close(shl_xtrace->fd);
|
||||
if (!newval || (shl_xtrace->fd = savefd(2)) == -1)
|
||||
shl_xtrace->fd = 2;
|
||||
|
||||
changed_xtrace:
|
||||
if ((Flag(FXTRACE) = newval) == 2)
|
||||
shf_puts(substitute(str_val(global("PS4")), 0), shl_xtrace);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse command line and set command arguments. Returns the index of
|
||||
* non-option arguments, -1 if there is an error.
|
||||
|
@ -444,8 +479,10 @@ parse_args(const char **argv,
|
|||
(argv[go.optind][0] == '-' || argv[go.optind][0] == '+') &&
|
||||
argv[go.optind][1] == '\0') {
|
||||
/* lone - clears -v and -x flags */
|
||||
if (argv[go.optind][0] == '-')
|
||||
Flag(FVERBOSE) = Flag(FXTRACE) = 0;
|
||||
if (argv[go.optind][0] == '-') {
|
||||
Flag(FVERBOSE) = 0;
|
||||
change_xtrace(0, false);
|
||||
}
|
||||
/* set skips lone - or + option */
|
||||
go.optind++;
|
||||
}
|
||||
|
|
7
mksh.1
7
mksh.1
|
@ -1,4 +1,4 @@
|
|||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.317 2013/07/21 18:36:02 tg Exp $
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.318 2013/07/21 18:47:21 tg Exp $
|
||||
.\" $OpenBSD: ksh.1,v 1.147 2013/06/13 19:43:09 millert Exp $
|
||||
.\"-
|
||||
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
|
@ -4165,6 +4165,11 @@ must be used.
|
|||
To avoid infinite loops, the shell will exit if
|
||||
.Dv EOF
|
||||
is read 13 times in a row.
|
||||
.It Fl o Ic inherit\-xtrace
|
||||
Do not reset
|
||||
.Fl o Ic xtrace
|
||||
upon entering functions.
|
||||
This is enabled by default.
|
||||
.It Fl o Ic nohup
|
||||
Do not kill running jobs with a
|
||||
.Dv SIGHUP
|
||||
|
|
9
sh.h
9
sh.h
|
@ -164,9 +164,9 @@
|
|||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.659 2013/06/03 22:28:33 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.660 2013/07/21 18:47:22 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R46 2013/06/03"
|
||||
#define MKSH_VERSION "R47 2013/07/21"
|
||||
|
||||
/* arithmetic types: C implementation */
|
||||
#if !HAVE_CAN_INTTYPES
|
||||
|
@ -520,7 +520,7 @@ char *ucstrstr(char *, const char *);
|
|||
#define mkssert(e) do { } while (/* CONSTCOND */ 0)
|
||||
#endif
|
||||
|
||||
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 469)
|
||||
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 471)
|
||||
#error Must run Build.sh to compile this.
|
||||
extern void thiswillneverbedefinedIhope(void);
|
||||
int
|
||||
|
@ -838,7 +838,7 @@ struct temp {
|
|||
* stdio and our IO routines
|
||||
*/
|
||||
|
||||
#define shl_spare (&shf_iob[0]) /* for c_read()/c_print() */
|
||||
#define shl_xtrace (&shf_iob[0]) /* for set -x */
|
||||
#define shl_stdout (&shf_iob[1])
|
||||
#define shl_out (&shf_iob[2])
|
||||
#ifdef DF
|
||||
|
@ -1906,6 +1906,7 @@ void initctypes(void);
|
|||
size_t option(const char *);
|
||||
char *getoptions(void);
|
||||
void change_flag(enum sh_flag, int, bool);
|
||||
void change_xtrace(unsigned char, bool);
|
||||
int parse_args(const char **, int, bool *);
|
||||
int getn(const char *, int *);
|
||||
int gmatchx(const char *, const char *, bool);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(SHFLAGS_DEFNS)
|
||||
__RCSID("$MirOS: src/bin/mksh/sh_flags.h,v 1.14 2013/05/02 20:28:15 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh_flags.h,v 1.15 2013/07/21 18:47:24 tg Exp $");
|
||||
#define FN(sname,cname,ochar,flags) /* nothing */
|
||||
#elif defined(SHFLAGS_ENUMS)
|
||||
#define FN(sname,cname,ochar,flags) cname,
|
||||
|
@ -45,6 +45,9 @@ FN("gmacs", FGMACS, 0, OF_ANY)
|
|||
/* ./. reading EOF does not exit */
|
||||
FN("ignoreeof", FIGNOREEOF, 0, OF_ANY)
|
||||
|
||||
/* ./. inherit -x flag */
|
||||
FN("inherit-xtrace", FXTRACEREC, 0, OF_ANY)
|
||||
|
||||
/* -i interactive shell */
|
||||
FN("interactive", FTALKING, 'i', OF_CMDLINE)
|
||||
|
||||
|
|
Loading…
Reference in New Issue