From a47d2917a50273770103abdb132186f09c466b5d Mon Sep 17 00:00:00 2001 From: Andrew Vagin Date: Sat, 20 Feb 2016 19:12:00 +0300 Subject: [PATCH] userns: use a correct type for uid and gid Currently we use int for them, but uid_t and gid_t is unsigned int. Signed-off-by: Andrew Vagin Signed-off-by: Pavel Emelyanov --- criu/include/namespaces.h | 6 ++++-- criu/namespaces.c | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h index 18c1fd9ab..cd7471016 100644 --- a/criu/include/namespaces.h +++ b/criu/include/namespaces.h @@ -94,8 +94,10 @@ extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd); extern int collect_user_namespaces(bool for_dump); extern int prepare_userns(struct pstree_item *item); extern int stop_usernsd(void); -extern int userns_uid(int uid); -extern int userns_gid(int gid); + +extern uid_t userns_uid(uid_t uid); +extern gid_t userns_gid(gid_t gid); + extern int dump_user_ns(pid_t pid, int ns_id); extern void free_userns_maps(void); diff --git a/criu/namespaces.c b/criu/namespaces.c index d89631333..d7f8a9f7e 100644 --- a/criu/namespaces.c +++ b/criu/namespaces.c @@ -507,8 +507,9 @@ int dump_task_ns_ids(struct pstree_item *item) } static UsernsEntry userns_entry = USERNS_ENTRY__INIT; +#define INVALID_ID (~0U) -static int userns_id(int id, UidGidExtent **map, int n) +static unsigned int userns_id(unsigned int id, UidGidExtent **map, int n) { int i; @@ -521,7 +522,7 @@ static int userns_id(int id, UidGidExtent **map, int n) return map[i]->first + (id - map[i]->lower_first); } - return -1; + return INVALID_ID; } static unsigned int host_id(unsigned int id, UidGidExtent **map, int n) @@ -537,7 +538,7 @@ static unsigned int host_id(unsigned int id, UidGidExtent **map, int n) return map[i]->lower_first + (id - map[i]->first); } - return -1; + return INVALID_ID; } static uid_t host_uid(uid_t uid) @@ -552,13 +553,13 @@ static gid_t host_gid(gid_t gid) return host_id(gid, e->gid_map, e->n_gid_map); } -int userns_uid(int uid) +uid_t userns_uid(uid_t uid) { UsernsEntry *e = &userns_entry; return userns_id(uid, e->uid_map, e->n_uid_map); } -int userns_gid(int gid) +gid_t userns_gid(gid_t gid) { UsernsEntry *e = &userns_entry; return userns_id(gid, e->gid_map, e->n_gid_map); @@ -672,7 +673,7 @@ static int check_user_ns(int pid) uid = host_uid(0); gid = host_gid(0); - if (uid == -1 || gid == -1) { + if (uid == INVALID_ID || gid == INVALID_ID) { pr_err("Unable to convert uid or gid\n"); return -1; }