Applied in this form: preverrout_fd = 2; + if (BASH_XTRACEFD && xflag) { + /* NB: bash closes fd == $BASH_XTRACEFD when it is changed. + * we do not emulate this. We only use its value. + */ + const char *xtracefd = lookupvar("BASH_XTRACEFD"); + if (xtracefd && is_number(xtracefd)) + preverrout_fd = atoi(xtracefd); + + } status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH | REDIR_SAVEFD2);
On Fri, Aug 4, 2017 at 12:58 PM, Johannes Schindelin <johannes.schinde...@gmx.de> wrote: > There is a very useful feature in Bash where you can redirect the trace > enabled by `set -x` to a file descriptor *different* than 2. This comes > in particularly handy when validating the error output of commands, say, > in Git's test suite, while tracing at the same time. > > It is such a useful feature, and very easily implemented. > > Signed-off-by: Johannes Schindelin <johannes.schinde...@gmx.de> > --- > shell/ash.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/shell/ash.c b/shell/ash.c > index 8c9f4adc6..1d1596fec 100644 > --- a/shell/ash.c > +++ b/shell/ash.c > @@ -182,6 +182,8 @@ > #define IF_BASH_PATTERN_SUBST IF_ASH_BASH_COMPAT > #define BASH_SUBSTR ENABLE_ASH_BASH_COMPAT > #define IF_BASH_SUBSTR IF_ASH_BASH_COMPAT > +#define BASH_XTRACEFD ENABLE_ASH_BASH_COMPAT > +#define IF_BASH_XTRACEFD IF_ASH_BASH_COMPAT > /* [[ EXPR ]] */ > #define BASH_TEST2 (ENABLE_ASH_BASH_COMPAT * ENABLE_ASH_TEST) > #define BASH_SOURCE ENABLE_ASH_BASH_COMPAT > @@ -9740,6 +9742,7 @@ evalcommand(union node *cmd, int flags) > int status; > char **nargv; > smallint cmd_is_exec; > + IF_BASH_XTRACEFD(const char *xtracefd;) > > /* First expand the arguments. */ > TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); > @@ -9791,6 +9794,10 @@ evalcommand(union node *cmd, int flags) > > expredir(cmd->ncmd.redirect); > redir_stop = pushredir(cmd->ncmd.redirect); > +#ifdef BASH_XTRACEFD > + xtracefd = lookupvar("BASH_XTRACEFD"); > + if (!xtracefd || (preverrout_fd = atoi(xtracefd)) < 0) > +#endif > preverrout_fd = 2; > status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH | REDIR_SAVEFD2); > > > base-commit: 4dc86699b57ff35c287ca396d562ec206776694a > -- > 2.13.3.windows.1.1055.g9b9ea5f2d78 > > Published-As: > https://github.com/dscho/busybox-w32/releases/tag/busybox-xtracefd-v1 > Fetch-It-Via: git fetch https://github.com/dscho/busybox-w32 > busybox-xtracefd-v1 > _______________________________________________ > busybox mailing list > busybox@busybox.net > http://lists.busybox.net/mailman/listinfo/busybox _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox