[PATCH 09/21] virCommand: Introduce virCommandGetArgList

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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 935ef7303b..31813f177f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1841,6 +1841,7 @@ virCommandDaemonize;
 virCommandDoAsyncIO;
 virCommandExec;
 virCommandFree;
+virCommandGetArgList;
 virCommandGetGID;
 virCommandGetUID;
 virCommandHandshakeNotify;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 20f196104f..aae0ddb730 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2132,6 +2132,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 e2be5bcf1c..ff8a785dbe 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -170,6 +170,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.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux