sh: Test for fd leaks
commit37b0df4c70540516e0a5572b9a0750d106ef66b3
authorEric Blake <eblake@redhat.com>
Fri, 2 Aug 2019 19:12:39 +0000 (2 14:12 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 2 Aug 2019 22:36:28 +0000 (2 17:36 -0500)
treeebb5637908436879b2df83d677cdbc8ee0e139b1
parent02786baf5aca7c3553085e0958dbda99bcc028c7
sh: Test for fd leaks

Various patches before this one plugged fd leaks of files opened
within nbdkit that the shell script need not see.  It's time to add
testsuite coverage to ensure we don't regress.

However, a user may intentionally want to expose an open fd to nbdkit,
which in turn remains available all the way through to the shell
script, so nbdkit does not close unrecognized inherited fds at
startup.  This makes the test more interesting - if you run 'exec
17>/dev/null && make check', then there will be one more inherited fd
in the environment of both nbdkit and the shell script, but this is
not an nbdkit leak.  Furthermore, checking how many fds are open in a
shell is tricky: many actions in the shell (such as a glob or
pipeline) increase the number of temporarily-open file descriptors; I
settled on creating a subshell, then using ls to check the files still
open in $$ (the subshell prevents the parent from using any more fds,
all without changing $$).

This addition is rather fragile - if it causes testsuite failures in
some environments, we may end up reverting it.

Signed-off-by: Eric Blake <eblake@redhat.com>
tests/test-parallel-sh.sh