[CRIU] [PATCH 1/2] proc_parse: parse Groups field

Ruslan Kuprieiev kupruser at gmail.com
Fri Jul 4 06:38:30 PDT 2014


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 include/proc_parse.h |  2 ++
 proc_parse.c         | 34 ++++++++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/include/proc_parse.h b/include/proc_parse.h
index b153328..a13ec14 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -83,6 +83,8 @@ struct proc_pid_stat {
 struct proc_status_creds {
 	unsigned int uids[4];
 	unsigned int gids[4];
+	unsigned int *groups;
+	unsigned int ngroups;
 
 	u32 cap_inh[PROC_CAP_SIZE];
 	u32 cap_prm[PROC_CAP_SIZE];
diff --git a/proc_parse.c b/proc_parse.c
index f2ea897..9053bec 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -689,6 +689,29 @@ static int ids_parse(char *str, unsigned int *arr)
 		return 0;
 }
 
+static int groups_parse(char *str, unsigned int **arr, unsigned int *arr_size)
+{
+	char *end;
+	unsigned int size = 0;
+	unsigned int *buf = NULL;
+
+	end = str - 1;
+	/* "Groups:" string has a space before '\n' */
+	while (!(*end == ' ' && *(end+1) == '\n')) {
+		size++;
+		buf = xrealloc(buf, size*sizeof(*buf));
+		if (!buf)
+			return -1;
+
+		buf[size-1] = strtol(end + 1, &end, 10);
+	}
+
+	*arr = buf;
+	*arr_size = size;
+
+	return 0;
+}
+
 static int cap_parse(char *str, unsigned int *res)
 {
 	int i, ret;
@@ -715,7 +738,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 		return -1;
 	}
 
-	while (done < 6 && fgets(str, sizeof(str), f)) {
+	while (done < 7 && fgets(str, sizeof(str), f)) {
 		if (!strncmp(str, "Uid:", 4)) {
 			if (ids_parse(str + 5, cr->uids))
 				goto err_parse;
@@ -730,6 +753,13 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 			done++;
 		}
 
+		if (!strncmp(str, "Groups:", 7)) {
+			if (groups_parse(str + 8, &cr->groups, &cr->ngroups))
+				goto err_parse;
+
+			done++;
+		}
+
 		if (!strncmp(str, "CapInh:", 7)) {
 			if (cap_parse(str + 8, cr->cap_inh))
 				goto err_parse;
@@ -759,7 +789,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
 		}
 	}
 
-	if (done != 6) {
+	if (done != 7) {
 err_parse:
 		pr_err("Error parsing proc status file\n");
 		fclose(f);
-- 
1.8.3.2



More information about the CRIU mailing list