]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_domain.c: modernize qemuDomainWriteMasterKeyFile()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Thu, 12 Nov 2020 21:14:54 +0000 (18:14 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 13 Nov 2020 15:11:44 +0000 (12:11 -0300)
Use VIR_AUTOCLOSE with 'fd' and delete the 'cleanup' label.

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/qemu/qemu_domain.c

index 2ab46d4b4dbc276e55e8d22a511c6b7deb3b6a12..421a3786136bc522480e568726bd3e6cf3645067 100644 (file)
@@ -406,8 +406,7 @@ qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                              virDomainObjPtr vm)
 {
     g_autofree char *path = NULL;
-    int fd = -1;
-    int ret = -1;
+    VIR_AUTOCLOSE fd = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
     /* Only gets filled in if we have the capability */
@@ -420,24 +419,19 @@ qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
     if ((fd = open(path, O_WRONLY|O_TRUNC|O_CREAT, 0600)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("failed to open domain master key file for write"));
-        goto cleanup;
+        return -1;
     }
 
     if (safewrite(fd, priv->masterKey, priv->masterKeyLen) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("failed to write master key file for domain"));
-        goto cleanup;
+        return -1;
     }
 
     if (qemuSecurityDomainSetPathLabel(driver, vm, path, false) < 0)
-        goto cleanup;
-
-    ret = 0;
-
- cleanup:
-    VIR_FORCE_CLOSE(fd);
+        return -1;
 
-    return ret;
+    return 0;
 }