2008-01-30 02:15:54 +08:00
|
|
|
#include <config.h>
|
2007-12-07 18:08:06 +08:00
|
|
|
|
2006-09-21 17:15:33 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-11-19 05:21:54 +08:00
|
|
|
#include <sys/utsname.h>
|
2007-12-07 22:38:34 +08:00
|
|
|
|
2007-03-07 05:55:44 +08:00
|
|
|
#include "internal.h"
|
2011-07-08 05:53:41 +08:00
|
|
|
#include "testutils.h"
|
2012-12-13 00:27:01 +08:00
|
|
|
#include "vircommand.h"
|
2006-11-09 18:14:01 +08:00
|
|
|
|
2011-07-09 17:50:38 +08:00
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
2006-09-21 17:15:33 +08:00
|
|
|
int id = 0;
|
2013-05-24 18:14:02 +08:00
|
|
|
bool ro = false;
|
2006-09-21 17:15:33 +08:00
|
|
|
virConnectPtr conn;
|
|
|
|
virDomainPtr dom;
|
2011-07-08 05:53:41 +08:00
|
|
|
virCommandPtr cmd;
|
2011-11-19 05:21:54 +08:00
|
|
|
struct utsname ut;
|
2011-07-08 05:53:41 +08:00
|
|
|
|
2011-11-19 05:21:54 +08:00
|
|
|
/* Skip test if xend is not running. Calling xend on a non-xen
|
|
|
|
kernel causes some versions of xend to issue a crash report, so
|
|
|
|
we first probe uname results. */
|
|
|
|
uname(&ut);
|
|
|
|
if (strstr(ut.release, "xen") == NULL)
|
|
|
|
return EXIT_AM_SKIP;
|
2011-07-08 05:53:41 +08:00
|
|
|
cmd = virCommandNewArgList("/usr/sbin/xend", "status", NULL);
|
2014-02-20 08:32:19 +08:00
|
|
|
if (virCommandRun(cmd, NULL) < 0) {
|
2011-07-08 05:53:41 +08:00
|
|
|
virCommandFree(cmd);
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
virCommandFree(cmd);
|
2006-09-21 17:15:33 +08:00
|
|
|
|
2013-09-17 21:20:24 +08:00
|
|
|
virtTestQuiesceLibvirtErrors(true);
|
2006-11-09 18:14:01 +08:00
|
|
|
|
|
|
|
conn = virConnectOpen(NULL);
|
|
|
|
if (conn == NULL) {
|
2013-05-24 18:14:02 +08:00
|
|
|
ro = true;
|
2008-04-11 00:54:54 +08:00
|
|
|
conn = virConnectOpenReadOnly(NULL);
|
2006-11-09 18:14:01 +08:00
|
|
|
}
|
2006-09-21 17:15:33 +08:00
|
|
|
if (conn == NULL) {
|
|
|
|
fprintf(stderr, "First virConnectOpen() failed\n");
|
2011-07-09 17:50:38 +08:00
|
|
|
return EXIT_FAILURE;
|
2006-09-21 17:15:33 +08:00
|
|
|
}
|
|
|
|
dom = virDomainLookupByID(conn, id);
|
|
|
|
if (dom == NULL) {
|
|
|
|
fprintf(stderr, "First lookup for domain %d failed\n", id);
|
2011-07-09 17:50:38 +08:00
|
|
|
return EXIT_FAILURE;
|
2006-09-21 17:15:33 +08:00
|
|
|
}
|
|
|
|
virDomainFree(dom);
|
|
|
|
virConnectClose(conn);
|
2013-05-24 18:14:02 +08:00
|
|
|
if (ro)
|
2008-04-11 00:54:54 +08:00
|
|
|
conn = virConnectOpenReadOnly(NULL);
|
2006-11-09 18:14:01 +08:00
|
|
|
else
|
2008-04-11 00:54:54 +08:00
|
|
|
conn = virConnectOpen(NULL);
|
2006-09-21 17:15:33 +08:00
|
|
|
if (conn == NULL) {
|
|
|
|
fprintf(stderr, "Second virConnectOpen() failed\n");
|
2011-07-09 17:50:38 +08:00
|
|
|
return EXIT_FAILURE;
|
2006-09-21 17:15:33 +08:00
|
|
|
}
|
|
|
|
dom = virDomainLookupByID(conn, id);
|
|
|
|
if (dom == NULL) {
|
|
|
|
fprintf(stderr, "Second lookup for domain %d failed\n", id);
|
2011-07-09 17:50:38 +08:00
|
|
|
return EXIT_FAILURE;
|
2006-09-21 17:15:33 +08:00
|
|
|
}
|
|
|
|
virDomainFree(dom);
|
|
|
|
virConnectClose(conn);
|
2008-02-06 03:27:37 +08:00
|
|
|
|
2011-07-09 17:50:38 +08:00
|
|
|
return EXIT_SUCCESS;
|
2006-09-21 17:15:33 +08:00
|
|
|
}
|
2011-07-09 17:50:38 +08:00
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|