chiark / gitweb /
test: Fix fd plumbing
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 11 Oct 2019 20:31:44 +0000 (21:31 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Oct 2019 22:29:26 +0000 (23:29 +0100)
In a background process, stdin defaults to /dev/null, so we need to do
a little dance.  <&0 looks like it ought to work according to the bash
manual and does indeed work in bash, but not in dash.  This
construction seems to work in both.

Tested with:
  date | sh -exc 'cat <&0 >t &'

SuS says:
  If job control is disabled (see set, -m), the standard input for an
  asynchronous list, before any explicit redirections are performed,
  shall be considered to be assigned to a file that has the same
  properties as /dev/null. This shall not happen if job control is
  enabled. In all cases, explicit redirection of standard input shall
  override this activity.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
test/invoke

index 98a7ea1187380370bd67187505d1762d1135e641..fb9ce2ca1b389673765f631f45956c065cc7a895 100755 (executable)
@@ -39,7 +39,8 @@ proc mkconf {which} {
     set fakeuh [open $fakeuf w 0755]
     puts $fakeuh "#!/bin/sh
 set -e
-cat >$pipefp.r &
+exec 3<&0
+cat <&3 3<&- >$pipefp.r &
 exec 3<>$pipefp.t
 exec <$pipefp.t
 exec 3<&-