libvirt/tests/seclabeltest.c
Eric Blake a22a36e8fe tests: avoid seclabeltest crash
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.
2012-07-20 15:04:23 -06:00

47 lines
1.0 KiB
C

#include <config.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "security/security_driver.h"
#include "virrandom.h"
int
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, "QEMU", false, true, false);
if (mgr == NULL) {
fprintf (stderr, "Failed to start security driver");
exit(EXIT_FAILURE);
}
model = virSecurityManagerGetModel(mgr);
if (!model)
{
fprintf (stderr, "Failed to copy secModel model: %s",
strerror (errno));
exit(EXIT_FAILURE);
}
doi = virSecurityManagerGetDOI(mgr);
if (!doi)
{
fprintf (stderr, "Failed to copy secModel DOI: %s",
strerror (errno));
exit(EXIT_FAILURE);
}
virSecurityManagerFree(mgr);
return 0;
}