From c0502bd98529eb55e6f1aeb630c551071f648f09 Mon Sep 17 00:00:00 2001 From: kraxel Date: Thu, 16 Aug 2007 09:39:08 +0000 Subject: cleanups --- .cvsignore | 1 + GNUmakefile | 18 +++++++-------- VERSION | 2 +- mdns-publish-vnc.c | 2 +- xd_view.c | 41 -------------------------------- xenlog.c | 2 +- xenscreen.c | 48 ++++++++++++++++++++++++++++++-------- xenstore.c | 68 +++++++++++++++--------------------------------------- xenstore.h | 4 ---- xs_tools.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ xs_tools.h | 4 ++++ xs_view.c | 40 +++++++++++++++++++++++++++----- 12 files changed, 168 insertions(+), 122 deletions(-) delete mode 100644 xenstore.h create mode 100644 xs_tools.c create mode 100644 xs_tools.h diff --git a/.cvsignore b/.cvsignore index 7488888..0a26407 100644 --- a/.cvsignore +++ b/.cvsignore @@ -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 diff --git a/VERSION b/VERSION index 49d5957..3b04cfb 100644 --- a/VERSION +++ b/VERSION @@ -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 #include "list.h" -#include "xenstore.h" +#include "xs_tools.h" #include "mdns-publish.h" /* ------------------------------------------------------------- */ diff --git a/xd_view.c b/xd_view.c index 8034460..cad4816 100644 --- a/xd_view.c +++ b/xd_view.c @@ -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; @@ -398,9 +374,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 = "X", - .callback = menu_cb_xenstore, - },{ - .name = "mDNS", - .label = "mDNS browser", - .callback = menu_cb_mdns, }, }; @@ -493,10 +456,6 @@ static char ui_xml[] = " " " " " " -" " -" " -" " -" " " " " " " " diff --git a/xenlog.c b/xenlog.c index b93bdd4..d7f548b 100644 --- a/xenlog.c +++ b/xenlog.c @@ -4,7 +4,7 @@ #include -#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; diff --git a/xenstore.c b/xenstore.c index f43b9d2..3aaa229 100644 --- a/xenstore.c +++ b/xenstore.c @@ -1,60 +1,28 @@ #include #include +#include +#include +#include +#include +#include +#include -#include +#include -#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/xenstore.h b/xenstore.h deleted file mode 100644 index 047563b..0000000 --- a/xenstore.h +++ /dev/null @@ -1,4 +0,0 @@ -struct xs_handle * xenstore_open(int daemon, int domain, - int readonly_ok, int verbose); -int xenstore_read(struct xs_handle *xenstore, char *path, - char *dst, size_t size); 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 +#include + +#include + +#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; +} diff --git a/xs_tools.h b/xs_tools.h new file mode 100644 index 0000000..047563b --- /dev/null +++ b/xs_tools.h @@ -0,0 +1,4 @@ +struct xs_handle * xenstore_open(int daemon, int domain, + int readonly_ok, int verbose); +int xenstore_read(struct xs_handle *xenstore, char *path, + char *dst, size_t size); diff --git a/xs_view.c b/xs_view.c index 824cf3b..7f791b7 100644 --- a/xs_view.c +++ b/xs_view.c @@ -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 ", 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 = "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 = "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[] = "" " " " " -" " +" " " " " " " " " " " " +" " +" " +" " " " " " -" " +" " " " ""; -- cgit