qemu: Don't overwrite error from qemuSecurityCommandRun()

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>
This commit is contained in:
Michal Privoznik 2023-02-13 12:18:02 +01:00
parent 0634d640d6
commit 17ffdbab1f
5 changed files with 19 additions and 10 deletions

View 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;
}

View 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;
}

View 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,

View 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;
}

View 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;
}