aboutsummaryrefslogtreecommitdiffstats
path: root/xenscreen.c
diff options
context:
space:
mode:
Diffstat (limited to 'xenscreen.c')
-rw-r--r--xenscreen.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/xenscreen.c b/xenscreen.c
index c7f0ddf..9a4479d 100644
--- a/xenscreen.c
+++ b/xenscreen.c
@@ -18,7 +18,7 @@
#endif
#include "list.h"
-#include "xenstore.h"
+#include "xs_tools.h"
#include "apps.h"
/* ------------------------------------------------------------- */
@@ -265,17 +265,30 @@ libvirt_xml_xpath_str(const char *doc, char *xpath, char *dest, int len)
return ret;
}
-static void libvirt_scan(virConnectPtr conn)
+static void libvirt_scan(virConnectPtr conn, int boot)
{
int i, count, *ids;
virDomainPtr vdom;
struct dom *dom;
const char *name, *xml;
-
+ struct list_head *item;
+
+ list_for_each(item, &doms) {
+ dom = list_entry(item, struct dom, next);
+ dom->destroyed = 1;
+ }
+
count = virConnectNumOfDomains(conn) + 4;
ids = malloc(count * sizeof(int));
count = virConnectListDomains(conn, ids, count);
for (i = 0; i < count; i++) {
+ dom = find_dom(ids[i]);
+ if (dom) {
+ /* have it */
+ dom->destroyed = 0;
+ continue;
+ }
+ /* new one */
vdom = virDomainLookupByID(conn, ids[i]);
name = virDomainGetName(vdom);
xml = virDomainGetXMLDesc(vdom, 0);
@@ -285,10 +298,16 @@ static void libvirt_scan(virConnectPtr conn)
snprintf(dom->name, sizeof(dom->name), "%s", name);
libvirt_xml_xpath_str(xml, "string(/domain/devices/console/@tty)",
dom->tty, sizeof(dom->tty));
- fprintf(stderr, "%s: tty=\"%s\"\n", dom->name, dom->tty);
- try_attach_domain(dom, 1);
+ fprintf(stderr, "libvirt debug: %s: tty=\"%s\"\n", dom->name, dom->tty);
+ try_attach_domain(dom, boot);
}
free(ids);
+
+ list_for_each(item, &doms) {
+ dom = list_entry(item, struct dom, next);
+ if (dom->destroyed)
+ try_release_domain(dom);
+ }
}
#endif
@@ -416,6 +435,7 @@ int main(int argc, char *argv[])
#ifdef HAVE_LIBVIRT
char *vir_url = getenv("VIRSH_DEFAULT_CONNECT_URI");
virConnectPtr vir_conn = NULL;
+ struct timeval tv;
#else
void *vir_conn = NULL;
#endif
@@ -581,7 +601,7 @@ int main(int argc, char *argv[])
fprintf(stderr,"looking for existing domains\n");
#ifdef HAVE_LIBVIRT
if (vir_conn)
- libvirt_scan(vir_conn);
+ libvirt_scan(vir_conn, 1);
#endif
#ifdef HAVE_XENSTORE
if (xenstore)
@@ -620,18 +640,28 @@ int main(int argc, char *argv[])
FD_SET(fd, &set);
if (maxfd < fd)
maxfd = fd;
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ }
+#endif
+#ifdef HAVE_LIBVIRT
+ if (vir_conn) {
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
}
#endif
- switch (select(maxfd+1, &set, NULL, NULL, NULL)) {
+ switch (select(maxfd+1, &set, NULL, NULL, tv.tv_sec ? &tv : NULL)) {
case -1:
if (EINTR == errno)
continue; /* termsig check */
perror("select");
break;
case 0:
- fprintf(stderr,"Huh, select() timeout?\n");
- exit(1);
+#ifdef HAVE_LIBVIRT
+ if (vir_conn)
+ libvirt_scan(vir_conn, 0);
+#endif
break;
default:
break;