]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: avoid seclabeltest crash
authorEric Blake <eblake@redhat.com>
Fri, 20 Jul 2012 20:44:54 +0000 (14:44 -0600)
committerCole Robinson <crobinso@redhat.com>
Mon, 13 Aug 2012 01:15:48 +0000 (21:15 -0400)
Commit a56c347 introduced a use of random numbers into seclabel
handling, but failed to initialize the random number generator
in the testsuite.  Also, fail with usual status, not 255.

* tests/seclabeltest.c (main): Initialize randomness.
(cherry picked from commit a22a36e8feaef19413e1a6af533eaa50f3c5df2d)

Conflicts:
tests/seclabeltest.c

tests/seclabeltest.c

index fca76b985163c595a42fa81e47ce01a614f92c8e..4f5e8b293fcfc99359cfaba34d4312ac1e83b696 100644 (file)
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <errno.h>
 #include "security/security_driver.h"
+#include "virrandom.h"
 
 int
 main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
@@ -13,10 +14,14 @@ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     virSecurityManagerPtr mgr;
     const char *doi, *model;
 
+    if (virThreadInitialize() < 0 ||
+        virRandomInitialize(time(NULL) ^ getpid()))
+        exit(EXIT_FAILURE);
+
     mgr = virSecurityManagerNew(NULL, false, true, false);
     if (mgr == NULL) {
         fprintf (stderr, "Failed to start security driver");
-        exit (-1);
+        exit(EXIT_FAILURE);
     }
 
     model = virSecurityManagerGetModel(mgr);
@@ -24,7 +29,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     {
         fprintf (stderr, "Failed to copy secModel model: %s",
                  strerror (errno));
-        exit (-1);
+        exit(EXIT_FAILURE);
     }
 
     doi = virSecurityManagerGetDOI(mgr);
@@ -32,7 +37,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     {
         fprintf (stderr, "Failed to copy secModel DOI: %s",
                  strerror (errno));
-        exit (-1);
+        exit(EXIT_FAILURE);
     }
 
     virSecurityManagerFree(mgr);