2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-12-07 10:08:06 +00:00
|
|
|
|
2006-09-21 09:15:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2007-12-07 14:38:34 +00:00
|
|
|
|
2007-03-06 21:55:44 +00:00
|
|
|
#include "internal.h"
|
2011-07-07 21:53:41 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
#include "command.h"
|
2006-11-09 10:14:01 +00:00
|
|
|
|
2007-03-06 21:55:44 +00:00
|
|
|
static void errorHandler(void *userData ATTRIBUTE_UNUSED,
|
2008-04-10 16:54:54 +00:00
|
|
|
virErrorPtr error ATTRIBUTE_UNUSED) {
|
2006-11-09 10:14:01 +00:00
|
|
|
}
|
2006-09-21 09:15:33 +00:00
|
|
|
|
2011-07-09 09:50:38 +00:00
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
2006-09-21 09:15:33 +00:00
|
|
|
int id = 0;
|
2006-11-09 10:14:01 +00:00
|
|
|
int ro = 0;
|
2006-09-21 09:15:33 +00:00
|
|
|
virConnectPtr conn;
|
|
|
|
virDomainPtr dom;
|
2011-07-07 21:53:41 +00:00
|
|
|
int status;
|
|
|
|
virCommandPtr cmd;
|
|
|
|
|
|
|
|
/* skip test if xend is not running */
|
|
|
|
cmd = virCommandNewArgList("/usr/sbin/xend", "status", NULL);
|
|
|
|
if (virCommandRun(cmd, &status) != 0 || status != 0) {
|
|
|
|
virCommandFree(cmd);
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
virCommandFree(cmd);
|
2006-09-21 09:15:33 +00:00
|
|
|
|
2006-11-09 10:14:01 +00:00
|
|
|
virSetErrorFunc(NULL, errorHandler);
|
|
|
|
|
|
|
|
conn = virConnectOpen(NULL);
|
|
|
|
if (conn == NULL) {
|
|
|
|
ro = 1;
|
2008-04-10 16:54:54 +00:00
|
|
|
conn = virConnectOpenReadOnly(NULL);
|
2006-11-09 10:14:01 +00:00
|
|
|
}
|
2006-09-21 09:15:33 +00:00
|
|
|
if (conn == NULL) {
|
|
|
|
fprintf(stderr, "First virConnectOpen() failed\n");
|
2011-07-09 09:50:38 +00:00
|
|
|
return EXIT_FAILURE;
|
2006-09-21 09:15:33 +00:00
|
|
|
}
|
|
|
|
dom = virDomainLookupByID(conn, id);
|
|
|
|
if (dom == NULL) {
|
|
|
|
fprintf(stderr, "First lookup for domain %d failed\n", id);
|
2011-07-09 09:50:38 +00:00
|
|
|
return EXIT_FAILURE;
|
2006-09-21 09:15:33 +00:00
|
|
|
}
|
|
|
|
virDomainFree(dom);
|
|
|
|
virConnectClose(conn);
|
2006-11-09 10:14:01 +00:00
|
|
|
if (ro == 1)
|
2008-04-10 16:54:54 +00:00
|
|
|
conn = virConnectOpenReadOnly(NULL);
|
2006-11-09 10:14:01 +00:00
|
|
|
else
|
2008-04-10 16:54:54 +00:00
|
|
|
conn = virConnectOpen(NULL);
|
2006-09-21 09:15:33 +00:00
|
|
|
if (conn == NULL) {
|
|
|
|
fprintf(stderr, "Second virConnectOpen() failed\n");
|
2011-07-09 09:50:38 +00:00
|
|
|
return EXIT_FAILURE;
|
2006-09-21 09:15:33 +00:00
|
|
|
}
|
|
|
|
dom = virDomainLookupByID(conn, id);
|
|
|
|
if (dom == NULL) {
|
|
|
|
fprintf(stderr, "Second lookup for domain %d failed\n", id);
|
2011-07-09 09:50:38 +00:00
|
|
|
return EXIT_FAILURE;
|
2006-09-21 09:15:33 +00:00
|
|
|
}
|
|
|
|
virDomainFree(dom);
|
|
|
|
virConnectClose(conn);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2011-07-09 09:50:38 +00:00
|
|
|
return EXIT_SUCCESS;
|
2006-09-21 09:15:33 +00:00
|
|
|
}
|
2011-07-09 09:50:38 +00:00
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|