summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Herrera <fherrera@onirica.com>2020-08-11 10:31:38 +0100
committerRichard Hughes <richard@hughsie.com>2020-08-11 12:16:00 +0100
commit85d5dd0f4993d8390b607c8e104aa3feef3c2610 (patch)
tree1f1ecac0984ba189eaf62ff18f3d47dea503da92
parentcb00a43ee4672f6db9217b9ee7c6cbf65cef2ed9 (diff)
command-not-found: fix handling arguments with spaces
Instead of joining the orignal arguments with spaces and executing with g_spawn_command_line_sync use g_spawn_sync with a new argv[] built from exec + arguments so we respect the original command line arguments
-rw-r--r--contrib/command-not-found/pk-command-not-found.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/contrib/command-not-found/pk-command-not-found.c b/contrib/command-not-found/pk-command-not-found.c
index edb2e8c47..8bedb081c 100644
--- a/contrib/command-not-found/pk-command-not-found.c
+++ b/contrib/command-not-found/pk-command-not-found.c
@@ -623,21 +623,24 @@ out:
}
static gint
-pk_cnf_spawn_command (const gchar *exec, gchar **arguments)
+pk_cnf_spawn_command (const gchar *exec, gchar **arguments, guint arguments_count)
{
+ g_autofree gchar **argv = NULL;
gint exit_status = EXIT_FAILURE;
g_autoptr(GError) error = NULL;
- g_autofree gchar *args = NULL;
- g_autofree gchar *cmd = NULL;
/* ensure program starts on a fresh line */
g_print ("\n");
- args = g_strjoinv (" ", arguments);
- cmd = g_strjoin (" ", exec, args, NULL);
- if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) {
+ argv = g_new0 (gchar *, arguments_count + 2);
+ argv[0] = (gchar*) exec;
+ for (guint i = 0; i <= arguments_count; i++) {
+ argv[1+i] = arguments[i];
+ }
+ if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
+ NULL, NULL, &exit_status, &error)) {
/* TRANSLATORS: we failed to launch the executable, the error follows */
- g_printerr ("%s '%s': %s\n", _("Failed to launch:"), cmd, error->message);
+ g_printerr ("%s '%s': %s\n", _("Failed to launch:"), exec, error->message);
}
return exit_status;
}
@@ -802,7 +805,7 @@ main (int argc, char *argv[])
/* run */
if (config->single_match == PK_CNF_POLICY_RUN) {
- retval = pk_cnf_spawn_command (possible, &argv[2]);
+ retval = pk_cnf_spawn_command (possible, &argv[2], argc - 2);
goto out;
}
@@ -812,7 +815,7 @@ main (int argc, char *argv[])
text = g_strdup_printf ("%s %s", _("Run similar command:"), possible);
ret = pk_console_get_prompt (text, TRUE);
if (ret)
- retval = pk_cnf_spawn_command (possible, &argv[2]);
+ retval = pk_cnf_spawn_command (possible, &argv[2], argc - 2);
g_free (text);
}
goto out;
@@ -842,7 +845,7 @@ main (int argc, char *argv[])
/* run command */
possible = g_ptr_array_index (array, i);
- retval = pk_cnf_spawn_command (possible, &argv[2]);
+ retval = pk_cnf_spawn_command (possible, &argv[2], argc - 2);
}
goto out;
@@ -870,7 +873,7 @@ main (int argc, char *argv[])
if (ret) {
ret = pk_cnf_install_package_id (package_ids[0]);
if (ret)
- retval = pk_cnf_spawn_command (argv[1], &argv[2]);
+ retval = pk_cnf_spawn_command (argv[1], &argv[2], argc - 2);
}
g_print ("\n");
goto out;
@@ -880,7 +883,7 @@ main (int argc, char *argv[])
if (config->single_install == PK_CNF_POLICY_INSTALL) {
ret = pk_cnf_install_package_id (package_ids[0]);
if (ret)
- retval = pk_cnf_spawn_command (argv[1], &argv[2]);
+ retval = pk_cnf_spawn_command (argv[1], &argv[2], argc - 2);
}
g_strfreev (parts);
goto out;
@@ -915,7 +918,7 @@ main (int argc, char *argv[])
/* run command */
ret = pk_cnf_install_package_id (package_ids[i - 1]);
if (ret)
- retval = pk_cnf_spawn_command (argv[1], &argv[2]);
+ retval = pk_cnf_spawn_command (argv[1], &argv[2], argc - 2);
}
goto out;
}