mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: use g_autofree in virSCSIHostGetUniqueId
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
2c211820cf
commit
843b709954
@ -46,17 +46,16 @@ int
|
|||||||
virSCSIHostGetUniqueId(const char *sysfs_prefix,
|
virSCSIHostGetUniqueId(const char *sysfs_prefix,
|
||||||
int host)
|
int host)
|
||||||
{
|
{
|
||||||
char *sysfs_path = NULL;
|
g_autofree char *sysfs_path = NULL;
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
int ret = -1;
|
g_autofree char *buf = NULL;
|
||||||
char *buf = NULL;
|
|
||||||
int unique_id;
|
int unique_id;
|
||||||
|
|
||||||
sysfs_path = g_strdup_printf("%s/host%d/unique_id",
|
sysfs_path = g_strdup_printf("%s/host%d/unique_id",
|
||||||
sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host);
|
sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host);
|
||||||
|
|
||||||
if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
|
if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if ((p = strchr(buf, '\n')))
|
if ((p = strchr(buf, '\n')))
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
@ -65,15 +64,10 @@ virSCSIHostGetUniqueId(const char *sysfs_prefix,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unable to parse unique_id: %s"), buf);
|
_("unable to parse unique_id: %s"), buf);
|
||||||
|
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = unique_id;
|
return unique_id;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(sysfs_path);
|
|
||||||
VIR_FREE(buf);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user