[libvirt] Add upstream patches: don't duplicate environment variables (RHBZ#859596).
Richard W.M. Jones
rjones at fedoraproject.org
Mon Sep 24 20:24:46 UTC 2012
commit 404e58cb18217cb1bc20bfc3c17c120640e4245b
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Mon Sep 24 20:58:47 2012 +0100
Add upstream patches: don't duplicate environment variables (RHBZ#859596).
...e-environ-adding-code-to-common-function-.patch | 94 ++++++++++++++++++++
...nge-virCommandAddEnv-so-it-replaces-exist.patch | 45 +++++++++
libvirt.spec | 12 ++-
3 files changed, 149 insertions(+), 2 deletions(-)
---
diff --git a/0001-command-Move-environ-adding-code-to-common-function-.patch b/0001-command-Move-environ-adding-code-to-common-function-.patch
new file mode 100644
index 0000000..7c93580
--- /dev/null
+++ b/0001-command-Move-environ-adding-code-to-common-function-.patch
@@ -0,0 +1,94 @@
+From f644361b1eeb78fd59be4cd7ec85567bbf300506 Mon Sep 17 00:00:00 2001
+From: "Richard W.M. Jones" <rjones at redhat.com>
+Date: Mon, 24 Sep 2012 17:30:18 +0100
+Subject: [PATCH 1/2] command: Move environ-adding code to common function
+ virCommandAddEnv.
+
+This is just code motion. The semantics of the code should be
+identical after this change.
+---
+ src/util/command.c | 40 ++++++++++++++++++++--------------------
+ 1 file changed, 20 insertions(+), 20 deletions(-)
+
+diff --git a/src/util/command.c b/src/util/command.c
+index 5d6e17b..f7d92dd 100644
+--- a/src/util/command.c
++++ b/src/util/command.c
+@@ -984,6 +984,22 @@ virCommandNonblockingFDs(virCommandPtr cmd)
+ cmd->flags |= VIR_EXEC_NONBLOCK;
+ }
+
++/* Add an environment variable to the cmd->env list. 'env' is a
++ * string like "name=value".
++ */
++static inline void
++virCommandAddEnv(virCommandPtr cmd, char *env)
++{
++ /* Arg plus trailing NULL. */
++ if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
++ VIR_FREE(env);
++ cmd->has_error = ENOMEM;
++ return;
++ }
++
++ cmd->env[cmd->nenv++] = env;
++}
++
+ /**
+ * virCommandAddEnvFormat:
+ * @cmd: the command to modify
+@@ -1009,14 +1025,7 @@ virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...)
+ }
+ va_end(list);
+
+- /* Arg plus trailing NULL. */
+- if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
+- VIR_FREE(env);
+- cmd->has_error = ENOMEM;
+- return;
+- }
+-
+- cmd->env[cmd->nenv++] = env;
++ virCommandAddEnv(cmd, env);
+ }
+
+ /**
+@@ -1056,14 +1065,7 @@ virCommandAddEnvString(virCommandPtr cmd, const char *str)
+ return;
+ }
+
+- /* env plus trailing NULL */
+- if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
+- VIR_FREE(env);
+- cmd->has_error = ENOMEM;
+- return;
+- }
+-
+- cmd->env[cmd->nenv++] = env;
++ virCommandAddEnv(cmd, env);
+ }
+
+
+@@ -1084,9 +1086,7 @@ virCommandAddEnvBuffer(virCommandPtr cmd, virBufferPtr buf)
+ return;
+ }
+
+- /* env plus trailing NULL. */
+- if (virBufferError(buf) ||
+- VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
++ if (virBufferError(buf)) {
+ cmd->has_error = ENOMEM;
+ virBufferFreeAndReset(buf);
+ return;
+@@ -1096,7 +1096,7 @@ virCommandAddEnvBuffer(virCommandPtr cmd, virBufferPtr buf)
+ return;
+ }
+
+- cmd->env[cmd->nenv++] = virBufferContentAndReset(buf);
++ virCommandAddEnv(cmd, virBufferContentAndReset(buf));
+ }
+
+
+--
+1.7.10.4
+
diff --git a/0002-command-Change-virCommandAddEnv-so-it-replaces-exist.patch b/0002-command-Change-virCommandAddEnv-so-it-replaces-exist.patch
new file mode 100644
index 0000000..00f0cc3
--- /dev/null
+++ b/0002-command-Change-virCommandAddEnv-so-it-replaces-exist.patch
@@ -0,0 +1,45 @@
+From 2b32735af480055e27400068d27364d521071117 Mon Sep 17 00:00:00 2001
+From: "Richard W.M. Jones" <rjones at redhat.com>
+Date: Mon, 24 Sep 2012 17:35:47 +0100
+Subject: [PATCH 2/2] command: Change virCommandAddEnv so it replaces existing
+ environment variables.
+
+---
+ src/util/command.c | 17 ++++++++++++++++-
+ 1 file changed, 16 insertions(+), 1 deletion(-)
+
+diff --git a/src/util/command.c b/src/util/command.c
+index f7d92dd..1adf7b9 100644
+--- a/src/util/command.c
++++ b/src/util/command.c
+@@ -985,11 +985,26 @@ virCommandNonblockingFDs(virCommandPtr cmd)
+ }
+
+ /* 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);
+--
+1.7.10.4
+
diff --git a/libvirt.spec b/libvirt.spec
index b5dffda..b47ec0e 100644
--- a/libvirt.spec
+++ b/libvirt.spec
@@ -316,7 +316,7 @@
Summary: Library providing a simple virtualization API
Name: libvirt
Version: 0.10.2
-Release: 2%{?dist}%{?extra_release}
+Release: 3%{?dist}%{?extra_release}
License: LGPLv2+
Group: Development/Libraries
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
@@ -331,6 +331,11 @@ Source: http://libvirt.org/sources/%{?mainturl}libvirt-%{version}.tar.gz
# NB: This patch is Fedora-specific and not upstream.
Patch1: 0001-Use-qemu-system-i386-as-binary-instead-of-qemu.patch
+# Don't duplicate environment variables
+# (RHBZ#859596, upstream after 0.10.2).
+Patch2: 0001-command-Move-environ-adding-code-to-common-function-.patch
+Patch3: 0002-command-Change-virCommandAddEnv-so-it-replaces-exist.patch
+
%if %{with_libvirtd}
Requires: libvirt-daemon = %{version}-%{release}
%if %{with_network}
@@ -1041,6 +1046,8 @@ of recent versions of Linux (and other OSes).
%prep
%setup -q
%patch1 -p1
+%patch2 -p1
+%patch3 -p1
%build
%if ! %{with_xen}
@@ -1884,9 +1891,10 @@ rm -f $RPM_BUILD_ROOT%{_sysconfdir}/sysctl.d/libvirtd
%endif
%changelog
-* Mon Sep 24 2012 Daniel Veillard <veillard at redhat.com> - 0.10.2-2
+* Mon Sep 24 2012 Richard W.M. Jones <rjones at redhat.com> - 0.10.2-3
- Re-add 0001-Use-qemu-system-i386-as-binary-instead-of-qemu.patch
NB: This patch is Fedora-specific and not upstream.
+- Add upstream patches: don't duplicate environment variables (RHBZ#859596).
* Mon Sep 24 2012 Daniel Veillard <veillard at redhat.com> - 0.10.2-1
- Upstream release 0.10.2
More information about the scm-commits
mailing list