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>