]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Add exitstatus parameter to virCommandRunRegex
authorJohn Ferlan <jferlan@redhat.com>
Fri, 13 May 2016 16:36:39 +0000 (12:36 -0400)
committerCole Robinson <crobinso@redhat.com>
Thu, 23 Jun 2016 19:40:48 +0000 (15:40 -0400)
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.

(cherry picked from commit 8b1049473317c09d34b3ce9671d0f9e91dd4f1c0)

src/storage/storage_backend_fs.c
src/storage/storage_backend_logical.c
src/util/vircommand.c
src/util/vircommand.h
src/util/viriscsi.c

index 692c9ff17989541efced0596cd1bfa5403bcf288..93d65aafa17009adfb9a29472af1c5c7ff86f1d9 100644 (file)
@@ -261,7 +261,7 @@ virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *state)
 
     if (virCommandRunRegex(cmd, 1, regexes, vars,
                            virStorageBackendFileSystemNetFindPoolSourcesFunc,
-                           state, NULL) < 0)
+                           state, NULL, NULL) < 0)
         goto cleanup;
 
     ret = 0;
index 90a194ebc44c75f84bfa03e97fa1b96554e6f9cf..ca05fe1a0062c95ebe2566c5ac93f654311d39ee 100644 (file)
@@ -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;
index 027cb6477cd46198483ec67d8c7c8cd4dc90c726..f5bd7af5e8a1890d39d91425e9fb1b1baac21aca 100644 (file)
@@ -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__);
index 198da2f9e386826e32211ff4d4a0b218614a9b87..44818efe2ab2125b2457dda0eb3605a7e0b499c3 100644 (file)
@@ -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,
index bd34feaa3766f2401f8b1165577c0be9d6afefd4..846ea686a18a7bda72f41d3543fb012535a00905 100644 (file)
@@ -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++) {