From: Mark Wooding Date: Sun, 10 May 2020 01:49:02 +0000 (+0100) Subject: bin/mdw-build: Close our file descriptors when running subcommands. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/a6776ae1cb174af2eab5ac748057ba0b5d08953b bin/mdw-build: Close our file descriptors when running subcommands. Otherwise they cause problems. Automake's generated `Makefile' calls out to `config.status' to do something involving dependency tracking; but that in turn calls back out to `make'. If the jobserver is active, then the file-descriptor juggling done inside `config.status' can clobber the jobserver pipe descriptors, which breaks things badly. It appears that the file-descriptor assignments in `config.status' are finely judged so that they will avoid the jobserver descriptors /if/ the prevailing environment hasn't opened any descriptors beyond the standard three. So we must keep our descriptors from leaking out and messing up this delicate balance. Of course, this is really a bug in Autoconf and/or Automake, but POSIX shell doesn't have a way to allocate a descriptor dynamically, so I'm going to cut them some slack here. --- diff --git a/bin/mdw-build b/bin/mdw-build index 7c82524..7f32c4f 100755 --- a/bin/mdw-build +++ b/bin/mdw-build @@ -224,14 +224,14 @@ assign () { runx () { notify 2 "+++ $*" - "$@" 2>&3 || fail "$1: exit $?" + "$@" 2>&3 3>&- 4>&- 5>&- || fail "$1: exit $?" } run () { runx "$@" >&3; } yesno () { echo -n "(test $*)" >&4 - if "$@" >&4 2>&4; then + if "$@" >&4 2>&4 3>&- 4>&- 5>&-; then echo "(yes)" >&4 echo yes else