Skip to contentSkip to conversation

linux-user: pass environment arguments in execve

PATCH Riku Voipio 1 participant 1 message Jun 20, 2016

lore
Share & tools
lore
#0 lore raw

20.6.2016 22.51 Joel Holdsworth <[email protected]> kirjoitti:

Quoted 6 lines · Laurent Vivier
Quoted 4 lines

Le 14/06/2016 `a 21:26, Joel Holdsworth a ecrit :

Quoted 2 lines

Previously, when emulating execve(2), qemu would execute a child instance of the emulator with the environment variables provided

by

Quoted 10 lines
Quoted 4 lines
Quoted 3 lines

the parent process. This caused problems with qemu if any of the variables affected the child emulator's behaviour e.g. LD_LIBRARY_PATH.

The best way to avoid that is to use a statically linked qemu.

Stepping back a bit; the problem I'm trying to solve is this...

There are some processes that invoke a helper process to do some work for them e.g. gstreamer's gst-plugin-scanner. Previously qemu would attempt to execute the helper executable as if it were

machine-native,

Quoted 1 line

which won't work. These patches modify qemu so that it will

(optionally)

Quoted 3 lines

run the child process inside a child instance of qemu.

My experience as a user was that it took a couple of hours of

searching

Quoted 2 lines

through strace logs to figure out what the issue was. gstreamer would just fail with a generic error about the helper. These patches are

meant

Quoted 3 lines

to make qemu do the right thing.

Saying to the user that they should make a static linked build of

qemu

Quoted 3 lines

isn't very practical. Having a command line argument is a much easier solution for the user, that doesn't force them not to used shared-library builds. The distros aren't going to go for that.

Actually at least Debian and Ubuntu already ship static qemu-user binaries. Using static qemu-user and binfmt_misc is the standard way people use qemu-user.

Quoted 15 lines

Moreover, LD_LIBRARY_PATH is just one example. LD_PRELOAD is another. Timezone and locale environment variables are also an issue.

In an ideal world, it wouldn't even be necessary to add an argument - qemu would just do the right thing automatically. Though I'm not sure how that could be done correctly, so a command line option is a good compromise for a starting point.

Quoted 5 lines
Quoted 5 lines

This patch solves this issue by passing the environment variables with '-E' arguments to the child qemu instance. The call to execve(2) is replaced by a call to execv(2) so that the parent emulator's environment variable state is propagated into the

child.

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

Any variables from the host environment that are not in the in the execve() call are removed with a '-U' argument.

Run ./scripts/checkpatch.pl on your patch...

and add your Signed-off-by here.

Sure ok.

Quoted 1 line

The environment is already managed in linux-user/main.c:main(), I

don't

Quoted 1 line
Quoted 1 line

understand why the qemu_execve() special case should differ from

the

Quoted 2 lines
Quoted 1 line

general case.

Maybe I've missed something, but the problem I'm trying to solve here

is

Quoted 1 line

the issue of correctly propagating the guest environment variables

into

Quoted 3 lines

the child process.

The parent guest process (running inside qemu-user) constructs a set

of

Quoted 1 line

environment variables and passes them to execve. However, if the

parent

Quoted 2 lines

qemu-user decides to run a child instance of qemu-user it should run with the same environment variables as the parent, but with

environment

Quoted 1 line

variables the parent-guest passed through the arguments for the

child-guest.

Quoted 2 lines

If gstreamer decides to run gst-plugin-scanner with a certain

environ,

Quoted 3 lines

that is for the child qemu guest, not the child qemu instance itself.