[CRIU] [PATCH 1/3] criu: dump loginuid & oom_score_adj values

Dmitry Safonov dsafonov at odin.com
Mon Dec 7 06:17:08 PST 2015


https://jira.sw.ru/browse/PSBM-41993

Signed-off-by: Dmitry Safonov <dsafonov at odin.com>
---
 cr-dump.c            | 11 +++++++++++
 include/proc_parse.h |  2 ++
 proc_parse.c         | 38 ++++++++++++++++++++++++++++++++++++++
 protobuf/core.proto  |  5 +++++
 4 files changed, 56 insertions(+)

diff --git a/cr-dump.c b/cr-dump.c
index 5cc375d..06cf428 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -323,6 +323,15 @@ static int dump_task_rlimits(int pid, TaskRlimitsEntry *rls)
 	return 0;
 }
 
+static void dump_pid_misc(pid_t pid, TaskCoreEntry *tc)
+{
+	pr_info("dumping /proc/%d/{oom_score_adj,loginuid}\n", pid);
+	tc->loginuid = parse_pid_loginuid(pid);
+	tc->has_loginuid = true;
+	tc->oom_score_adj = parse_pid_oom_score_adj(pid);
+	tc->has_oom_score_adj = true;
+}
+
 static int dump_filemap(pid_t pid, struct vma_area *vma_area,
 		const struct cr_imgset *imgset)
 {
@@ -702,6 +711,8 @@ static int dump_task_core_all(struct pstree_item *item,
 	if (ret)
 		goto err;
 
+	dump_pid_misc(pid, core->tc);
+
 	ret = dump_task_rlimits(pid, core->tc->rlimits);
 	if (ret)
 		goto err;
diff --git a/include/proc_parse.h b/include/proc_parse.h
index e45d93f..3cc821b 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -114,6 +114,8 @@ struct vm_area_list;
 extern bool add_skip_mount(const char *mountpoint);
 extern struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump);
 extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
+extern unsigned int parse_pid_loginuid(pid_t pid);
+extern int parse_pid_oom_score_adj(pid_t pid);
 extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list);
 extern int parse_self_maps_lite(struct vm_area_list *vms);
 extern int parse_pid_status(pid_t pid, struct proc_status_creds *);
diff --git a/proc_parse.c b/proc_parse.c
index c479b0f..c40a1b1 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -724,6 +724,44 @@ err:
 	return -1;
 }
 
+unsigned int parse_pid_loginuid(pid_t pid)
+{
+	unsigned int ret = 4294967295; /* unset value */
+	int fd;
+
+	fd = open_proc(pid, "loginuid");
+	if (fd < 0)
+		goto out;
+
+	if (read(fd, buf, BUF_SIZE) < 0)
+		goto close_out;
+	ret = strtol(buf, NULL, 10);
+
+close_out:
+	close(fd);
+out:
+	return ret;
+}
+
+int parse_pid_oom_score_adj(pid_t pid)
+{
+	int ret = 0;
+	int fd;
+
+	fd = open_proc(pid, "oom_score_adj");
+	if (fd < 0)
+		goto out;
+
+	if (read(fd, buf, BUF_SIZE) < 0)
+		goto close_out;
+	ret = strtol(buf, NULL, 10);
+
+close_out:
+	close(fd);
+out:
+	return ret;
+}
+
 static int ids_parse(char *str, unsigned int *arr)
 {
 	char *end;
diff --git a/protobuf/core.proto b/protobuf/core.proto
index 94322c0..4fe604e 100644
--- a/protobuf/core.proto
+++ b/protobuf/core.proto
@@ -38,6 +38,11 @@ message task_core_entry {
 
 	optional seccomp_mode		seccomp_mode	= 11;
 	optional uint32			seccomp_filter	= 12;
+
+	optional uint32			loginuid	= 13
+					[default = 4294967295]; /* not set */
+
+	optional int32			oom_score_adj	= 14;
 }
 
 message task_kobj_ids_entry {
-- 
2.6.3



More information about the CRIU mailing list