[console] application: Pass --command argument to shell
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [console] application: Pass --command argument to shell
- Date: Mon, 20 Jun 2022 13:45:19 +0000 (UTC)
commit d5ccb5715ebdf3075f484a45ca8875215ae717fb
Author: Simon McVittie <smcv debian org>
Date: Mon Jun 20 11:16:12 2022 +0100
application: Pass --command argument to shell
Using the real shell, rather than splitting with g_shell_parse_argv(),
means the command can contain shell metacharacters and syntactic
constructs like
kgx --command="ls *.txt"
or
kgx --command="if [ -e foo ]; then bar; fi"
Signed-off-by: Simon McVittie <smcv debian org>
src/kgx-application.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
---
diff --git a/src/kgx-application.c b/src/kgx-application.c
index e3e9ddc..30af450 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -503,20 +503,17 @@ kgx_application_command_line (GApplication *app,
}
if (command != NULL) {
- g_autoptr (GError) error = NULL;
-
if (argv != NULL && argv[0] != NULL) {
g_warning (_("Cannot use both --command and positional parameters"));
return EXIT_FAILURE;
}
g_clear_pointer (&argv, g_strfreev);
-
- if (!g_shell_parse_argv (command, NULL, &argv, &error)) {
- g_warning ("Failed to parse ā%sā as a command: %s", command, error->message);
- g_clear_error (&error);
- g_clear_pointer (&argv, g_strfreev);
- }
+ argv = g_new0 (char *, 4);
+ argv[0] = g_strdup ("/bin/sh");
+ argv[1] = g_strdup ("-c");
+ argv[2] = g_strdup (command);
+ argv[3] = NULL;
}
if (g_variant_dict_lookup (options, "tab", "b", &tab) && tab) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]