2006-09-21 09:15:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <libvirt/libvirt.h>
|
2006-11-09 10:14:01 +00:00
|
|
|
#include <libvirt/virterror.h>
|
|
|
|
|
|
|
|
static void errorHandler(void *userData, virErrorPtr error) {
|
|
|
|
}
|
2006-09-21 09:15:33 +00:00
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
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;
|
|
|
|
|
2006-11-09 10:14:01 +00:00
|
|
|
virSetErrorFunc(NULL, errorHandler);
|
|
|
|
|
|
|
|
conn = virConnectOpen(NULL);
|
|
|
|
if (conn == NULL) {
|
|
|
|
ro = 1;
|
|
|
|
conn = virConnectOpenReadOnly(NULL);
|
|
|
|
}
|
2006-09-21 09:15:33 +00:00
|
|
|
if (conn == NULL) {
|
|
|
|
fprintf(stderr, "First virConnectOpen() failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
dom = virDomainLookupByID(conn, id);
|
|
|
|
if (dom == NULL) {
|
|
|
|
fprintf(stderr, "First lookup for domain %d failed\n", id);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
virDomainFree(dom);
|
|
|
|
virConnectClose(conn);
|
2006-11-09 10:14:01 +00:00
|
|
|
if (ro == 1)
|
|
|
|
conn = virConnectOpenReadOnly(NULL);
|
|
|
|
else
|
|
|
|
conn = virConnectOpen(NULL);
|
2006-09-21 09:15:33 +00:00
|
|
|
if (conn == NULL) {
|
|
|
|
fprintf(stderr, "Second virConnectOpen() failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
dom = virDomainLookupByID(conn, id);
|
|
|
|
if (dom == NULL) {
|
|
|
|
fprintf(stderr, "Second lookup for domain %d failed\n", id);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
virDomainFree(dom);
|
|
|
|
virConnectClose(conn);
|
|
|
|
printf("OK\n");
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|