]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Don't overwrite error from qemuSecurityCommandRun()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 13 Feb 2023 11:18:02 +0000 (12:18 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 3 Mar 2023 11:02:30 +0000 (12:02 +0100)
The usual pattern when starting a helper daemon is:

  if (qemuSecurityCommandRun(..., &exitstatus, &cmdret) < 0)
      goto cleanup;

  if (cmdret < 0 || exitstatus != 0) {
      virReportError();
      goto cleanup;
  }

The only problem with this pattern is that if virCommandRun()
fails (i.e. cmdret < 0), then proper error was already reported.
But in this pattern we overwrite it (usually with less specific)
error.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_dbus.c
src/qemu/qemu_passt.c
src/qemu/qemu_security.c
src/qemu/qemu_slirp.c
src/qemu/qemu_vhost_user_gpu.c

index cb2694795e5923551ca5b80cd905b41caea7131e..a5807527a671ed8bfddba23fe0729b69ea426cba 100644 (file)
@@ -224,8 +224,10 @@ qemuDBusStart(virQEMUDriver *driver,
         goto cleanup;
 
     if (cmdret < 0 || exitstatus != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not start dbus-daemon. exitstatus: %d"), exitstatus);
+        if (cmdret >= 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Could not start dbus-daemon. exitstatus: %d"), exitstatus);
+        }
         goto cleanup;
     }
 
index 8d28a554551fa0c798279a02bd8f1f08194dd49e..158bd5b5b24b1ca6576fdfb8de1b02bfbe2c3ba4 100644 (file)
@@ -289,8 +289,10 @@ qemuPasstStart(virDomainObj *vm,
         goto error;
 
     if (cmdret < 0 || exitstatus != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not start 'passt': %s"), NULLSTR(errbuf));
+        if (cmdret >= 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Could not start 'passt': %s"), NULLSTR(errbuf));
+        }
         goto error;
     }
 
index beada669f7f1ec975b79ef0c691982b7afc46fdf..2548fc0ecd464ca141f5ddf625f9966895ca798a 100644 (file)
@@ -626,10 +626,11 @@ qemuSecurityDomainRestorePathLabel(virQEMUDriver *driver,
  * @cmdret: pointer to int returning result of virCommandRun
  *
  * Run @cmd with seclabels set on it. If @uid and/or @gid are not
- * -1 then their value is enforced.
+ * -1 then their value is enforced. If @cmdret is negative upon
+ *  return, then appropriate error was already reported.
  *
  * Returns: 0 on success,
- *         -1 otherwise.
+ *         -1 otherwise (with error reported).
  */
 int
 qemuSecurityCommandRun(virQEMUDriver *driver,
index faf58b03944c97d87522471645bfb66751a8804f..1bd45cb06ceae16b5bfe7964534bf56d401a0077 100644 (file)
@@ -331,8 +331,10 @@ qemuSlirpStart(virDomainObj *vm,
         goto error;
 
     if (cmdret < 0 || exitstatus != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not start 'slirp'. exitstatus: %d"), exitstatus);
+        if (cmdret >= 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Could not start 'slirp'. exitstatus: %d"), exitstatus);
+        }
         goto error;
     }
 
index bc5a1dc3ec838432af1e4d3474f3067f6a962928..a9a5fe3a3e3d7327f73ea6ba774fb72c5ddac578 100644 (file)
@@ -157,8 +157,10 @@ int qemuExtVhostUserGPUStart(virQEMUDriver *driver,
         goto error;
 
     if (cmdret < 0 || exitstatus != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not start 'vhost-user-gpu'. exitstatus: %d"), exitstatus);
+        if (cmdret >= 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Could not start 'vhost-user-gpu'. exitstatus: %d"), exitstatus);
+        }
         goto cleanup;
     }