From 017d3fac30a7d6f28046b541e7926b9e151f9d7c Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Tue, 12 Jan 2021 10:06:25 +0100 Subject: use gterm if installed --- meson.build | 1 - vconsole.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index bdc03fc..c11c2c8 100644 --- a/meson.build +++ b/meson.build @@ -24,7 +24,6 @@ configure_file(output : 'config.h', configuration : config) add_global_arguments(['-include', 'config.h'], language : 'c') # build & install - stringify = find_program('./stringify.sh') main_ui = custom_target('main-ui', input : ['main.ui'], diff --git a/vconsole.c b/vconsole.c index 15372ef..79fe70f 100644 --- a/vconsole.c +++ b/vconsole.c @@ -341,6 +341,28 @@ static struct vconsole_domain *find_guest(struct vconsole_window *win) return dom; } +static bool is_installed(const char *name) +{ + char *path = strdup(getenv("PATH")); + char *elem, *binary, *ptr; + bool retval = false; + int rc; + + for (elem = strtok_r(path, ":", &ptr); + elem != NULL; + elem = strtok_r(NULL, ":", &ptr)) { + binary = g_strdup_printf("%s/%s", elem, name); + rc = access(binary, X_OK); + g_free(binary); + if (rc == 0) { + retval = true; + break; + } + } + free(path); + return retval; +} + static void prepare_exec(void) { int i; @@ -386,11 +408,16 @@ static void run_virsh_edit(struct vconsole_domain *dom) { char *argv[32]; int argc = 0; + char *app = "xterm"; char *uri; uri = virConnectGetURI(dom->conn->ptr); - argv[argc++] = "xterm"; + if (is_installed("gterm")) { + app = "gterm"; + } + + argv[argc++] = app; argv[argc++] = "-e"; argv[argc++] = "virsh"; argv[argc++] = "-c"; @@ -407,7 +434,7 @@ static void run_virsh_edit(struct vconsole_domain *dom) } else { /* child */ prepare_exec(); - execvp("xterm", argv); + execvp(app, argv); perror("execvp"); exit(1); } -- cgit