mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
qemu: domain: Store passthrough environment variables in a struct
Previously they were stored in two separate arrays. This way it's obvious when referencing the same one. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
8c85d51926
commit
b7b8ea965b
@ -10638,8 +10638,8 @@ qemuBuildCommandLine(virQEMUDriver *driver,
|
||||
for (i = 0; i < qemuxmlns->num_args; i++)
|
||||
virCommandAddArg(cmd, qemuxmlns->args[i]);
|
||||
for (i = 0; i < qemuxmlns->num_env; i++)
|
||||
virCommandAddEnvPair(cmd, qemuxmlns->env_name[i],
|
||||
NULLSTR_EMPTY(qemuxmlns->env_value[i]));
|
||||
virCommandAddEnvPair(cmd, qemuxmlns->env[i].name,
|
||||
NULLSTR_EMPTY(qemuxmlns->env[i].value));
|
||||
}
|
||||
|
||||
if (qemuBuildSeccompSandboxCommandLine(cmd, cfg, qemuCaps) < 0)
|
||||
|
@ -3319,12 +3319,18 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks = {
|
||||
static void
|
||||
qemuDomainXmlNsDefFree(qemuDomainXmlNsDef *def)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!def)
|
||||
return;
|
||||
|
||||
for (i = 0; i < def->num_env; i++) {
|
||||
g_free(def->env[i].name);
|
||||
g_free(def->env[i].value);
|
||||
}
|
||||
g_free(def->env);
|
||||
|
||||
virStringListFreeCount(def->args, def->num_args);
|
||||
virStringListFreeCount(def->env_name, def->num_env);
|
||||
virStringListFreeCount(def->env_value, def->num_env);
|
||||
virStringListFreeCount(def->capsadd, def->ncapsadd);
|
||||
virStringListFreeCount(def->capsdel, def->ncapsdel);
|
||||
|
||||
@ -3372,15 +3378,21 @@ qemuDomainDefNamespaceParseCommandlineArgs(qemuDomainXmlNsDef *nsdef,
|
||||
|
||||
|
||||
static int
|
||||
qemuDomainDefNamespaceParseCommandlineEnvNameValidate(const char *envname)
|
||||
qemuDomainDefNamespaceParseCommandlineEnvValidate(qemuDomainXmlNsEnvTuple *env)
|
||||
{
|
||||
if (!g_ascii_isalpha(envname[0]) && envname[0] != '_') {
|
||||
if (!env->name) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("No qemu environment name specified"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!g_ascii_isalpha(env->name[0]) && env->name[0] != '_') {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Invalid environment name, it must begin with a letter or underscore"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strspn(envname, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_") != strlen(envname)) {
|
||||
if (strspn(env->name, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_") != strlen(env->name)) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Invalid environment name, it must contain only alphanumerics and underscore"));
|
||||
return -1;
|
||||
@ -3404,22 +3416,17 @@ qemuDomainDefNamespaceParseCommandlineEnv(qemuDomainXmlNsDef *nsdef,
|
||||
if (nnodes == 0)
|
||||
return 0;
|
||||
|
||||
nsdef->env_name = g_new0(char *, nnodes);
|
||||
nsdef->env_value = g_new0(char *, nnodes);
|
||||
nsdef->env = g_new0(qemuDomainXmlNsEnvTuple, nnodes);
|
||||
|
||||
for (i = 0; i < nnodes; i++) {
|
||||
if (!(nsdef->env_name[nsdef->num_env] = virXMLPropString(nodes[i], "name"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("No qemu environment name specified"));
|
||||
return -1;
|
||||
}
|
||||
qemuDomainXmlNsEnvTuple *env = nsdef->env + i;
|
||||
|
||||
if (qemuDomainDefNamespaceParseCommandlineEnvNameValidate(nsdef->env_name[nsdef->num_env]) < 0)
|
||||
return -1;
|
||||
|
||||
nsdef->env_value[nsdef->num_env] = virXMLPropString(nodes[i], "value");
|
||||
/* a NULL value for command is allowed, since it might be empty */
|
||||
env->name = virXMLPropString(nodes[i], "name");
|
||||
env->value = virXMLPropString(nodes[i], "value");
|
||||
nsdef->num_env++;
|
||||
|
||||
if (qemuDomainDefNamespaceParseCommandlineEnvValidate(env) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -3513,9 +3520,8 @@ qemuDomainDefNamespaceFormatXMLCommandline(virBuffer *buf,
|
||||
virBufferEscapeString(buf, "<qemu:arg value='%s'/>\n",
|
||||
cmd->args[i]);
|
||||
for (i = 0; i < cmd->num_env; i++) {
|
||||
virBufferAsprintf(buf, "<qemu:env name='%s'", cmd->env_name[i]);
|
||||
if (cmd->env_value[i])
|
||||
virBufferEscapeString(buf, " value='%s'", cmd->env_value[i]);
|
||||
virBufferAsprintf(buf, "<qemu:env name='%s'", cmd->env[i].name);
|
||||
virBufferEscapeString(buf, " value='%s'", cmd->env[i].value);
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
}
|
||||
|
||||
|
@ -457,14 +457,19 @@ struct _qemuDomainSaveCookie {
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuDomainSaveCookie, virObjectUnref);
|
||||
|
||||
typedef struct _qemuDomainXmlNsEnvTuple qemuDomainXmlNsEnvTuple;
|
||||
struct _qemuDomainXmlNsEnvTuple {
|
||||
char *name;
|
||||
char *value;
|
||||
};
|
||||
|
||||
typedef struct _qemuDomainXmlNsDef qemuDomainXmlNsDef;
|
||||
struct _qemuDomainXmlNsDef {
|
||||
size_t num_args;
|
||||
char **args;
|
||||
|
||||
unsigned int num_env;
|
||||
char **env_name;
|
||||
char **env_value;
|
||||
qemuDomainXmlNsEnvTuple *env;
|
||||
|
||||
size_t ncapsadd;
|
||||
char **capsadd;
|
||||
|
Loading…
x
Reference in New Issue
Block a user