mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
virParseOwnershipIds: Refactor
Use automatic clearing for temporary variable, remove 'cleanup' label and declare parameters according to new coding style rules. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
parent
7af0b6ea75
commit
568b3c6abe
@ -1377,25 +1377,24 @@ virValidateWWN(const char *wwn)
|
||||
* Returns -1 on error, 0 otherwise.
|
||||
*/
|
||||
int
|
||||
virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
|
||||
virParseOwnershipIds(const char *label,
|
||||
uid_t *uidPtr,
|
||||
gid_t *gidPtr)
|
||||
{
|
||||
int rc = -1;
|
||||
uid_t theuid;
|
||||
gid_t thegid;
|
||||
char *tmp_label = NULL;
|
||||
g_autofree char *tmp_label = g_strdup(label);
|
||||
char *sep = NULL;
|
||||
char *owner = NULL;
|
||||
char *group = NULL;
|
||||
|
||||
tmp_label = g_strdup(label);
|
||||
|
||||
/* Split label */
|
||||
sep = strchr(tmp_label, ':');
|
||||
if (sep == NULL) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("Failed to parse uid and gid from '%1$s'"),
|
||||
label);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
*sep = '\0';
|
||||
owner = tmp_label;
|
||||
@ -1406,19 +1405,14 @@ virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
|
||||
*/
|
||||
if (virGetUserID(owner, &theuid) < 0 ||
|
||||
virGetGroupID(group, &thegid) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (uidPtr)
|
||||
*uidPtr = theuid;
|
||||
if (gidPtr)
|
||||
*gidPtr = thegid;
|
||||
|
||||
rc = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(tmp_label);
|
||||
|
||||
return rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static time_t selfLastChanged;
|
||||
|
Loading…
x
Reference in New Issue
Block a user