[CRIU] [PATCH v2 2/3] criu: restore loginuid & oom_score_adj values

Dmitry Safonov dsafonov at odin.com
Tue Dec 8 01:54:43 PST 2015


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

Signed-off-by: Dmitry Safonov <dsafonov at odin.com>
---
 cr-restore.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/cr-restore.c b/cr-restore.c
index 1c0c641..00fcd57 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -840,6 +840,48 @@ err:
 	return -1;
 }
 
+static void prepare_pid_oom_score_adj(pid_t pid, int value)
+{
+	int fd;
+	char buf[11];
+
+	fd = open_proc_rw(pid, "oom_score_adj");
+	if (fd < 0) {
+		pr_err("Can't open /proc/%d/oom_score_adj to restore\n", pid);
+		return;
+	}
+	snprintf(buf, 11, "%d", value);
+	if (write(fd, buf, 11) < 0)
+		pr_perror("Write %s to /proc/%d/oom_score_adj failed",
+			buf, pid);
+	close(fd);
+}
+
+static void prepare_pid_loginuid(pid_t pid, unsigned int value)
+{
+	int fd;
+	char buf[11]; /* 4294967295 is maximum for u32 */
+
+	fd = open_proc_rw(pid, "loginuid");
+	if (fd < 0) {
+		pr_err("Can't open /proc/%d/loginuid to restore\n", pid);
+		return;
+	}
+	snprintf(buf, 11, "%u", value);
+	if (write(fd, buf, 11) < 0)
+		pr_perror("Write %s to /proc/%d/loginuid failed", buf, pid);
+	close(fd);
+}
+
+static int prepare_proc_misc(pid_t pid, TaskCoreEntry *tc)
+{
+	if (tc->has_loginuid)
+		prepare_pid_loginuid(pid, tc->loginuid);
+	if (tc->has_oom_score_adj)
+		prepare_pid_oom_score_adj(pid, tc->oom_score_adj);
+	return 0;
+}
+
 static int restore_one_alive_task(int pid, CoreEntry *core)
 {
 	pr_info("Restoring resources\n");
@@ -876,6 +918,9 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
 	if (inherit_fd_fini() < 0)
 		return -1;
 
+	if (prepare_proc_misc(pid, core->tc))
+		return -1;
+
 	return sigreturn_restore(pid, core);
 }
 
-- 
2.6.3



More information about the CRIU mailing list