diff options
author | kraxel <kraxel> | 2006-07-04 10:23:57 +0000 |
---|---|---|
committer | kraxel <kraxel> | 2006-07-04 10:23:57 +0000 |
commit | c1cb096a8136c0acb2f8a80f53d2a6ef2bf771bf (patch) | |
tree | e582682fefbbae2a07f72c288a618e3cd377af39 /xd_view.c | |
parent | 95dea4f9392a676d9149c141cd96b62d23ae50bf (diff) | |
download | xenwatch-c1cb096a8136c0acb2f8a80f53d2a6ef2bf771bf.tar.gz |
misc tweaks
Diffstat (limited to 'xd_view.c')
-rw-r--r-- | xd_view.c | 247 |
1 files changed, 97 insertions, 150 deletions
@@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include <unistd.h> #include <string.h> #include <errno.h> @@ -91,57 +92,6 @@ static gboolean get_domain(gint *id, char **name, char **tty, char **os) /* ------------------------------------------------------------------ */ -static int attach_to_screen(gint id, char *name, char *tty) -{ - int rc; - int i; - - /* try attaching to a running screen ... */ - rc = run_application(1, "screen", "screen", - "-X", "-S", "xenconsole", - "screen", "-t", name, tty, - NULL); - if (0 == rc) - return 0; - - /* ... failing that start a new one ... */ - rc = run_application(1, "screen", "screen", - "-d", "-m", "-S", "xenconsole", "-t", name, tty, - NULL); - if (0 != rc) { - gtk_message(GTK_MESSAGE_ERROR, "creating screen session failed\n"); - return -1; - } - - /* ... configure (loop to workaround race) ... */ - for (i = 0; i < 3; i++) { - rc = run_application(1, "screen", "screen", - "-X", "-S", "xenconsole", - "hardstatus", "lastline", - "%{=b bw} xen | %-w%{yb} %n %t* %{-}%+w", - NULL); - if (0 == rc) - break; - sleep(1); - } - if (0 != rc) { - gtk_message(GTK_MESSAGE_ERROR, "configuring screen session failed\n"); - return -1; - } - - /* new screen session created */ - return 1; -} - -static void display_screen_xterm(void) -{ - run_application(0, "xterm", "xterm", - "-name", "xenconsole", - "-title", "xen consoles via screen", - "-e", "screen", "-d", "-r", "xenconsole", - NULL); -} - static void open_xenconsole(gint id, char *name, char *tty) { char title[64], ids[8]; @@ -150,13 +100,13 @@ static void open_xenconsole(gint id, char *name, char *tty) snprintf(ids, sizeof(ids), "%d", id); run_application(0, "xterm", "xterm", - "-name", "xenconsole", + "-name", "console_xterm", "-title", title, "-e", XENCONSOLE, ids, NULL); } -static void open_tty(gint id, char *name, char *tty, int screen) +static void open_tty(gint id, char *name, char *tty) { int rc; @@ -173,19 +123,10 @@ static void open_tty(gint id, char *name, char *tty, int screen) } /* open terminal */ - if (screen) { - if (have_application("screen")) { - if (1 == attach_to_screen(id, name, tty)) - display_screen_xterm(); - } else { - gtk_message(GTK_MESSAGE_ERROR, "need screen, please install\n"); - } + if (have_application(XENCONSOLE)) { + open_xenconsole(id, name, tty); } else { - if (have_application(XENCONSOLE)) { - open_xenconsole(id, name, tty); - } else { - gtk_message(GTK_MESSAGE_ERROR, "need xen-tools, please install\n"); - } + gtk_message(GTK_MESSAGE_ERROR, "need xen-tools, please install\n"); } } @@ -202,44 +143,22 @@ static void open_vnc(gint id, char *name, char *ostype) /* ------------------------------------------------------------------ */ -#if 0 -static int xc_action(int (*func)(int xc_handle, uint32_t domid)) -{ - char *name, *tty, *ostype; - gint id = -1; - int xc_handle; - int rc; - - if (!get_domain(&id, &name, &tty, &ostype)) - return -1; - xc_handle = xc_interface_open(); - if (-1 == xc_handle) { - gtk_message(GTK_MESSAGE_ERROR, "can't open control interface\n"); - return -1; - } - rc = func(xc_handle, id); - xc_interface_close(xc_handle); - if (-1 == rc) - gtk_message(GTK_MESSAGE_ERROR, "xc action failed\n"); - return rc; -} -#endif - -static int xend_request(char *req) +static int xmlrpc_request(char *method, ...) { struct addrinfo ask; char *host = "localhost"; - char *serv = "8000"; + char *serv = "8005"; struct sockaddr_un unix_xend = { .sun_family = PF_UNIX, - .sun_path = "/var/lib/xend/xend-socket", + .sun_path = "/var/run/xend/xmlrpc.sock", }; + va_list args; char head[256]; - char body[256]; - char reply[256]; - int sock,lhead, lbody, rc; - char *name, *tty, *ostype; + char body[1024]; + char reply[1024]; + int sock,lhead, lbody, lreply, rc, eof; + char *name, *tty, *ostype, *arg; gint id = -1; struct timeval tv; fd_set rd; @@ -263,29 +182,88 @@ static int xend_request(char *req) } connected: - lbody = snprintf(body, sizeof(body), "%s", req); + /* req start + method name */ + lbody = snprintf(body, sizeof(body), + "<?xml version=\'1.0\'?>\n" + "<methodCall>\n" + " <methodName>%s</methodName>\n" + " <params>\n", + method); + /* domain */ + lbody += snprintf(body + lbody, sizeof(body) - lbody, + " <param>\n" + " <value><int>%d</int></value>\n" + " </param>\n", + id); + + /* maybe more args */ + va_start(args, method); + for (;;) { + arg = va_arg(args, char*); + if (NULL == arg) + break; + lbody += snprintf(body + lbody, sizeof(body) - lbody, + " <param>\n" + " <value><string>%s</string></value>\n" + " </param>\n", + arg); + } + va_end(args); + + /* finish off */ + lbody += snprintf(body + lbody, sizeof(body) - lbody, + " </params>\n" + "</methodCall>\n"); + if (debug) + write(2, body, lbody); + + /* http header */ lhead = snprintf(head, sizeof(head), - "POST /xend/domain/%s HTTP/1.1\r\n" + "POST /RPC2 HTTP/1.0\r\n" "Host: %s\r\n" - "Accept-Encoding: identity\r\n" - "Content-Type: application/x-www-form-urlencoded\r\n" + "User-Agent: xenwatch\r\n" + "Content-Type: text/xml\r\n" "Content-Length: %d\r\n" "\r\n", - name, host, lbody); + host, lbody); write(sock, head, lhead); write(sock, body, lbody); - FD_ZERO(&rd); - FD_SET(sock, &rd); - tv.tv_sec = 3; - tv.tv_usec = 0; - if (1 == select(sock+1, &rd, NULL, NULL, &tv)) { - rc = read(sock, reply, sizeof(reply)); - /* FIXME: ignore response for now ... */ - } else { - gtk_message(GTK_MESSAGE_ERROR, "Huh, no xend reply?\n"); + for (lreply = 0, eof = 0; !eof;) { + FD_ZERO(&rd); + FD_SET(sock, &rd); + tv.tv_sec = 3; + tv.tv_usec = 0; + if (1 == select(sock+1, &rd, NULL, NULL, &tv)) { + rc = read(sock, reply + lreply, sizeof(reply) - lreply -1); + switch (rc) { + case -1: + perror("read"); + /* fall through */ + case 0: + eof = 1; + break; + default: + lreply += rc; + reply[lreply] = 0; + break; + } + } } close(sock); + + if (!lreply) { + gtk_message(GTK_MESSAGE_ERROR, "Huh, no xend reply?\n"); + return -1; + } + + if (NULL != strstr(reply, "<fault>")) { + gtk_message(GTK_MESSAGE_ERROR, "XMLRPC call failed:\n\n%s", reply); + return -1; + } + + if (debug) + write(2, reply, lreply); return 0; } @@ -341,49 +319,32 @@ static void menu_cb_open_console(void) return; if (debug) fprintf(stderr, "%s: %d\n", __FUNCTION__, id); - open_tty(id, name, tty, 0); -} - -static void menu_cb_attach_screen(void) -{ - char *name, *tty, *ostype; - gint id = -1; - - if (!get_domain(&id, &name, &tty, &ostype)) - return; - if (debug) - fprintf(stderr, "%s: %d\n", __FUNCTION__, id); - open_tty(id, name, tty, 1); -} - -static void menu_cb_display_screen(void) -{ - display_screen_xterm(); + open_tty(id, name, tty); } static void menu_cb_domain_pause(void) { - xend_request("op=pause"); + xmlrpc_request("xend.domain.pause", NULL); } static void menu_cb_domain_unpause(void) { - xend_request("op=unpause"); + xmlrpc_request("xend.domain.unpause", NULL); } static void menu_cb_domain_shutdown(void) { - xend_request("op=shutdown&reason=poweroff"); + xmlrpc_request("xend.domain.shutdown", "poweroff", NULL); } static void menu_cb_domain_reboot(void) { - xend_request("op=shutdown&reason=reboot"); + xmlrpc_request("xend.domain.shutdown", "reboot", NULL); } static void menu_cb_domain_destroy(void) { - xend_request("op=destroy"); + xmlrpc_request("xend.domain.destroy", NULL); } static void menu_cb_about(void) @@ -452,28 +413,17 @@ static const GtkActionEntry entries[] = { .accelerator = "<control>C", .tooltip = "Open xterm with console", .callback = menu_cb_open_console, - },{ - .name = "AttachScreen", - .label = "_Screen", - .accelerator = "<control>S", - .tooltip = "Attach console to the xenconsole screen session", - .callback = menu_cb_attach_screen, - },{ - .name = "DisplayScreen", - .label = "Show screen _xterm", - .tooltip = "Display xterm with the xenconsole screen session", - .callback = menu_cb_display_screen, },{ .name = "DomainPause", .stock_id = GTK_STOCK_MEDIA_PAUSE, - .label = "Pause", + .label = "_Pause", .tooltip = "Pause domain", .callback = menu_cb_domain_pause, },{ .name = "DomainUnpause", .stock_id = GTK_STOCK_MEDIA_PLAY, - .label = "Unpause", + .label = "_Unpause", .tooltip = "Unpause domain", .callback = menu_cb_domain_unpause, },{ @@ -486,13 +436,13 @@ static const GtkActionEntry entries[] = { },{ .name = "DomainShutdown", .stock_id = GTK_STOCK_STOP, - .label = "Shutdown", + .label = "_Shutdown", .tooltip = "Graceful shutdown of the domain", .callback = menu_cb_domain_shutdown, },{ .name = "DomainDestroy", .stock_id = GTK_STOCK_DELETE, - .label = "_Destroy", + .label = "Destroy", .tooltip = "Radically kill off domain", .callback = menu_cb_domain_destroy, },{ @@ -517,8 +467,6 @@ static char ui_xml[] = " <menu action='DomainMenu'>" " <menuitem action='OpenVNC'/>" " <menuitem action='OpenConsole'/>" -" <menuitem action='AttachScreen'/>" -" <menuitem action='DisplayScreen'/>" " <separator/>" " <menuitem action='DomainPause'/>" " <menuitem action='DomainUnpause'/>" @@ -540,7 +488,6 @@ static char ui_xml[] = #if 0 " <toolitem action='OpenVNC'/>" " <toolitem action='OpenConsole'/>" -" <toolitem action='AttachScreen'/>" " <separator/>" #endif " <toolitem action='DomainReboot'/>" |