From b64347d279e05cd2b1f960c22ec73f8529443ded Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Sat, 23 Jul 2022 22:00:53 +0200 Subject: [PATCH] gio: add support for terminal with no option Introduce support for terminals executing commands without an option, i.e., the command is passed directly as argument to the terminal emulator. This is needed for xdg-terminal-exec. --- gio/gdesktopappinfo.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 94e1f7fd9..eb833b110 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -2629,7 +2629,7 @@ prepend_terminal_to_vector (int *argc, char **real_argv; size_t real_argc; size_t i; - int term_argc = 2; + size_t term_argc; char *found_terminal; char **the_argv; const char *term_arg; @@ -2681,14 +2681,21 @@ prepend_terminal_to_vector (int *argc, return FALSE; } + /* check if the terminal require an option */ + term_argc = term_arg ? 2 : 1; + real_argc = term_argc + *argc; real_argv = g_new (char *, real_argc + 1); - real_argv[0] = found_terminal; - real_argv[1] = g_strdup (term_arg); + i = 0; + real_argv[i++] = found_terminal; - for (i = term_argc; i < real_argc; i++) - real_argv[i] = the_argv[i - term_argc]; + if (term_arg) + real_argv[i++] = g_strdup (term_arg); + + g_assert (i == term_argc); + for (int j = 0; j < *argc; j++) + real_argv[i++] = the_argv[j]; real_argv[i] = NULL;