libvirt/tests/reconnect.c
Jim Meyering e04912a9f0 Remove all trailing blanks; turn on the rule to detect them.
* Makefile.cfg (local-checks-to-skip): Remove sc_trailing_blank.
* .x-sc_trailing_blank: New file, to exempt the few binary files.
2008-02-05 19:27:37 +00:00

58 lines
1.2 KiB
C

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include "libvirt/libvirt.h"
#include "libvirt/virterror.h"
#include "internal.h"
static void errorHandler(void *userData ATTRIBUTE_UNUSED,
virErrorPtr error ATTRIBUTE_UNUSED) {
}
int main(void) {
int id = 0;
int ro = 0;
virConnectPtr conn;
virDomainPtr dom;
virSetErrorFunc(NULL, errorHandler);
conn = virConnectOpen(NULL);
if (conn == NULL) {
ro = 1;
conn = virConnectOpenReadOnly(NULL);
}
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);
if (ro == 1)
conn = virConnectOpenReadOnly(NULL);
else
conn = virConnectOpen(NULL);
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);
}