[libvirt] [PATCH v2 2/3] qemu: command: Enforce setting XDG variables for system QEMU

Erik Skultety posted 3 patches 6 years, 11 months ago
[libvirt] [PATCH v2 2/3] qemu: command: Enforce setting XDG variables for system QEMU
Posted by Erik Skultety 6 years, 11 months ago
For session mode, only XDG_CACHE_HOME is set, because we want to remain
integrating with services in user session, but for system mode, this
would have become reading/writing to '/' which carries the obvious issue
with permissions (also, '/' is the wrong location in 99.9% cases anyway).

Signed-off-by: Erik Skultety <eskultet@redhat.com>
---
 src/qemu/qemu_command.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3a2ec7f26c..23be0d8554 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10658,6 +10658,22 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
 
     virCommandAddEnvPassCommon(cmd);
 
+    /* For system QEMU we want to set both HOME and all the XDG variables to
+     * libDir/qemu otherwise apps QEMU links to might try to access the default
+     * home dir '/' which would always result in a permission issue.
+     *
+     * For session QEMU, we only want to set XDG_CACHE_HOME as cache data
+     * may be purged at any time and that should not affect any app. We
+     * do want VMs to integrate with services in user's session so we're
+     * not re-setting any other env variables
+     */
+    if (!driver->privileged) {
+        virCommandAddEnvFormat(cmd, "XDG_CACHE_HOME=%s/%s",
+                               priv->libDir, ".cache");
+    } else {
+        virCommandAddEnvXDG(cmd, priv->libDir);
+    }
+
     if (qemuBuildNameCommandLine(cmd, cfg, def, qemuCaps) < 0)
         goto error;
 
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 2/3] qemu: command: Enforce setting XDG variables for system QEMU
Posted by Daniel P. Berrangé 6 years, 11 months ago
On Fri, Mar 08, 2019 at 01:00:48PM +0100, Erik Skultety wrote:
> For session mode, only XDG_CACHE_HOME is set, because we want to remain
> integrating with services in user session, but for system mode, this
> would have become reading/writing to '/' which carries the obvious issue
> with permissions (also, '/' is the wrong location in 99.9% cases anyway).
> 
> Signed-off-by: Erik Skultety <eskultet@redhat.com>
> ---
>  src/qemu/qemu_command.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

(with the test cases that have been snipped)


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list