chiark / gitweb /
bin/mdw-build: Close our file descriptors when running subcommands.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 10 May 2020 01:49:02 +0000 (02:49 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 10 May 2020 01:49:02 +0000 (02:49 +0100)
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.

bin/mdw-build

index 7c825243ffbcea5488c4b85c21f83381ca84af24..7f32c4f3ebd176025b6806e3f7de187b594214d3 100755 (executable)
@@ -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