qemu: refactor virQEMUCapsNewForBinaryInternal

Use g_auto and remove pointless labels.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
This commit is contained in:
Ján Tomko 2021-08-23 16:21:18 +02:00
parent fa8f99bbee
commit a41b23d718

View File

@ -5430,18 +5430,18 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
unsigned int microcodeVersion, unsigned int microcodeVersion,
const char *kernelVersion) const char *kernelVersion)
{ {
virQEMUCaps *qemuCaps; g_autoptr(virQEMUCaps) qemuCaps = NULL;
struct stat sb; struct stat sb;
if (!(qemuCaps = virQEMUCapsNewBinary(binary))) if (!(qemuCaps = virQEMUCapsNewBinary(binary)))
goto error; return NULL;
/* We would also want to check faccessat if we cared about ACLs, /* We would also want to check faccessat if we cared about ACLs,
* but we don't. */ * but we don't. */
if (stat(binary, &sb) < 0) { if (stat(binary, &sb) < 0) {
virReportSystemError(errno, _("Cannot check QEMU binary %s"), virReportSystemError(errno, _("Cannot check QEMU binary %s"),
binary); binary);
goto error; return NULL;
} }
qemuCaps->ctime = sb.st_ctime; qemuCaps->ctime = sb.st_ctime;
@ -5452,20 +5452,20 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
if (!virFileIsExecutable(binary)) { if (!virFileIsExecutable(binary)) {
virReportSystemError(errno, _("QEMU binary %s is not executable"), virReportSystemError(errno, _("QEMU binary %s is not executable"),
binary); binary);
goto error; return NULL;
} }
if (virFileExists(QEMU_MODDIR)) { if (virFileExists(QEMU_MODDIR)) {
if (stat(QEMU_MODDIR, &sb) < 0) { if (stat(QEMU_MODDIR, &sb) < 0) {
virReportSystemError(errno, _("Cannot check QEMU module directory %s"), virReportSystemError(errno, _("Cannot check QEMU module directory %s"),
QEMU_MODDIR); QEMU_MODDIR);
goto error; return NULL;
} }
qemuCaps->modDirMtime = sb.st_mtime; qemuCaps->modDirMtime = sb.st_mtime;
} }
if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid) < 0) if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid) < 0)
goto error; return NULL;
qemuCaps->libvirtCtime = virGetSelfLastChanged(); qemuCaps->libvirtCtime = virGetSelfLastChanged();
qemuCaps->libvirtVersion = LIBVIR_VERSION_NUMBER; qemuCaps->libvirtVersion = LIBVIR_VERSION_NUMBER;
@ -5484,11 +5484,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
qemuCaps->kvmSupportsSecureGuest = virQEMUCapsKVMSupportsSecureGuest(); qemuCaps->kvmSupportsSecureGuest = virQEMUCapsKVMSupportsSecureGuest();
} }
return qemuCaps; return g_steal_pointer(&qemuCaps);
error:
virObjectUnref(qemuCaps);
return NULL;
} }
static void * static void *