ae1e5e873b
f644361b-virCommand-env.patch 2b32735a-virCommand-env.patch OBS-URL: https://build.opensuse.org/package/show/Virtualization/libvirt?expand=0&rev=233
39 lines
1.3 KiB
Diff
39 lines
1.3 KiB
Diff
commit 2b32735af480055e27400068d27364d521071117
|
|
Author: Richard W.M. Jones <rjones@redhat.com>
|
|
Date: Mon Sep 24 17:35:47 2012 +0100
|
|
|
|
command: Change virCommandAddEnv so it replaces existing environment variables.
|
|
|
|
Index: libvirt-0.10.2/src/util/command.c
|
|
===================================================================
|
|
--- libvirt-0.10.2.orig/src/util/command.c
|
|
+++ libvirt-0.10.2/src/util/command.c
|
|
@@ -985,11 +985,26 @@ virCommandNonblockingFDs(virCommandPtr c
|
|
}
|
|
|
|
/* 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
|
|
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. */
|
|
if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
|
|
VIR_FREE(env);
|