Having just ranted about a bug caused by shell scripts statically
allocating file descriptors, fix `mdw-build' to allocate descriptors
dynamically, since it's written in Bash, which can apparently do this.
##
## 0 -- original stdin (never touched)
## 1, 2 -- stdout, stderr, redirected to 3 while running comamnds
##
## 0 -- original stdin (never touched)
## 1, 2 -- stdout, stderr, redirected to 3 while running comamnds
-## 3 -- original stderr (verbose), or logfile (quiet); captures command
+## log -- original stderr (verbose), or logfile (quiet); captures command
-## 4 -- null (verbose), or logfile (quiet); primary diagnostic output
-## 5 -- orginal stderr; secondary diagnostic output (with colours)
+## diag -- null (verbose), or logfile (quiet); primary diagnostic output
+## term -- orginal stderr; secondary diagnostic output (with colours)
-exec 3>&2 4>/dev/null 5>&2
+exec {log}>&2 {diag}>/dev/null {term}>&2
notify () {
colour=$1 message=$2
notify () {
colour=$1 message=$2
- echo $message >&4
- echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)" >&5
+ echo $message >&$diag
+ echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)" >&$term
runx () {
notify 2 "+++ $*"
runx () {
notify 2 "+++ $*"
- "$@" 2>&3 3>&- 4>&- 5>&- || fail "$1: exit $?"
+ "$@" 2>&$log {log}>&- {diag}>&- {term}>&- || fail "$1: exit $?"
-run () { runx "$@" >&3; }
+run () { runx "$@" >&$log; }
- echo -n "(test $*)" >&4
- if "$@" >&4 2>&4 3>&- 4>&- 5>&-; then
- echo "(yes)" >&4
+ echo -n "(test $*)" >&$diag
+ if "$@" >&$diag 2>&$diag {log}>&- {diag}>&- {term}>&-; then
+ echo "(yes)" >&$diag
mkdir $releasepath
case $verbose in
no)
mkdir $releasepath
case $verbose in
no)
- exec 4>$releasepath/mdw-build.log 3>&4 ||
+ exec {log}>&- {diag}>&-
+ exec {diag}>$releasepath/mdw-build.log {log}>&$diag ||
fail "Failed to create log."
;;
esac
fail "Failed to create log."
;;
esac
cat >find-distdir.mk <<'EOF'
include Makefile
print-distdir:
cat >find-distdir.mk <<'EOF'
include Makefile
print-distdir:
+ @echo >&$(fd) $(distdir)
- $({ $make -f find-distdir.mk print-distdir >/dev/null 2>&1; } 3>&1)
+ $({ $make -f find-distdir.mk print-distdir fd=$t >/dev/null 2>&1; } {t}>&1)
## Get a tarball distribution.
case "$distcheck" in
## Get a tarball distribution.
case "$distcheck" in