提交 2b32735a 编写于 作者: R Richard W.M. Jones

command: Change virCommandAddEnv so it replaces existing environment variables.

上级 f644361b
...@@ -985,11 +985,26 @@ virCommandNonblockingFDs(virCommandPtr cmd) ...@@ -985,11 +985,26 @@ virCommandNonblockingFDs(virCommandPtr cmd)
} }
/* Add an environment variable to the cmd->env list. 'env' is a /* Add an environment variable to the cmd->env list. 'env' is a
* string like "name=value". * string like "name=value". If the named environment variable is
* already set, then it is replaced in the list.
*/ */
static inline void static inline void
virCommandAddEnv(virCommandPtr cmd, char *env) virCommandAddEnv(virCommandPtr cmd, char *env)
{ {
size_t namelen;
size_t i;
/* Search for the name in the existing environment. */
namelen = strcspn(env, "=");
for (i = 0; i < cmd->nenv; ++i) {
/* + 1 because we want to match the '=' character too. */
if (STREQLEN(cmd->env[i], env, namelen + 1)) {
VIR_FREE(cmd->env[i]);
cmd->env[i] = env;
return;
}
}
/* Arg plus trailing NULL. */ /* Arg plus trailing NULL. */
if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) { if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
VIR_FREE(env); VIR_FREE(env);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册