render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
404e58
From f644361b1eeb78fd59be4cd7ec85567bbf300506 Mon Sep 17 00:00:00 2001
404e58
From: "Richard W.M. Jones" <rjones@redhat.com>
404e58
Date: Mon, 24 Sep 2012 17:30:18 +0100
404e58
Subject: [PATCH 1/2] command: Move environ-adding code to common function
404e58
 virCommandAddEnv.
404e58
404e58
This is just code motion.  The semantics of the code should be
404e58
identical after this change.
404e58
---
404e58
 src/util/command.c |   40 ++++++++++++++++++++--------------------
404e58
 1 file changed, 20 insertions(+), 20 deletions(-)
404e58
404e58
diff --git a/src/util/command.c b/src/util/command.c
404e58
index 5d6e17b..f7d92dd 100644
404e58
--- a/src/util/command.c
404e58
+++ b/src/util/command.c
404e58
@@ -984,6 +984,22 @@ virCommandNonblockingFDs(virCommandPtr cmd)
404e58
     cmd->flags |= VIR_EXEC_NONBLOCK;
404e58
 }
404e58
 
404e58
+/* Add an environment variable to the cmd->env list.  'env' is a
404e58
+ * string like "name=value".
404e58
+ */
404e58
+static inline void
404e58
+virCommandAddEnv(virCommandPtr cmd, char *env)
404e58
+{
404e58
+    /* Arg plus trailing NULL. */
404e58
+    if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
404e58
+        VIR_FREE(env);
404e58
+        cmd->has_error = ENOMEM;
404e58
+        return;
404e58
+    }
404e58
+
404e58
+    cmd->env[cmd->nenv++] = env;
404e58
+}
404e58
+
404e58
 /**
404e58
  * virCommandAddEnvFormat:
404e58
  * @cmd: the command to modify
404e58
@@ -1009,14 +1025,7 @@ virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...)
404e58
     }
404e58
     va_end(list);
404e58
 
404e58
-    /* Arg plus trailing NULL. */
404e58
-    if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
404e58
-        VIR_FREE(env);
404e58
-        cmd->has_error = ENOMEM;
404e58
-        return;
404e58
-    }
404e58
-
404e58
-    cmd->env[cmd->nenv++] = env;
404e58
+    virCommandAddEnv(cmd, env);
404e58
 }
404e58
 
404e58
 /**
404e58
@@ -1056,14 +1065,7 @@ virCommandAddEnvString(virCommandPtr cmd, const char *str)
404e58
         return;
404e58
     }
404e58
 
404e58
-    /* env plus trailing NULL */
404e58
-    if (VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
404e58
-        VIR_FREE(env);
404e58
-        cmd->has_error = ENOMEM;
404e58
-        return;
404e58
-    }
404e58
-
404e58
-    cmd->env[cmd->nenv++] = env;
404e58
+    virCommandAddEnv(cmd, env);
404e58
 }
404e58
 
404e58
 
404e58
@@ -1084,9 +1086,7 @@ virCommandAddEnvBuffer(virCommandPtr cmd, virBufferPtr buf)
404e58
         return;
404e58
     }
404e58
 
404e58
-    /* env plus trailing NULL. */
404e58
-    if (virBufferError(buf) ||
404e58
-        VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 1 + 1) < 0) {
404e58
+    if (virBufferError(buf)) {
404e58
         cmd->has_error = ENOMEM;
404e58
         virBufferFreeAndReset(buf);
404e58
         return;
404e58
@@ -1096,7 +1096,7 @@ virCommandAddEnvBuffer(virCommandPtr cmd, virBufferPtr buf)
404e58
         return;
404e58
     }
404e58
 
404e58
-    cmd->env[cmd->nenv++] = virBufferContentAndReset(buf);
404e58
+    virCommandAddEnv(cmd, virBufferContentAndReset(buf));
404e58
 }
404e58
 
404e58
 
404e58
-- 
404e58
1.7.10.4
404e58