Some modules/libraries within QEMU could make use of the XDG_ vars when writing their data to the disk. Define the most common XDG variables and point them to the specific driver's libDir, i.e. XDG_CACHE_HOME -> /var/lib/libvirt/<driver>/.cache XDG_DATA_HOME -> /var/lib/libvirt/<driver>/.local/share XDG_CONFIG_HOME -> /var/lib/libvirt/<driver>/.config Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx> --- src/libvirt_private.syms | 1 + src/util/vircommand.c | 21 +++++++++++++++++++++ src/util/vircommand.h | 2 ++ 3 files changed, 24 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d2a240fc7a..92e21d3939 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1628,6 +1628,7 @@ virCommandAddEnvPassAllowSUID; virCommandAddEnvPassBlockSUID; virCommandAddEnvPassCommon; virCommandAddEnvString; +virCommandAddEnvXDG; virCommandAllowCap; virCommandClearCaps; virCommandDaemonize; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 84a65a2f6d..15e2f0ef1e 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1483,6 +1483,27 @@ virCommandAddEnvPassCommon(virCommandPtr cmd) virCommandAddEnvPassBlockSUID(cmd, "TMPDIR", NULL); } + +void +virCommandAddEnvXDG(virCommandPtr cmd, const char *baseDir) +{ + if (!cmd || cmd->has_error) + return; + + if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 3) < 0) { + cmd->has_error = ENOMEM; + return; + } + + virCommandAddEnvFormat(cmd, "XDG_DATA_HOME=%s/%s", + baseDir, ".local/share"); + virCommandAddEnvFormat(cmd, "XDG_CACHE_HOME=%s/%s", + baseDir, ".cache"); + virCommandAddEnvFormat(cmd, "XDG_CONFIG_HOME=%s/%s", + baseDir, ".config"); +} + + /** * virCommandAddArg: * @cmd: the command to modify diff --git a/src/util/vircommand.h b/src/util/vircommand.h index 99849051f8..efdc5dd00d 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -122,6 +122,8 @@ void virCommandAddEnvPassAllowSUID(virCommandPtr cmd, void virCommandAddEnvPassCommon(virCommandPtr cmd); +void virCommandAddEnvXDG(virCommandPtr cmd, const char *baseDir); + void virCommandAddArg(virCommandPtr cmd, const char *val) ATTRIBUTE_NONNULL(2); -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list