This is a wrapper over virCommandAddEnvPassCommon and virCommandAddEnvXDG. It is defined within the qemu module, since it is meant to enforce isolation of QEMU processes which is not much useful for other processes we spawn, like dnsmasq. Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx> --- src/qemu/qemu_command.c | 25 +++++++++++++++++++++++-- src/qemu/qemu_command.h | 3 +++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2c6d6188e2..85b90be429 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10620,6 +10620,28 @@ qemuBuildVsockCommandLine(virCommandPtr cmd, } +/** + * qemuCommandEnvSetup: + * @cmd: command to modify + * @baseDir: absolute path to a dir which HOME and XDG vars will be based on + * + * Defines the basic set of environment variables for a QEMU process, e.g. + * HOME, PATH, XDG_, etc. To isolate individual QEMU processes, HOME and XDG_ + * variables are derived from @baseDir. Therefore, @baseDir must not be NULL. + */ +void +qemuCommandEnvSetup(virCommandPtr cmd, + const char *baseDir) +{ + if (!baseDir) + return; + + virCommandAddEnvPassCommon(cmd); + + virCommandAddEnvXDG(cmd, baseDir); +} + + /* * Constructs a argv suitable for launching qemu with config defined * for a given virtual machine. @@ -10657,8 +10679,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, cmd = virCommandNew(def->emulator); - virCommandAddEnvPassCommon(cmd); - virCommandAddEnvXDG(cmd, priv->libDir); + qemuCommandEnvSetup(cmd, priv->libDir); if (qemuBuildNameCommandLine(cmd, cfg, def, qemuCaps) < 0) goto error; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 077484094d..07a034504a 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -227,4 +227,7 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); +void +qemuCommandEnvSetup(virCommandPtr cmd, const char *baseDir); + #endif /* LIBVIRT_QEMU_COMMAND_H */ -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list