Comment 4 for bug 1179287

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

This is a bit tricky. I don’t quite like how BASH_XTRACEFD works.

I personally like the idea to dup stderr at the time of
running “set -x” the best (any subsequent “set +x” will
close the dup; any subsequent “set -x” will close the
dup if open, then dup whatever stderr currently is anew).

However, none of these scenarios work well with subshells.
We could do something environment-y to pass the fd number
of the dup down to the subshell, but that’s get funny to
decide who dups or closes what when. Consider:

parentshell: FOO_DUPFD=25 mksh subshell

subshell: exec 25>foo; set -x

This would either mean that the shell has to dup FOO_DUPFD
upon startup if it’s set, or trace all redirections (which
we could use to avoid the dup in the first place… except
if stderr was actually closed…), or that the set -x in the
subshell would go to the file foo instead of to what the
parent’s goes.

Considering all this, and that XTRACE is not inherited by
subshells anyway (just sub-environments in the same shell),
I’d say ignore the fact and just dup on “set -x”?

Does anyone else have any ideas/comments on this?