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(a)redhat.com>
---
src/qemu/qemu_dbus.c | 6 ++++--
src/qemu/qemu_passt.c | 6 ++++--
src/qemu/qemu_security.c | 5 +++--
src/qemu/qemu_slirp.c | 6 ++++--
src/qemu/qemu_vhost_user_gpu.c | 6 ++++--
5 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_dbus.c b/src/qemu/qemu_dbus.c
index cb2694795e..a5807527a6 100644
--- a/src/qemu/qemu_dbus.c
+++ b/src/qemu/qemu_dbus.c
@@ -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;
}
diff --git a/src/qemu/qemu_passt.c b/src/qemu/qemu_passt.c
index 1217a6a087..53a7cc9605 100644
--- a/src/qemu/qemu_passt.c
+++ b/src/qemu/qemu_passt.c
@@ -275,8 +275,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;
}
diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c
index beada669f7..2548fc0ecd 100644
--- a/src/qemu/qemu_security.c
+++ b/src/qemu/qemu_security.c
@@ -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,
diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c
index faf58b0394..1bd45cb06c 100644
--- a/src/qemu/qemu_slirp.c
+++ b/src/qemu/qemu_slirp.c
@@ -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;
}
diff --git a/src/qemu/qemu_vhost_user_gpu.c b/src/qemu/qemu_vhost_user_gpu.c
index bc5a1dc3ec..a9a5fe3a3e 100644
--- a/src/qemu/qemu_vhost_user_gpu.c
+++ b/src/qemu/qemu_vhost_user_gpu.c
@@ -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;
}
--
2.39.2