Skip to content
Snippets Groups Projects
Commit 4c13f72a authored by Simon McVittie's avatar Simon McVittie
Browse files

launch: Add the ability to unset environment variables everywhere


If we're doing the equivalent of `flatpak-spawn` or
`flatpak-spawn --host`, we can emulate the unset-env option by running
`env -u`.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 634aae10
No related branches found
No related tags found
1 merge request!194Flatpak-related fixes
This commit is part of merge request !194. Comments created here will be created in the context of that merge request.
...@@ -60,9 +60,7 @@ as a subprocess of **pressure-vessel-launcher**. ...@@ -60,9 +60,7 @@ as a subprocess of **pressure-vessel-launcher**.
owned by the **flatpak-session-helper** per-user service, and the owned by the **flatpak-session-helper** per-user service, and the
*COMMAND* is launched on the host system, similar to the *COMMAND* is launched on the host system, similar to the
**--host** option of **flatpak-spawn**(1). **--host** option of **flatpak-spawn**(1).
The **--terminate** option is not allowed in this mode, and most The **--terminate** option is not allowed in this mode.
options that would unset environment variables, such as **--unset-env**,
are ignored with a warning (but **--clear-env** is still possible).
As another special case, if the *NAME* is As another special case, if the *NAME* is
**org.freedesktop.portal.Flatpak**, then it is assumed to be **org.freedesktop.portal.Flatpak**, then it is assumed to be
...@@ -72,8 +70,7 @@ as a subprocess of **pressure-vessel-launcher**. ...@@ -72,8 +70,7 @@ as a subprocess of **pressure-vessel-launcher**.
Options that alter how the sub-sandbox is created, such as Options that alter how the sub-sandbox is created, such as
**--sandbox-flag**, are not currently supported. **--sandbox-flag**, are not currently supported.
As with **org.freedesktop.Flatpak**, the As with **org.freedesktop.Flatpak**, the
**--terminate** option is not allowed in this mode, and most **--terminate** option is not allowed in this mode.
options that would unset environment variables are ignored with a warning.
**--clear-env** **--clear-env**
: The *COMMAND* runs in an empty environment, apart from any environment : The *COMMAND* runs in an empty environment, apart from any environment
......
...@@ -534,6 +534,7 @@ main (int argc, ...@@ -534,6 +534,7 @@ main (int argc,
g_auto(GStrv) original_environ = NULL; g_auto(GStrv) original_environ = NULL;
g_autoptr(GMainLoop) loop = NULL; g_autoptr(GMainLoop) loop = NULL;
g_autoptr(GOptionContext) context = NULL; g_autoptr(GOptionContext) context = NULL;
g_autoptr(GPtrArray) replacement_command_and_args = NULL;
g_autoptr(GError) local_error = NULL; g_autoptr(GError) local_error = NULL;
GError **error = &local_error; GError **error = &local_error;
char **command_and_args; char **command_and_args;
...@@ -881,9 +882,29 @@ main (int argc, ...@@ -881,9 +882,29 @@ main (int argc,
} }
else else
{ {
replacement_command_and_args = g_ptr_array_new_with_free_func (g_free);
g_ptr_array_add (replacement_command_and_args, g_strdup ("/usr/bin/env"));
while (g_hash_table_iter_next (&iter, &key, NULL)) while (g_hash_table_iter_next (&iter, &key, NULL))
g_warning ("Cannot unset %s when using Flatpak services", {
(const char *) key); g_ptr_array_add (replacement_command_and_args, g_strdup ("-u"));
g_ptr_array_add (replacement_command_and_args, g_strdup (key));
}
if (strchr (command_and_args[0], '=') != NULL)
{
g_ptr_array_add (replacement_command_and_args, g_strdup ("/bin/sh"));
g_ptr_array_add (replacement_command_and_args, g_strdup ("-euc"));
g_ptr_array_add (replacement_command_and_args, g_strdup ("exec \"$@\""));
g_ptr_array_add (replacement_command_and_args, g_strdup ("sh")); /* argv[0] */
}
for (i = 0; command_and_args[i] != NULL; i++)
g_ptr_array_add (replacement_command_and_args, g_strdup (command_and_args[i]));
g_ptr_array_add (replacement_command_and_args, NULL);
command_and_args = (char **) replacement_command_and_args->pdata;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment