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

[libvirt] [PATCH 1/6] util: Add exitstatus parameter to virCommandRunRegex



Rather than have virCommandRun just spit out the error, allow callers
to decide to pass the exitstatus so the caller can make intelligent
decisions based on the error.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/storage/storage_backend_fs.c      |  2 +-
 src/storage/storage_backend_logical.c | 10 ++++++----
 src/util/vircommand.c                 |  9 ++++++---
 src/util/vircommand.h                 |  3 ++-
 src/util/viriscsi.c                   |  4 ++--
 5 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 02a129e..45474cb 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -267,7 +267,7 @@ virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *state)
 
     if (virCommandRunRegex(cmd, 1, regexes, vars,
                            virStorageBackendFileSystemNetFindPoolSourcesFunc,
-                           state, NULL) < 0)
+                           state, NULL, NULL) < 0)
         goto cleanup;
 
     ret = 0;
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 90a194e..ca05fe1 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -398,7 +398,8 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
                            vars,
                            virStorageBackendLogicalMakeVol,
                            &cbdata,
-                           "lvs") < 0)
+                           "lvs",
+                           NULL) < 0)
         goto cleanup;
 
     ret = 0;
@@ -511,10 +512,10 @@ virStorageBackendLogicalGetPoolSources(virStoragePoolSourceListPtr sourceList)
     cmd = virCommandNewArgList(PVS,
                                "--noheadings",
                                "-o", "pv_name,vg_name",
-                               NULL);
+                               NULL, NULL);
     if (virCommandRunRegex(cmd, 1, regexes, vars,
                            virStorageBackendLogicalFindPoolSourcesFunc,
-                           sourceList, "pvs") < 0)
+                           sourceList, "pvs", NULL) < 0)
         goto cleanup;
     ret = 0;
 
@@ -799,7 +800,8 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                            vars,
                            virStorageBackendLogicalRefreshPoolFunc,
                            pool,
-                           "vgs") < 0)
+                           "vgs",
+                           NULL) < 0)
         goto cleanup;
 
     ret = 0;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 027cb64..f5bd7af 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2900,6 +2900,7 @@ virCommandSetDryRun(virBufferPtr buf,
  * needs to return 0 on success
  * @data: additional data that will be passed to the callback function
  * @prefix: prefix that will be skipped at the beginning of each line
+ * @exitstatus: allows the caller to handle command run exit failures
  *
  * Run an external program.
  *
@@ -2917,7 +2918,8 @@ virCommandRunRegex(virCommandPtr cmd,
                    int *nvars,
                    virCommandRunRegexFunc func,
                    void *data,
-                   const char *prefix)
+                   const char *prefix,
+                   int *exitstatus)
 {
     int err;
     regex_t *reg;
@@ -2959,7 +2961,7 @@ virCommandRunRegex(virCommandPtr cmd,
         goto cleanup;
 
     virCommandSetOutputBuffer(cmd, &outbuf);
-    if (virCommandRun(cmd, NULL) < 0)
+    if (virCommandRun(cmd, exitstatus) < 0)
         goto cleanup;
 
     if (!outbuf) {
@@ -3114,7 +3116,8 @@ virCommandRunRegex(virCommandPtr cmd ATTRIBUTE_UNUSED,
                    int *nvars ATTRIBUTE_UNUSED,
                    virCommandRunRegexFunc func ATTRIBUTE_UNUSED,
                    void *data ATTRIBUTE_UNUSED,
-                   const char *prefix ATTRIBUTE_UNUSED)
+                   const char *prefix ATTRIBUTE_UNUSED,
+                   int *exitstatus ATTRIBUTE_UNUSED)
 {
     virReportError(VIR_ERR_INTERNAL_ERROR,
                    _("%s not implemented on Win32"), __FUNCTION__);
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index 198da2f..44818ef 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -205,7 +205,8 @@ int virCommandRunRegex(virCommandPtr cmd,
                        int *nvars,
                        virCommandRunRegexFunc func,
                        void *data,
-                       const char *cmd_to_ignore);
+                       const char *cmd_to_ignore,
+                       int *exitstatus);
 
 int virCommandRunNul(virCommandPtr cmd,
                      size_t n_columns,
diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c
index bd34fea..846ea68 100644
--- a/src/util/viriscsi.c
+++ b/src/util/viriscsi.c
@@ -87,7 +87,7 @@ virISCSIGetSession(const char *devpath,
                            regexes,
                            vars,
                            virISCSIExtractSession,
-                           &cbdata, NULL) < 0)
+                           &cbdata, NULL, NULL) < 0)
         goto cleanup;
 
     if (cbdata.session == NULL && !probe) {
@@ -437,7 +437,7 @@ virISCSIScanTargets(const char *portal,
                            regexes,
                            vars,
                            virISCSIGetTargets,
-                           &list, NULL) < 0)
+                           &list, NULL, NULL) < 0)
         goto cleanup;
 
     for (i = 0; i < list.ntargets; i++) {
-- 
2.5.5


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