diff options
author | kraxel <kraxel> | 2007-08-16 09:39:08 +0000 |
---|---|---|
committer | kraxel <kraxel> | 2007-08-16 09:39:08 +0000 |
commit | c0502bd98529eb55e6f1aeb630c551071f648f09 (patch) | |
tree | da4c50825b640f1c3c82bed24be557a085ff7a10 | |
parent | dbe2e2d981739d80417288a57872d2e24c5acf1d (diff) | |
download | xenwatch-c0502bd98529eb55e6f1aeb630c551071f648f09.tar.gz |
cleanups
-rw-r--r-- | .cvsignore | 1 | ||||
-rw-r--r-- | GNUmakefile | 18 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | mdns-publish-vnc.c | 2 | ||||
-rw-r--r-- | xd_view.c | 41 | ||||
-rw-r--r-- | xenlog.c | 2 | ||||
-rw-r--r-- | xenscreen.c | 48 | ||||
-rw-r--r-- | xenstore.c | 68 | ||||
-rw-r--r-- | xs_tools.c | 60 | ||||
-rw-r--r-- | xs_tools.h (renamed from xenstore.h) | 0 | ||||
-rw-r--r-- | xs_view.c | 40 |
11 files changed, 164 insertions, 118 deletions
@@ -3,6 +3,7 @@ xenlog xenscreen xenscreenrc xenwatch +xenstore mdns-browser mdns-publish-xendom mdns-publish-vnc diff --git a/GNUmakefile b/GNUmakefile index 79ef2b7..857a7d8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -7,14 +7,14 @@ CFLAGS += -DVERSION='"$(VERSION)"' -DLIB='"$(LIB)"' # build TARGETS := xenlog xenscreen -BUILD_GTK := xenwatch mdns-browser +BUILD_GTK := xenwatch xenstore mdns-browser BUILD_AVAHI := mdns-publish-xendom mdns-publish-vnc BUILD_VNCCLIENT := vnc-client -NEEDS_XENSTORE := xenlog xenscreen xenwatch mdns-publish-xendom mdns-publish-vnc +NEEDS_XENSTORE := xenlog xenscreen xenwatch xenstore mdns-publish-xendom mdns-publish-vnc NEEDS_LIBVIRT := xenscreen -NEEDS_GTK := xenwatch mdns-browser vnc-client -NEEDS_AVAHI := xenwatch mdns-browser mdns-publish-xendom mdns-publish-vnc +NEEDS_GTK := xenwatch xenstore mdns-browser vnc-client +NEEDS_AVAHI := mdns-browser mdns-publish-xendom mdns-publish-vnc NEEDS_VNCCLIENT := xenwatch mdns-browser vnc-client # default target @@ -93,13 +93,13 @@ realclean distclean: clean ############################################# -xenlog: xenlog.o xenstore.o -xenscreen: xenscreen.o xenstore.o apps.o -xenwatch: xenwatch.o xs_view.o xs_store.o xd_view.o xd_store.o \ - apps.o apps-x11.o tcp.o mdns.o vnc.o x11.o +xenlog: xenlog.o xs_tools.o +xenscreen: xenscreen.o xs_tools.o apps.o +xenwatch: xenwatch.o xd_view.o xd_store.o apps.o apps-x11.o tcp.o vnc.o x11.o +xenstore: xenstore.o xs_view.o xs_store.o mdns-browser: mdns-browser.o mdns.o vnc.o x11.o apps.o apps-x11.o mdns-publish-xendom: mdns-publish-xendom.o mdns-publish.o -mdns-publish-vnc: mdns-publish-vnc.o mdns-publish.o xenstore.o +mdns-publish-vnc: mdns-publish-vnc.o mdns-publish.o xs_tools.o vnc-client: vnc-client.o vnc.o x11.o xenscreenrc: xenscreen @@ -1 +1 @@ -0.1 +0.2 diff --git a/mdns-publish-vnc.c b/mdns-publish-vnc.c index f73f586..0d5bf89 100644 --- a/mdns-publish-vnc.c +++ b/mdns-publish-vnc.c @@ -12,7 +12,7 @@ #include <xs.h> #include "list.h" -#include "xenstore.h" +#include "xs_tools.h" #include "mdns-publish.h" /* ------------------------------------------------------------- */ @@ -277,30 +277,6 @@ static void menu_cb_quit(void) gtk_widget_destroy(xd_toplevel); } -static void menu_cb_xenstore(void) -{ - if (NULL == xs_toplevel) - xenstore_create_window(); - gtk_widget_show_all(xs_toplevel); -} - -static void menu_cb_mdns(void) -{ -#ifdef HAVE_AVAHI - struct mdns_window *mdns; - - mdns = mdns_create_window(0, MDNS_VIEW_XEN, NULL); - if (NULL == mdns) { - gtk_message(GTK_MESSAGE_ERROR, "Can't setup mDNS browser, sorry.\n"); - return; - } - mdns_browse(mdns, 1, "_xendom._tcp", NULL); - mdns_show_window(mdns); -#else - gtk_message(GTK_MESSAGE_ERROR, "Compiled without mDNS support, sorry.\n"); -#endif -} - static void menu_cb_open_vnc(void) { char *name, *tty, *ostype; @@ -399,9 +375,6 @@ static const GtkActionEntry entries[] = { .name = "DomainMenu", .label = "_Domain", },{ - .name = "WindowMenu", - .label = "_Window", - },{ .name = "HelpMenu", .label = "_Help", },{ @@ -463,16 +436,6 @@ static const GtkActionEntry entries[] = { .label = "Destroy", .tooltip = "Radically kill off domain", .callback = menu_cb_domain_destroy, - },{ - - .name = "Xenstore", - .label = "_Xenstore browser", - .accelerator = "<control>X", - .callback = menu_cb_xenstore, - },{ - .name = "mDNS", - .label = "mDNS browser", - .callback = menu_cb_mdns, }, }; @@ -493,10 +456,6 @@ static char ui_xml[] = " <menuitem action='DomainShutdown'/>" " <menuitem action='DomainDestroy'/>" " </menu>" -" <menu action='WindowMenu'>" -" <menuitem action='Xenstore'/>" -" <menuitem action='mDNS'/>" -" </menu>" " <menu action='HelpMenu'>" " <menuitem action='About'/>" " </menu>" @@ -4,7 +4,7 @@ #include <xs.h> -#include "xenstore.h" +#include "xs_tools.h" /* ------------------------------------------------------------- */ 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; @@ -1,60 +1,28 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> +#include <locale.h> +#include <signal.h> -#include <xs.h> +#include <gtk/gtk.h> -#include "xenstore.h" +#include "xenviews.h" -/* ------------------------------------------------------------- */ +/* ------------------------------------------------------------------ */ -struct xs_handle *xenstore_open(int daemon, int domain, - int readonly_ok, int verbose) +int +main(int argc, char *argv[]) { - struct xs_handle *xenstore = NULL; + setlocale(LC_ALL,""); + gtk_init(&argc, &argv); - if (NULL == xenstore && daemon && readonly_ok) { - xenstore = xs_daemon_open_readonly(); - if (NULL == xenstore) - fprintf(stderr,"can't connect to %s\n",xs_daemon_socket_ro()); - else - if (verbose) - printf("connected to %s\n", xs_daemon_socket_ro()); - } + xenstore_create_window(); + gtk_widget_show_all(xs_toplevel); - if (NULL == xenstore && daemon) { - xenstore = xs_daemon_open(); - if (NULL == xenstore) - fprintf(stderr,"can't connect to %s\n",xs_daemon_socket()); - else - if (verbose) - printf("connected to %s\n", xs_daemon_socket()); - } - - if (NULL == xenstore && domain) { - xenstore = xs_domain_open(); - if (NULL == xenstore) - fprintf(stderr, "can't connect to %s\n", xs_domain_dev()); - else - if (verbose) - printf("connected to %s\n", xs_domain_dev()); - } - return xenstore; -} - -int xenstore_read(struct xs_handle *xenstore, char *path, char *dst, size_t size) -{ - xs_transaction_t xst; - char *xs_value = NULL; - - xst = xs_transaction_start(xenstore); - if (!xst) - return -1; - - xs_value = xs_read(xenstore, xst, path, NULL); - xs_transaction_end(xenstore, xst, 0); - if (NULL == xs_value) - return -2; - snprintf(dst, size, "%s", xs_value); - free(xs_value); - return 0; + gtk_main(); + fprintf(stderr,"bye...\n"); + exit(0); } diff --git a/xs_tools.c b/xs_tools.c new file mode 100644 index 0000000..5a72b45 --- /dev/null +++ b/xs_tools.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <xs.h> + +#include "xs_tools.h" + +/* ------------------------------------------------------------- */ + +struct xs_handle *xenstore_open(int daemon, int domain, + int readonly_ok, int verbose) +{ + struct xs_handle *xenstore = NULL; + + if (NULL == xenstore && daemon && readonly_ok) { + xenstore = xs_daemon_open_readonly(); + if (NULL == xenstore) + fprintf(stderr,"can't connect to %s\n",xs_daemon_socket_ro()); + else + if (verbose) + printf("connected to %s\n", xs_daemon_socket_ro()); + } + + if (NULL == xenstore && daemon) { + xenstore = xs_daemon_open(); + if (NULL == xenstore) + fprintf(stderr,"can't connect to %s\n",xs_daemon_socket()); + else + if (verbose) + printf("connected to %s\n", xs_daemon_socket()); + } + + if (NULL == xenstore && domain) { + xenstore = xs_domain_open(); + if (NULL == xenstore) + fprintf(stderr, "can't connect to %s\n", xs_domain_dev()); + else + if (verbose) + printf("connected to %s\n", xs_domain_dev()); + } + return xenstore; +} + +int xenstore_read(struct xs_handle *xenstore, char *path, char *dst, size_t size) +{ + xs_transaction_t xst; + char *xs_value = NULL; + + xst = xs_transaction_start(xenstore); + if (!xst) + return -1; + + xs_value = xs_read(xenstore, xst, path, NULL); + xs_transaction_end(xenstore, xst, 0); + if (NULL == xs_value) + return -2; + snprintf(dst, size, "%s", xs_value); + free(xs_value); + return 0; +} @@ -44,11 +44,28 @@ static void menu_cb_expand_all(void) gtk_tree_view_expand_all(GTK_TREE_VIEW(view)); } +static void menu_cb_about(void) +{ + static char *comments = "xenstore browser"; + static char *copyright = "(c) 2005-2007 Gerd Hoffmann"; + static char *authors[] = { "Gerd Hoffmann <kraxel@redhat.com>", NULL }; + + gtk_show_about_dialog(GTK_WINDOW(xs_toplevel), + "authors", authors, + "comments", comments, + "copyright", copyright, + "logo-icon-name", GTK_STOCK_ABOUT, + "version", VERSION, + NULL); +} + static void destroy(GtkWidget *widget, gpointer data) { g_object_unref(store); xs_toplevel = NULL; + + gtk_main_quit(); } /* ------------------------------------------------------------------ */ @@ -58,10 +75,9 @@ static const GtkActionEntry entries[] = { .name = "FileMenu", .label = "_File", },{ - .name = "Close", - .stock_id = GTK_STOCK_CLOSE, - .label = "_Close", - .accelerator = "<control>Q", + .name = "Quit", + .stock_id = GTK_STOCK_QUIT, + .label = "_Quit", .callback = menu_cb_close, },{ @@ -77,6 +93,15 @@ static const GtkActionEntry entries[] = { .label = "Expand _all", .accelerator = "<control>A", .callback = menu_cb_expand_all, + },{ + + .name = "HelpMenu", + .label = "_Help", + },{ + .name = "About", + .stock_id = GTK_STOCK_ABOUT, + .label = "_About ...", + .callback = menu_cb_about, }, }; @@ -84,15 +109,18 @@ static char ui_xml[] = "<ui>" " <menubar name='MainMenu'>" " <menu action='FileMenu'>" -" <menuitem action='Close'/>" +" <menuitem action='Quit'/>" " </menu>" " <menu action='ViewMenu'>" " <menuitem action='ExpandSubTree'/>" " <menuitem action='ExpandAll'/>" " </menu>" +" <menu action='HelpMenu'>" +" <menuitem action='About'/>" +" </menu>" " </menubar>" " <toolbar action='ToolBar'>" -" <toolitem action='Close'/>" +" <toolitem action='Quit'/>" " </toolbar>" "</ui>"; |