qemu: Let virCommand module translate exitstatus

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>
This commit is contained in:
Michal Privoznik 2023-02-13 12:35:28 +01:00
parent caa25f75cf
commit cf01bbb992
5 changed files with 5 additions and 35 deletions

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

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

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

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

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