aboutsummaryrefslogtreecommitdiffstats
path: root/xd_view.c
diff options
context:
space:
mode:
authorkraxel <kraxel>2005-12-16 17:05:31 +0000
committerkraxel <kraxel>2005-12-16 17:05:31 +0000
commit6b767b90916a843ef5c23dc6cb670893607d9f01 (patch)
treea292522287d3aaedbb456288263a7f9541cd1241 /xd_view.c
parent6dbf21b755ea62b3bb0ecf82b00b4597e43d3bae (diff)
downloadxenwatch-6b767b90916a843ef5c23dc6cb670893607d9f01.tar.gz
- GUI fixups, xend improvements.
Diffstat (limited to 'xd_view.c')
-rw-r--r--xd_view.c145
1 files changed, 114 insertions, 31 deletions
diff --git a/xd_view.c b/xd_view.c
index c4bca88..3287793 100644
--- a/xd_view.c
+++ b/xd_view.c
@@ -6,13 +6,16 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/un.h>
#include <gtk/gtk.h>
#include <xs.h>
-#include <xenctrl.h>
#include "xd_store.h"
#include "xenviews.h"
+#include "tcp.h"
#define XENCONSOLE "/usr/lib/xen/bin/xenconsole"
@@ -188,6 +191,7 @@ static int run_application(int do_wait, const char *app, ...)
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",
@@ -205,14 +209,18 @@ static int attach_to_screen(gint id, char *name, char *tty)
gtk_message(GTK_MESSAGE_ERROR, "creating screen session failed\n");
return -1;
}
- sleep(1); /* workaround for the race we have here ... */
- /* ... configure ... */
- rc = run_application(1, "screen", "screen",
- "-X", "-S", "xenconsole",
- "hardstatus", "lastline",
- "%{=b bw} xen | %-w%{yb} %n %t* %{-}%+w",
- NULL);
+ /* ... 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;
@@ -311,6 +319,7 @@ static void detect_apps(void)
/* ------------------------------------------------------------------ */
+#if 0
static int xc_action(int (*func)(int xc_handle, uint32_t domid))
{
char *name, *tty, *ostype;
@@ -331,6 +340,71 @@ static int xc_action(int (*func)(int xc_handle, uint32_t domid))
gtk_message(GTK_MESSAGE_ERROR, "xc action failed\n");
return rc;
}
+#endif
+
+static int xend_request(char *req)
+{
+ struct addrinfo ask;
+ char *host = "localhost";
+ char *serv = "8000";
+ struct sockaddr_un unix_xend = {
+ .sun_family = PF_UNIX,
+ .sun_path = "/var/lib/xend/xend-socket",
+ };
+
+ char head[256];
+ char body[256];
+ char reply[256];
+ int sock,lhead, lbody, rc;
+ char *name, *tty, *ostype;
+ gint id = -1;
+ struct timeval tv;
+ fd_set rd;
+
+ if (!get_domain(&id, &name, &tty, &ostype))
+ return -1;
+
+ /* try tcp first */
+ memset(&ask,0,sizeof(ask));
+ ask.ai_socktype = SOCK_STREAM;
+ ask.ai_family = PF_UNSPEC;
+ sock = tcp_connect(&ask, NULL, NULL, host, serv);
+ if (0 == sock)
+ goto connected;
+
+ /* failing that unix sockets */
+ sock = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (-1 == connect(sock, (struct sockaddr*)&unix_xend, sizeof(unix_xend))) {
+ gtk_message(GTK_MESSAGE_ERROR, "can't connect to xend\n");
+ return -1;
+ }
+
+ connected:
+ lbody = snprintf(body, sizeof(body), "%s", req);
+ lhead = snprintf(head, sizeof(head),
+ "POST /xend/domain/%s HTTP/1.1\r\n"
+ "Host: %s\r\n"
+ "Accept-Encoding: identity\r\n"
+ "Content-Type: application/x-www-form-urlencoded\r\n"
+ "Content-Length: %d\r\n"
+ "\r\n",
+ name, 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");
+ }
+ close(sock);
+ return 0;
+}
/* ------------------------------------------------------------------ */
@@ -389,27 +463,27 @@ static void menu_cb_display_screen(void)
static void menu_cb_domain_pause(void)
{
- xc_action(xc_domain_pause);
+ xend_request("op=pause");
}
static void menu_cb_domain_unpause(void)
{
- xc_action(xc_domain_unpause);
+ xend_request("op=unpause");
}
static void menu_cb_domain_shutdown(void)
{
- gtk_message(GTK_MESSAGE_INFO, "shutdown is not implemented yet\n");
+ xend_request("op=shutdown&reason=poweroff");
}
static void menu_cb_domain_reboot(void)
{
- gtk_message(GTK_MESSAGE_INFO, "reboot is not implemented yet\n");
+ xend_request("op=shutdown&reason=reboot");
}
static void menu_cb_domain_destroy(void)
{
- xc_action(xc_domain_destroy);
+ xend_request("op=destroy");
}
static void menu_cb_about(void)
@@ -443,12 +517,12 @@ static const GtkActionEntry entries[] = {
.name = "FileMenu",
.label = "_File",
},{
- .name = "ViewMenu",
- .label = "_View",
- },{
.name = "DomainMenu",
.label = "_Domain",
},{
+ .name = "WindowMenu",
+ .label = "_Window",
+ },{
.name = "HelpMenu",
.label = "_Help",
},{
@@ -476,45 +550,56 @@ static const GtkActionEntry entries[] = {
.name = "OpenVNC",
.label = "_VNC",
.accelerator = "<control>V",
+ .tooltip = "Open VNC viewer (vmx domains only)",
.callback = menu_cb_open_vnc,
},{
.name = "OpenConsole",
.label = "_Console",
.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",
+ .tooltip = "Pause domain",
.callback = menu_cb_domain_pause,
},{
.name = "DomainUnpause",
.stock_id = GTK_STOCK_MEDIA_PLAY,
.label = "Unpause",
+ .tooltip = "Unpause domain",
.callback = menu_cb_domain_unpause,
},{
- .name = "DomainShutdown",
- .stock_id = GTK_STOCK_MEDIA_STOP,
- .label = "Shutdown",
- .callback = menu_cb_domain_shutdown,
- },{
.name = "DomainReboot",
.stock_id = GTK_STOCK_REFRESH,
- .label = "Reboot",
+ .label = "_Reboot",
+ .accelerator = "<control>R",
+ .tooltip = "Reboot domain",
.callback = menu_cb_domain_reboot,
},{
+ .name = "DomainShutdown",
+ .stock_id = GTK_STOCK_STOP,
+ .label = "Shutdown",
+ .tooltip = "Graceful shutdown of the domain",
+ .callback = menu_cb_domain_shutdown,
+ },{
.name = "DomainDestroy",
- .label = "Destroy",
+ .stock_id = GTK_STOCK_DELETE,
+ .label = "_Destroy",
+ .tooltip = "Radically kill off domain",
.callback = menu_cb_domain_destroy,
},
};
@@ -525,9 +610,6 @@ static char ui_xml[] =
" <menu action='FileMenu'>"
" <menuitem action='Quit'/>"
" </menu>"
-" <menu action='ViewMenu'>"
-" <menuitem action='Xenstore'/>"
-" </menu>"
" <menu action='DomainMenu'>"
" <menuitem action='OpenVNC'/>"
" <menuitem action='OpenConsole'/>"
@@ -536,10 +618,13 @@ static char ui_xml[] =
" <separator/>"
" <menuitem action='DomainPause'/>"
" <menuitem action='DomainUnpause'/>"
-" <menuitem action='DomainShutdown'/>"
" <menuitem action='DomainReboot'/>"
+" <menuitem action='DomainShutdown'/>"
" <menuitem action='DomainDestroy'/>"
" </menu>"
+" <menu action='WindowMenu'>"
+" <menuitem action='Xenstore'/>"
+" </menu>"
" <menu action='HelpMenu'>"
" <menuitem action='About'/>"
" </menu>"
@@ -553,10 +638,8 @@ static char ui_xml[] =
" <toolitem action='AttachScreen'/>"
" <separator/>"
#endif
-" <toolitem action='DomainPause'/>"
-" <toolitem action='DomainUnpause'/>"
-" <toolitem action='DomainShutdown'/>"
" <toolitem action='DomainReboot'/>"
+" <toolitem action='DomainShutdown'/>"
" </toolbar>"
"</ui>";
@@ -674,7 +757,7 @@ void xen_doms_create_window(void)
xd_toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(xd_toplevel), _("xendoms"));
- gtk_widget_set_size_request(GTK_WIDGET(xd_toplevel), 400, 300);
+ gtk_widget_set_size_request(GTK_WIDGET(xd_toplevel), 480, 320);
g_signal_connect(G_OBJECT(xd_toplevel), "destroy",
G_CALLBACK(destroy), NULL);