mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
qemu_domain.c: modernize qemuDomainWriteMasterKeyFile()
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>
This commit is contained in:
parent
5a5fde03bb
commit
8a778ebfe1
@ -406,8 +406,7 @@ qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
|
|||||||
virDomainObjPtr vm)
|
virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
g_autofree char *path = NULL;
|
g_autofree char *path = NULL;
|
||||||
int fd = -1;
|
VIR_AUTOCLOSE fd = -1;
|
||||||
int ret = -1;
|
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
|
||||||
/* Only gets filled in if we have the capability */
|
/* 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) {
|
if ((fd = open(path, O_WRONLY|O_TRUNC|O_CREAT, 0600)) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("failed to open domain master key file for write"));
|
_("failed to open domain master key file for write"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safewrite(fd, priv->masterKey, priv->masterKeyLen) < 0) {
|
if (safewrite(fd, priv->masterKey, priv->masterKeyLen) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("failed to write master key file for domain"));
|
_("failed to write master key file for domain"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuSecurityDomainSetPathLabel(driver, vm, path, false) < 0)
|
if (qemuSecurityDomainSetPathLabel(driver, vm, path, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user