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(a)redhat.com>
---
Pushed as a CI build fix
tests/virsystemdtest.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
index 586c512fca..cd031914ab 100644
--- a/tests/virsystemdtest.c
+++ b/tests/virsystemdtest.c
@@ -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;
}
--
2.21.0