From ab9fae2a7024947a944b3448930801eae1ce4003 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 10 May 2020 02:56:28 +0100 Subject: [PATCH] bin/mdw-build: Use dynamically chosen file descriptors. Organization: Straylight/Edgeware From: Mark Wooding 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. --- bin/mdw-build | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/bin/mdw-build b/bin/mdw-build index 7f32c4f..27eac50 100755 --- a/bin/mdw-build +++ b/bin/mdw-build @@ -188,17 +188,17 @@ case $jobs in 1) ;; *) makeopts="$makeopts -j$jobs" ;; esac ## ## 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 ## output -## 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 - 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 } fail () { @@ -224,18 +224,18 @@ assign () { 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; } yesno () { - 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 echo yes else - echo "(no)" >&4 + echo "(no)" >&$diag echo no fi } @@ -270,7 +270,8 @@ rm -rf $releasepath 2>/dev/null || : 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 @@ -375,10 +376,10 @@ esac cat >find-distdir.mk <<'EOF' include Makefile print-distdir: - @echo >&3 $(distdir) + @echo >&$(fd) $(distdir) EOF assign 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 -- [mdw]