Inherit flatpak-run environment from parent instance when spawning#5510
Inherit flatpak-run environment from parent instance when spawning#5510smcv merged 7 commits intoflatpak:mainfrom
Conversation
3af927d to
8390a5d
Compare
1e33167 to
3132d7c
Compare
smcv
left a comment
There was a problem hiding this comment.
I have some comments on the implementation, but this looks like a really good direction to be going in. Thank you for working on this!
|
I want to test this with Steam/pressure-vessel before landing it, but it seems "the same shape" as what I would have implemented myself if I had time, so I expect it to work fine with Steam/pressure-vessel. |
3132d7c to
c8e6f44
Compare
|
I handled some of the smaller comments. I'll handle the rest in the coming days. |
c8e6f44 to
3af514a
Compare
|
I pushed another set of changes to address a few of the review comments. I hope to find time to handle the rest tomorrow. |
3f8de3e to
c824771
Compare
|
I pushed another set of changes to handle a few more review comments. The remaining threads are all waiting for a reply. With this last set of changes, I think the PR is ready for a second round of review. |
b874b0f to
cf2a00c
Compare
|
@smcv, thanks for the thorough review! All review comments have been handled. |
cf2a00c to
241399c
Compare
This allows extending the instance ID allocation logic with less impact on readability. No change in behavior.
Unlike the instance directory, whose directory structure is considered public API and is mounted in the sandbox, the private instance directory is meant to hold private data or metadata about an instance for use by internal components. The private instance directory is not meant to be shared with any external component, and provides no guarantees about its structure or contents. While the public instance directory is named "<instance-id>", the private instance directory is named "<instance-id>-private". Both the public and private instance directories share the same parent directory. The private instance directory relies on the same lock file as the public instance directory, and both are garbage-collected together.
Save the environment in which flatpak-run was executed in the private instance directory. The environment is saved in "env -0" format.
This function can be used to parse environment variable blocks in "env -0" format from a buffer. It performs a few format checks during its parsing and returns an error if an issue is found. When successful, it returns a string array containing each individual environment variable parsed from the buffer, in the same format as the return value of g_get_environ(). The implementation of this function is based on flatpak_context_parse_env_block().
No change in behavior, except minor wording of the error message.
This private function returns the environment in which flatpak-run was executed for a given FlatpakInstance.
Instead of inheriting the portal's environment when spawning a subsandbox using flatpak-run, inherit the environment in which flatpak-run was originally executed for the parent instance. This means that environment variables that affect the sandbox setup of the parent instance now also propagate to the setup of subsandboxes, including "FLATPAK_GL_DRIVERS". Closes: flatpak#5278
241399c to
da02d99
Compare
|
@smcv, is anything else needed from me here? Unfortunately I won't be able to make code changes for a while, so hopefully the code is acceptable in its current form. |
smcv
left a comment
There was a problem hiding this comment.
I need to do some "live" testing on this with the Steam Linux Runtime, but it seems right. Thanks!
This PR propagates the environment in which the original
flatpak runcommand was executed to theflatpak runcommand that spawns subsandboxes.This implements the idea discussed in #5278.
Before
FLATPAK_GL_DRIVERSwhich is used to select a GL runtime extension to mount in the sandbox is not considered when setting up subsandboxes, resulting in thedefaultGL extension being mounted in the subsandbox unexpectedly:After
FLATPAK_GL_DRIVERSwhich is used to select a GL runtime extension to mount in the sandbox is now properly considered when setting up subsandboxes, resulting in themesa-gitGL extension being mounted in the subsandbox as expected:CC: @smcv
instance: Extract lock creation logic and reverse checks
This allows extending the instance ID allocation logic with less
impact on readability.
No change in behavior.
instance: Create private instance directory
Unlike the instance directory, whose directory structure is
considered public API and is mounted in the sandbox, the private
instance directory is meant to hold private data or metadata about
an instance for use by internal components.
The private instance directory is not meant to be shared with any
external component, and provides no guarantees about its structure
or contents.
While the public instance directory is named "<instance-id>", the
private instance directory is named "<instance-id>-private". Both the
public and private instance directories share the same parent
directory.
The private instance directory relies on the same lock file as the
public instance directory, and both are garbage-collected together.
run: Save flatpak-run environment
Save the environment in which flatpak-run was executed in the private
instance directory.
The environment is saved in "env -0" format.
utils: Add flatpak_parse_env_block()
This function can be used to parse environment variable blocks in
"env -0" format from a buffer. It performs a few format checks during
its parsing and returns an error if an issue is found.
When successful, it returns a string array containing each individual
environment variable parsed from the buffer, in the same format as
the return value of g_get_environ().
The implementation of this function is based on
flatpak_context_parse_env_block().
context: Use flatpak_parse_env_block()
No change in behavior, except minor wording of the error message.
instance: Add flatpak_instance_get_run_environ()
This private function returns the environment in which flatpak-run
was executed for a given FlatpakInstance.
portal: Inherit flatpak-run environment from parent when spawning
Instead of inheriting the portal's environment when spawning a
subsandbox using flatpak-run, inherit the environment in which
flatpak-run was originally executed for the parent instance.
This means that environment variables that affect the sandbox setup
of the parent instance now also propagate to the setup of
subsandboxes, including "FLATPAK_GL_DRIVERS".
Closes: [Bug]: Subsandbox should base its environment on the environment of the original
flatpak run#5278