From 548ea1fcfcfbfc40fab04301e780d28ebe4320a4 Mon Sep 17 00:00:00 2001
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 13 May 2020 17:55:21 +0200
Subject: [PATCH 13/18] virCommand: Introduce virCommandGetArgList

The helper returns a list of arguments of a virCommand. This will be
useful in tests where we'll inspect certain already formatted arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/util/vircommand.c    | 23 +++++++++++++++++++++++
 src/util/vircommand.h    |  1 +
 3 files changed, 25 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 726e7a21f9..861a4892be 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1829,6 +1829,7 @@ virCommandDaemonize;
 virCommandDoAsyncIO;
 virCommandExec;
 virCommandFree;
+virCommandGetArgList;
 virCommandGetGID;
 virCommandGetUID;
 virCommandHandshakeNotify;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index b84fb40948..86e4c5cd39 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2167,6 +2167,29 @@ virCommandToString(virCommandPtr cmd, bool linebreaks)
 }
 
 
+int
+virCommandGetArgList(virCommandPtr cmd,
+                     char ***args,
+                     size_t *nargs)
+{
+    size_t i;
+
+    if (cmd->has_error) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("invalid use of command API"));
+        return -1;
+    }
+
+    *args = g_new0(char *, cmd->nargs);
+    *nargs = cmd->nargs - 1;
+
+    for (i = 1; i < cmd->nargs; i++)
+        (*args)[i - 1] = g_strdup(cmd->args[i]);
+
+    return 0;
+}
+
+
 #ifndef WIN32
 /*
  * Manage input and output to the child process.
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index 4e6cb0ac0d..854bfe6576 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -171,6 +171,7 @@ void virCommandWriteArgLog(virCommandPtr cmd,
                            int logfd);
 
 char *virCommandToString(virCommandPtr cmd, bool linebreaks) G_GNUC_WARN_UNUSED_RESULT;
+int virCommandGetArgList(virCommandPtr cmd, char ***args, size_t *nargs);
 
 int virCommandExec(virCommandPtr cmd, gid_t *groups, int ngroups) G_GNUC_WARN_UNUSED_RESULT;
 
-- 
2.23.0.windows.1

