util: command: Introduce virCommandAddEnvXDG helper

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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Erik Skultety 2019-03-04 12:47:08 +01:00
parent 0b7d544c88
commit 2d69af2907
3 changed files with 24 additions and 0 deletions

View File

@ -1635,6 +1635,7 @@ virCommandAddEnvPassAllowSUID;
virCommandAddEnvPassBlockSUID;
virCommandAddEnvPassCommon;
virCommandAddEnvString;
virCommandAddEnvXDG;
virCommandAllowCap;
virCommandClearCaps;
virCommandDaemonize;

View File

@ -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

View File

@ -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);