]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Let virCommand module translate exitstatus
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 13 Feb 2023 11:35:28 +0000 (12:35 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 3 Mar 2023 11:03:25 +0000 (12:03 +0100)
When starting (some) external helpers, callers of
qemuSecurityCommandRun() pass &exitstatus variable, to learn the
exit code of helper process (with qemuTPMEmulatorStart() being
the only exception). Then, if the status wasn't zero they produce
a generic error message, like:

  "Starting of helper process failed. exitstatus=%d"

or, in case of qemuPasstStart():

  "Could not start 'passt': %s"

This is needless as virCommandRun() (that's called under the
hood), can do both for us, if NULL was passed instead of
@exitstatus. Not only it appends exit status, it also reads
stderr of failed command producing comprehensive error message:

  Child process (${args}) unexpected exit status ${exitstatus}: ${stderr}

Therefore, pass NULL everywhere. But in contrast with one of
previous commits which removed @cmdret argument, there could be a
sensible caller which might want to process exit code. So keep
the argument for now and just pass NULL.

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 74cb5457ea6f8768379fc3755d51cd7e5de00ed4..a6dc802637bd1410f355151f5c6ea76a08b7f597 100644 (file)
@@ -182,7 +182,6 @@ qemuDBusStart(virQEMUDriver *driver,
     virTimeBackOffVar timebackoff;
     const unsigned long long timeout = 500 * 1000; /* ms */
     VIR_AUTOCLOSE errfd = -1;
-    int exitstatus = 0;
     pid_t cpid = -1;
     int ret = -1;
 
@@ -218,15 +217,9 @@ qemuDBusStart(virQEMUDriver *driver,
     virCommandDaemonize(cmd);
     virCommandAddArgFormat(cmd, "--config-file=%s", configfile);
 
-    if (qemuSecurityCommandRun(driver, vm, cmd, -1, -1, &exitstatus) < 0)
+    if (qemuSecurityCommandRun(driver, vm, cmd, -1, -1, NULL) < 0)
         goto cleanup;
 
-    if (exitstatus != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not start dbus-daemon. exitstatus: %d"), exitstatus);
-        goto cleanup;
-    }
-
     if (virPidFileReadPath(pidfile, &cpid) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("dbus-daemon %s didn't show up"),
index 7f67c3dcc304077b8256069c88a53c56352d46d1..0afa8bdb3addefe4975fe28acc1d6ae5958e8b2f 100644 (file)
@@ -169,15 +169,12 @@ qemuPasstStart(virDomainObj *vm,
     g_autofree char *passtSocketName = qemuPasstCreateSocketPath(vm, net);
     g_autoptr(virCommand) cmd = NULL;
     g_autofree char *pidfile = qemuPasstCreatePidFilename(vm, net);
-    g_autofree char *errbuf = NULL;
     char macaddr[VIR_MAC_STRING_BUFLEN];
     size_t i;
-    int exitstatus = 0;
 
     cmd = virCommandNew(PASST);
 
     virCommandClearCaps(cmd);
-    virCommandSetErrorBuffer(cmd, &errbuf);
 
     virCommandAddArgList(cmd,
                          "--one-off",
@@ -284,15 +281,9 @@ qemuPasstStart(virDomainObj *vm,
     if (qemuExtDeviceLogCommand(driver, vm, cmd, "passt") < 0)
         return -1;
 
-    if (qemuSecurityCommandRun(driver, vm, cmd, -1, -1, &exitstatus) < 0)
+    if (qemuSecurityCommandRun(driver, vm, cmd, -1, -1, NULL) < 0)
         goto error;
 
-    if (exitstatus != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not start 'passt': %s"), NULLSTR(errbuf));
-        goto error;
-    }
-
     return 0;
 
  error:
index 07fcffb28864128197de06c1baf1dfef469d1de4..ee03e2225e495aaf4825e5c70c44af2b9c19a684 100644 (file)
@@ -622,7 +622,7 @@ qemuSecurityDomainRestorePathLabel(virQEMUDriver *driver,
  * @cmd: the command to run
  * @uid: the uid to force
  * @gid: the gid to force
- * @existstatus: pointer to int returning exit status of process
+ * @existstatus: optional pointer to int returning exit status of process
  *
  * Run @cmd with seclabels set on it. If @uid and/or @gid are not
  * -1 then their value is enforced.
index bbe919f37a2f755ca4480a6f976fcf005f78b584..9697542cd3d83c8bb0b05cb4e374dd18efa34412 100644 (file)
@@ -247,7 +247,6 @@ qemuSlirpStart(virDomainObj *vm,
     size_t i;
     pid_t pid = (pid_t) -1;
     int rc;
-    int exitstatus = 0;
     bool killDBusDaemon = false;
     g_autofree char *fdname = g_strdup_printf("slirpfd-%s", net->info.alias);
 
@@ -326,15 +325,9 @@ qemuSlirpStart(virDomainObj *vm,
     if (qemuExtDeviceLogCommand(driver, vm, cmd, "slirp") < 0)
         goto error;
 
-    if (qemuSecurityCommandRun(driver, vm, cmd, -1, -1, &exitstatus) < 0)
+    if (qemuSecurityCommandRun(driver, vm, cmd, -1, -1, NULL) < 0)
         goto error;
 
-    if (exitstatus != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not start 'slirp'. exitstatus: %d"), exitstatus);
-        goto error;
-    }
-
     rc = virPidFileReadPath(pidfile, &pid);
     if (rc < 0) {
         virReportSystemError(-rc,
index 196ebc7dff12037f110a16d49416ed111c936ea8..5b49ef4e28c7722a3b0ca657dff028755e72851d 100644 (file)
@@ -106,7 +106,6 @@ int qemuExtVhostUserGPUStart(virQEMUDriver *driver,
     g_autoptr(virCommand) cmd = NULL;
     int pair[2] = { -1, -1 };
     int rc;
-    int exitstatus = 0;
     pid_t pid;
     int ret = -1;
 
@@ -153,15 +152,9 @@ int qemuExtVhostUserGPUStart(virQEMUDriver *driver,
             virCommandAddArgFormat(cmd, "--render-node=%s", video->accel->rendernode);
     }
 
-    if (qemuSecurityCommandRun(driver, vm, cmd, -1, -1, &exitstatus) < 0)
+    if (qemuSecurityCommandRun(driver, vm, cmd, -1, -1, NULL) < 0)
         goto error;
 
-    if (exitstatus != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not start 'vhost-user-gpu'. exitstatus: %d"), exitstatus);
-        goto cleanup;
-    }
-
     rc = virPidFileReadPath(pidfile, &pid);
     if (rc < 0) {
         virReportSystemError(-rc,