]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: skip systemd activation test if FDs 3/4/5 are open
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 12 Jul 2019 16:55:13 +0000 (17:55 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 12 Jul 2019 17:12:25 +0000 (18:12 +0100)
With systemd activation the passed in file descriptors are required to
be numbered from STDERR_FILENO + 1 onwards. The unit tests thus require
FDs 3, 4 and 5 to be available.

This may not be the case in all environments in which the tests run. For
example on RHEL7 it was seen that a library constructor (gcrypt probably)
opens /dev/urandom and leaves the file handle open. This means FD 3 is
not available and the activation tests fail.

The best way to deal with this would be to create a standalone helper
program for the tests, but that's much more work than just skipping the
tests if we notice we have the problem.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
tests/virsystemdtest.c

index 586c512fca4a574bd9c943c9e240cfc5d5a09a33..cd031914abb6a7e0deb189166626e2765f6022e6 100644 (file)
@@ -23,6 +23,7 @@
 #if defined(WITH_DBUS) && defined(__linux__)
 
 # include <dbus/dbus.h>
+# include <fcntl.h>
 
 # define LIBVIRT_VIRSYSTEMDPRIV_H_ALLOW
 # include "virsystemdpriv.h"
@@ -762,10 +763,17 @@ mymain(void)
 
     if (virTestRun("Test activation empty", testActivationEmpty, NULL) < 0)
         ret = -1;
-    if (virTestRun("Test activation names", testActivationFDNames, NULL) < 0)
-        ret = -1;
-    if (virTestRun("Test activation addrs", testActivationFDAddrs, NULL) < 0)
-        ret = -1;
+
+    if (fcntl(STDERR_FILENO + 1, F_GETFL) == -1 && errno == EBADF &&
+        fcntl(STDERR_FILENO + 2, F_GETFL) == -1 && errno == EBADF &&
+        fcntl(STDERR_FILENO + 3, F_GETFL) == -1 && errno == EBADF) {
+        if (virTestRun("Test activation names", testActivationFDNames, NULL) < 0)
+            ret = -1;
+        if (virTestRun("Test activation addrs", testActivationFDAddrs, NULL) < 0)
+            ret = -1;
+    } else {
+        VIR_INFO("Skipping activation tests as FD 3/4/5 is open");
+    }
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }