95 lines
2.5 KiB
Diff
95 lines
2.5 KiB
Diff
From f644361b1eeb78fd59be4cd7ec85567bbf300506 Mon Sep 17 00:00:00 2001
|
|
From: "Richard W.M. Jones" <rjones@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
|
|
|