[PATCH] tests: commandhelper: Accept POLLNVAL on macOS

Roman Bolshakov r.bolshakov at yadro.com
Wed Oct 7 12:20:56 UTC 2020


commandhelper hangs indefinetely in poll() on macOS on commandtest test2
and later because POLLNVAL is returned on revents for input file
descriptor opened from /dev/null, i.e this hangs:

  $ tests/commandhelper < /dev/null
  BEGIN STDOUT
  BEGIN STDERR
  ^C

But it works fine with regular stdin:

  $ tests/commandhelper <<< test
  BEGIN STDOUT
  BEGIN STDERR
  test
  test
  END STDOUT
  END STDERR

The issue is mentioned in poll(2):

  BUGS
    The poll() system call currently does not support devices.

With the change all 28 cases in commandtest pass.

Signed-off-by: Roman Bolshakov <r.bolshakov at yadro.com>
---
 tests/commandhelper.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 7c260c4e13..676ef55e9f 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -190,7 +190,15 @@ int main(int argc, char **argv) {
         }
 
         for (i = 0; i < numpollfds; i++) {
-            if (fds[i].revents & (POLLIN | POLLHUP | POLLERR)) {
+            if (fds[i].revents & (POLLIN | POLLHUP | POLLERR |
+# ifdef __APPLE__
+                                  /*
+                                   * poll() on /dev/null will return POLLNVAL
+                                   */
+                                  POLLNVAL)) {
+# else
+                                  0)) {
+# endif
                 fds[i].revents = 0;
 
                 got = read(fds[i].fd, buf, sizeof(buf));
-- 
2.28.0





More information about the libvir-list mailing list