28f4698
From: John Ferlan <jferlan@redhat.com>
28f4698
Date: Fri, 13 May 2016 12:36:39 -0400
28f4698
Subject: [PATCH] util: Add exitstatus parameter to virCommandRunRegex
28f4698
28f4698
Rather than have virCommandRun just spit out the error, allow callers
28f4698
to decide to pass the exitstatus so the caller can make intelligent
28f4698
decisions based on the error.
28f4698
28f4698
(cherry picked from commit 8b1049473317c09d34b3ce9671d0f9e91dd4f1c0)
28f4698
---
28f4698
 src/storage/storage_backend_fs.c      |  2 +-
28f4698
 src/storage/storage_backend_logical.c | 10 ++++++----
28f4698
 src/util/vircommand.c                 |  9 ++++++---
28f4698
 src/util/vircommand.h                 |  3 ++-
28f4698
 src/util/viriscsi.c                   |  4 ++--
28f4698
 5 files changed, 17 insertions(+), 11 deletions(-)
28f4698
28f4698
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
28f4698
index 692c9ff..93d65aa 100644
28f4698
--- a/src/storage/storage_backend_fs.c
28f4698
+++ b/src/storage/storage_backend_fs.c
28f4698
@@ -261,7 +261,7 @@ virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *state)
28f4698
 
28f4698
     if (virCommandRunRegex(cmd, 1, regexes, vars,
28f4698
                            virStorageBackendFileSystemNetFindPoolSourcesFunc,
28f4698
-                           state, NULL) < 0)
28f4698
+                           state, NULL, NULL) < 0)
28f4698
         goto cleanup;
28f4698
 
28f4698
     ret = 0;
28f4698
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
28f4698
index 90a194e..ca05fe1 100644
28f4698
--- a/src/storage/storage_backend_logical.c
28f4698
+++ b/src/storage/storage_backend_logical.c
28f4698
@@ -398,7 +398,8 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
28f4698
                            vars,
28f4698
                            virStorageBackendLogicalMakeVol,
28f4698
                            &cbdata,
28f4698
-                           "lvs") < 0)
28f4698
+                           "lvs",
28f4698
+                           NULL) < 0)
28f4698
         goto cleanup;
28f4698
 
28f4698
     ret = 0;
28f4698
@@ -511,10 +512,10 @@ virStorageBackendLogicalGetPoolSources(virStoragePoolSourceListPtr sourceList)
28f4698
     cmd = virCommandNewArgList(PVS,
28f4698
                                "--noheadings",
28f4698
                                "-o", "pv_name,vg_name",
28f4698
-                               NULL);
28f4698
+                               NULL, NULL);
28f4698
     if (virCommandRunRegex(cmd, 1, regexes, vars,
28f4698
                            virStorageBackendLogicalFindPoolSourcesFunc,
28f4698
-                           sourceList, "pvs") < 0)
28f4698
+                           sourceList, "pvs", NULL) < 0)
28f4698
         goto cleanup;
28f4698
     ret = 0;
28f4698
 
28f4698
@@ -799,7 +800,8 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
28f4698
                            vars,
28f4698
                            virStorageBackendLogicalRefreshPoolFunc,
28f4698
                            pool,
28f4698
-                           "vgs") < 0)
28f4698
+                           "vgs",
28f4698
+                           NULL) < 0)
28f4698
         goto cleanup;
28f4698
 
28f4698
     ret = 0;
28f4698
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
28f4698
index 027cb64..f5bd7af 100644
28f4698
--- a/src/util/vircommand.c
28f4698
+++ b/src/util/vircommand.c
28f4698
@@ -2900,6 +2900,7 @@ virCommandSetDryRun(virBufferPtr buf,
28f4698
  * needs to return 0 on success
28f4698
  * @data: additional data that will be passed to the callback function
28f4698
  * @prefix: prefix that will be skipped at the beginning of each line
28f4698
+ * @exitstatus: allows the caller to handle command run exit failures
28f4698
  *
28f4698
  * Run an external program.
28f4698
  *
28f4698
@@ -2917,7 +2918,8 @@ virCommandRunRegex(virCommandPtr cmd,
28f4698
                    int *nvars,
28f4698
                    virCommandRunRegexFunc func,
28f4698
                    void *data,
28f4698
-                   const char *prefix)
28f4698
+                   const char *prefix,
28f4698
+                   int *exitstatus)
28f4698
 {
28f4698
     int err;
28f4698
     regex_t *reg;
28f4698
@@ -2959,7 +2961,7 @@ virCommandRunRegex(virCommandPtr cmd,
28f4698
         goto cleanup;
28f4698
 
28f4698
     virCommandSetOutputBuffer(cmd, &outbuf);
28f4698
-    if (virCommandRun(cmd, NULL) < 0)
28f4698
+    if (virCommandRun(cmd, exitstatus) < 0)
28f4698
         goto cleanup;
28f4698
 
28f4698
     if (!outbuf) {
28f4698
@@ -3114,7 +3116,8 @@ virCommandRunRegex(virCommandPtr cmd ATTRIBUTE_UNUSED,
28f4698
                    int *nvars ATTRIBUTE_UNUSED,
28f4698
                    virCommandRunRegexFunc func ATTRIBUTE_UNUSED,
28f4698
                    void *data ATTRIBUTE_UNUSED,
28f4698
-                   const char *prefix ATTRIBUTE_UNUSED)
28f4698
+                   const char *prefix ATTRIBUTE_UNUSED,
28f4698
+                   int *exitstatus ATTRIBUTE_UNUSED)
28f4698
 {
28f4698
     virReportError(VIR_ERR_INTERNAL_ERROR,
28f4698
                    _("%s not implemented on Win32"), __FUNCTION__);
28f4698
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
28f4698
index 198da2f..44818ef 100644
28f4698
--- a/src/util/vircommand.h
28f4698
+++ b/src/util/vircommand.h
28f4698
@@ -205,7 +205,8 @@ int virCommandRunRegex(virCommandPtr cmd,
28f4698
                        int *nvars,
28f4698
                        virCommandRunRegexFunc func,
28f4698
                        void *data,
28f4698
-                       const char *cmd_to_ignore);
28f4698
+                       const char *cmd_to_ignore,
28f4698
+                       int *exitstatus);
28f4698
 
28f4698
 int virCommandRunNul(virCommandPtr cmd,
28f4698
                      size_t n_columns,
28f4698
diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c
28f4698
index bd34fea..846ea68 100644
28f4698
--- a/src/util/viriscsi.c
28f4698
+++ b/src/util/viriscsi.c
28f4698
@@ -87,7 +87,7 @@ virISCSIGetSession(const char *devpath,
28f4698
                            regexes,
28f4698
                            vars,
28f4698
                            virISCSIExtractSession,
28f4698
-                           &cbdata, NULL) < 0)
28f4698
+                           &cbdata, NULL, NULL) < 0)
28f4698
         goto cleanup;
28f4698
 
28f4698
     if (cbdata.session == NULL && !probe) {
28f4698
@@ -437,7 +437,7 @@ virISCSIScanTargets(const char *portal,
28f4698
                            regexes,
28f4698
                            vars,
28f4698
                            virISCSIGetTargets,
28f4698
-                           &list, NULL) < 0)
28f4698
+                           &list, NULL, NULL) < 0)
28f4698
         goto cleanup;
28f4698
 
28f4698
     for (i = 0; i < list.ntargets; i++) {