On Mon, Apr 13, 2020 at 07:29:01PM -0500, Eric Blake wrote:
Enhance the testsuite to ensure we don't regress with recent changes to stdin/out handling. This adds: - test-single-sh.sh: prove that 'nbdkit -s sh script' is viable - test-stdio.sh: create plugin that checks stdin/out match /dev/null, then run it with -s, --run, -f
Signed-off-by: Eric Blake <eblake@redhat.com> ... +/* Check whether stdin/out match /dev/null */ +static bool +stdio_check (void) +{ + static int dn = -1; + struct stat st1, st2; + + if (dn == -1) { + dn = open ("/dev/null", O_RDONLY); + assert (dn > STDERR_FILENO); + } + if (fstat (dn, &st1) == -1) + assert (false); + + if (fstat (STDIN_FILENO, &st2) == -1) + assert (false); + if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) + return false; + + if (fstat (STDOUT_FILENO, &st2) == -1) + assert (false); + if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) + return false; + + return true; +}
Interesting - I think I would have done a Linux-specific hack involving /proc/fd, but your way should be better :-) All looks good, ACK. Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/