From 8b3af5ffbd9e615a8ff423fbf415ae4fd21f896e Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Wed, 16 Dec 2020 12:03:23 +0000
Subject: [PATCH] pressure-vessel: Stop worrying about whether argv[1][0] is
 "-"

The reason we originally did this is that older versions of bwrap
didn't support the GNU-style "--" argument separator, used to
disambiguate between non-option arguments and strangely-named
executables that happened to start with a minus.

However, we now wrap our user-controlled "payload" command with pressure-vessel-adverb(1) in
all cases, which means we don't need this. bwrap's first non-option
argument is the absolute path to pressure-vessel-adverb, which
definitely does not start with "-" and so cannot be confused with an
option; and all of our own commands, notably pressure-vessel-adverb,
use GOptionContext and therefore support the "--" option-separator
correctly.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 pressure-vessel/wrap.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/pressure-vessel/wrap.c b/pressure-vessel/wrap.c
index 497a3f889..e4d91b678 100644
--- a/pressure-vessel/wrap.c
+++ b/pressure-vessel/wrap.c
@@ -2308,26 +2308,12 @@ main (int argc,
     }
   else
     {
-      g_autoptr(FlatpakBwrap) wrapped_command =
-        flatpak_bwrap_new (flatpak_bwrap_empty_env);
-
-      if (argc > 1 && argv[1][0] == '-')
-        {
-          /* Make sure wrapped_command is something we can validly pass to env(1) */
-          if (strchr (argv[1], '=') != NULL)
-            flatpak_bwrap_add_args (wrapped_command,
-                                    "sh", "-euc", "exec \"$@\"", "sh",
-                                    NULL);
-
-          /* Make sure bwrap will interpret wrapped_command as the end of its
-           * options */
-          flatpak_bwrap_add_arg (wrapped_command, "env");
-        }
-
+      /* In non-"--launcher" mode, arguments after the "--" separator
+       * are the command to execute, passed to the adverb after "--".
+       * Because we always use the adverb, we don't need to worry about
+       * whether argv[1] starts with "-". */
       g_debug ("Setting arguments for wrapped command");
-      flatpak_bwrap_append_argsv (wrapped_command, &argv[1], argc - 1);
-
-      flatpak_bwrap_append_bwrap (bwrap, wrapped_command);
+      flatpak_bwrap_append_argsv (bwrap, &argv[1], argc - 1);
     }
 
   if (is_flatpak_env)
-- 
GitLab