From: Peter Krempa <[email protected]>

Introduce virCommandArgListAccess which returns 'args' and 'nargs'

Upcoming patches will add code which censores/stabilizes FD numbers in
test outputs. This will be done by rewriting the argument of the command
before comparing it with test output. Add a test-only function to
directly access 'args' and 'nargs' of a virCommand to do this
modification.

This accessor will also be used instead of 'virCommandGetArgList' in
'testCompareXMLToArgvValidateSchema' to avoid needles copy of all
arguments.

Signed-off-by: Peter Krempa <[email protected]>
---
 src/libvirt_private.syms  |  1 +
 src/util/vircommand.c     | 20 ++++++++++++++++++++
 src/util/vircommandpriv.h |  4 ++++
 3 files changed, 25 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7232b7c663..d2fc35505b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2208,6 +2208,7 @@ virCommandAddEnvPassCommon;
 virCommandAddEnvString;
 virCommandAddEnvXDG;
 virCommandAllowCap;
+virCommandArgListAccess;
 virCommandClearCaps;
 virCommandDaemonize;
 virCommandDoAsyncIO;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 2d13cf629c..00d0b58ee1 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2172,6 +2172,26 @@ virCommandGetArgList(virCommand *cmd,
 }


+/**
+ * virCommandGetArgList:
+ * @cmd: command struct
+ * @args: filled with pointer to list of args of @cmd
+ * @nargs: filled with number of arguments
+ *
+ * For use only in tests.
+ *
+ * Allows access to the arguments, including modification.
+ */
+void
+virCommandArgListAccess(virCommand *cmd,
+                        char ***args,
+                        size_t *nargs)
+{
+    *args = cmd->args;
+    *nargs = cmd->nargs;
+}
+
+
 /*
  * virCommandGetBinaryPath:
  * @cmd: virCommand* containing all information about the program
diff --git a/src/util/vircommandpriv.h b/src/util/vircommandpriv.h
index d579810bb5..ca58269afa 100644
--- a/src/util/vircommandpriv.h
+++ b/src/util/vircommandpriv.h
@@ -51,3 +51,7 @@ void virCommandSetDryRun(virCommandDryRunToken *tok,
 void virCommandPeekSendBuffers(virCommand *cmd,
                                virCommandSendBuffer **buffers,
                                int *nbuffers);
+
+void virCommandArgListAccess(virCommand *cmd,
+                             char ***args,
+                             size_t *nargs);
-- 
2.54.0

Reply via email to