[CRIU] [PATCH] userns: use a correct type for uid and gid
Andrey Vagin
avagin at openvz.org
Sat Feb 20 08:12:52 PST 2016
From: Andrew Vagin <avagin at virtuozzo.com>
Currently we use int for them, but uid_t and gid_t is unsigned int.
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
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 eba0fac..20fbbaa 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -88,8 +88,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 bb5b622..744a711 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -493,8 +493,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;
@@ -507,7 +508,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)
@@ -523,7 +524,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)
@@ -538,13 +539,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);
@@ -658,7 +659,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;
}
--
2.5.0
More information about the CRIU
mailing list