aboutsummaryrefslogtreecommitdiffstats
path: root/xd_view.c
diff options
context:
space:
mode:
authorkraxel <kraxel>2006-04-06 15:18:48 +0000
committerkraxel <kraxel>2006-04-06 15:18:48 +0000
commite16b25e7d718809a3eddfa9cae63a20a1b1c20ac (patch)
treef84d8056df0003ba808919049a834c5ea9a5725c /xd_view.c
parent1131de02524b7d4d87c804cc18f8ec0337b20e70 (diff)
downloadxenwatch-e16b25e7d718809a3eddfa9cae63a20a1b1c20ac.tar.gz
desktop detection, app start reorganization
Diffstat (limited to 'xd_view.c')
-rw-r--r--xd_view.c131
1 files changed, 7 insertions, 124 deletions
diff --git a/xd_view.c b/xd_view.c
index dbec3cd..16fa78f 100644
--- a/xd_view.c
+++ b/xd_view.c
@@ -17,8 +17,7 @@
#include "xenviews.h"
#include "tcp.h"
#include "mdns.h"
-
-#define XENCONSOLE "/usr/" LIB "/xen/bin/xenconsole"
+#include "apps.h"
#define array_size(x) (sizeof(x)/sizeof(*x))
@@ -30,11 +29,6 @@ static GtkWidget *status;
static XenDoms *store;
static GtkWidget *view;
-static int have_screen;
-static int have_xenconsole;
-static int have_krdc;
-static int have_vncviewer;
-
static int debug = 0;
/* ------------------------------------------------------------------ */
@@ -97,98 +91,6 @@ static gboolean get_domain(gint *id, char **name, char **tty, char **os)
/* ------------------------------------------------------------------ */
-static gboolean have_binary(char *name)
-{
- char *path, *elem, *binary;
- struct stat st;
- int rc;
-
- if (strchr(name,'/')) {
- /* path specified ... */
- if (-1 == stat(name, &st))
- return false;
- if (!S_ISREG(st.st_mode))
- return false;
- if (!(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
- return false;
- return true;
- }
-
- /* walk $PATH */
- path = getenv("PATH");
- if (NULL == path)
- return false;
- path = strdup(path);
- for (elem = strtok(path, ":"); NULL != elem; elem = strtok(NULL, ":")) {
- binary = malloc(strlen(elem)+strlen(name)+2);
- sprintf(binary, "%s/%s", elem, name);
- rc = stat(binary, &st);
- free(binary);
- if (-1 == rc)
- continue;
- if (!S_ISREG(st.st_mode))
- continue;
- if (!(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
- continue;
- free(path);
- return true;
- }
- free(path);
- return false;
-}
-
-static int run_application(int do_wait, const char *app, ...)
-{
- va_list args;
- char *argv[64];
- int status, rc, i;
- pid_t pid;
-
- while (waitpid(-1, &status, WNOHANG) > 0)
- /* collect zombies */;
-
- if (debug)
- fprintf(stderr,"%s: %s |", __FUNCTION__, app);
- va_start(args, app);
- for (i = 0; i < array_size(argv); i++) {
- argv[i] = va_arg(args, char*);
- if (NULL == argv[i])
- break;
- if (debug)
- fprintf(stderr,"%s \"%s\"", (0 == i) ? "" : ",", argv[i]);
- }
- va_end(args);
- if (debug)
- fprintf(stderr,"\n");
-
- if (array_size(argv) == i) {
- fprintf(stderr,"%s: oops: argv too small\n", __FUNCTION__);
- return -1;
- }
-
- if (0 == (pid = fork())) {
- /* child */
- execvp(app, argv);
- fprintf(stderr,"%s: execvp(%s): %s\n", __FUNCTION__,
- app, strerror(errno));
- exit(1);
- }
-
- if (!do_wait)
- return 0;
-
- rc = waitpid(pid, &status, 0);
- if (rc != pid) {
- /* Huh? */
- fprintf(stderr,"%s: waidpid(%d): %s\n", __FUNCTION__,
- pid, strerror(errno));
- exit(1);
- }
- if (!WIFEXITED(status))
- return -1;
- return WEXITSTATUS(status);
-}
-
static int attach_to_screen(gint id, char *name, char *tty)
{
int rc;
@@ -272,14 +174,14 @@ static void open_tty(gint id, char *name, char *tty, int screen)
/* open terminal */
if (screen) {
- if (have_screen) {
+ if (app_have_screen) {
if (1 == attach_to_screen(id, name, tty))
display_screen_xterm();
} else {
gtk_message(GTK_MESSAGE_ERROR, "need screen, please install\n");
}
} else {
- if (have_xenconsole) {
+ if (app_have_xenconsole) {
open_xenconsole(id, name, tty);
} else {
gtk_message(GTK_MESSAGE_ERROR, "need xen-tools, please install\n");
@@ -289,35 +191,15 @@ static void open_tty(gint id, char *name, char *tty, int screen)
static void open_vnc(gint id, char *name, char *ostype)
{
- char *app = NULL;
- char display[32];
-
- if (have_vncviewer) {
- app = "vncviewer";
- } else if (have_krdc) {
- app = "krdc";
- } else {
- gtk_message(GTK_MESSAGE_ERROR, "need vncviewer or krdc, please install\n");
- return;
- }
-
if (0 == strcmp(ostype, "vmx")) {
/* works for vmx ... */
- snprintf(display, sizeof(display), "localhost:%d", id);
- run_application(0, app, app, display, NULL);
+ if (-1 == open_vnc_session("localhost", id))
+ gtk_message(GTK_MESSAGE_ERROR, app_error);
} else {
gtk_message(GTK_MESSAGE_ERROR, "VNC works for vmx domains only.\n");
}
}
-static void detect_apps(void)
-{
- have_screen = have_binary("screen");
- have_xenconsole = have_binary(XENCONSOLE);
- have_krdc = have_binary("krdc");
- have_vncviewer = have_binary("vncviewer");
-}
-
/* ------------------------------------------------------------------ */
#if 0
@@ -826,6 +708,7 @@ void xen_doms_create_window(void)
gtk_container_add(GTK_CONTAINER(scroll), view);
gtk_box_pack_end(GTK_BOX(vbox), status, FALSE, TRUE, 0);
- detect_apps();
+ detect_applications();
+ detect_desktop();
return;
}