[CRIU] [PATCH v2 2/3] criu: fetch kdat.has_loginuid value on C/R
Dmitry Safonov
dsafonov at odin.com
Thu Dec 24 03:43:44 PST 2015
Dump/Restore loginuid value only when kdat.has_loginuid set.
Signed-off-by: Dmitry Safonov <dsafonov at odin.com>
---
cr-dump.c | 26 ++++++++++++++++----------
cr-restore.c | 11 ++++++++---
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index fabf20a..6057db7 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -327,17 +327,23 @@ static int dump_pid_misc(pid_t pid, TaskCoreEntry *tc)
{
int ret;
- pr_info("dumping /proc/%d/{oom_score_adj,loginuid}\n", pid);
+ if (kdat.has_loginuid) {
+ pr_info("dumping /proc/%d/loginuid\n", pid);
- tc->has_loginuid = true;
- tc->loginuid = parse_pid_loginuid(pid, &ret);
- tc->loginuid = userns_uid(tc->loginuid);
- /*
- * loginuid dumping is critical, as if not correctly
- * restored, you may loss ability to login via SSH to CT
- */
- if (ret < 0)
- return ret;
+ tc->has_loginuid = true;
+ tc->loginuid = parse_pid_loginuid(pid, &ret);
+ tc->loginuid = userns_uid(tc->loginuid);
+ /*
+ * loginuid dumping is critical, as if not correctly
+ * restored, you may loss ability to login via SSH to CT
+ */
+ if (ret < 0)
+ return ret;
+ } else {
+ tc->has_loginuid = false;
+ }
+
+ pr_info("dumping /proc/%d/oom_score_adj\n", pid);
tc->oom_score_adj = parse_pid_oom_score_adj(pid, &ret);
/*
diff --git a/cr-restore.c b/cr-restore.c
index 52d70a9..9bcbeba 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -865,7 +865,8 @@ static int prepare_proc_misc(pid_t pid, TaskCoreEntry *tc)
int ret;
/* loginuid value is critical to restore */
- if (tc->has_loginuid && tc->loginuid != INVALID_UID) {
+ if (kdat.has_loginuid && tc->has_loginuid &&
+ tc->loginuid != INVALID_UID) {
ret = prepare_loginuid(tc->loginuid);
if (ret < 0)
return ret;
@@ -1852,9 +1853,10 @@ static unsigned int saved_loginuid;
static int prepare_userns_hook(void)
{
- pid_t pid = getpid();
int ret;
+ if (!kdat.has_loginuid)
+ return 0;
/*
* Save old loginuid and set it to INVALID_UID:
* this value means that loginuid is unset and it will be inherited.
@@ -1862,7 +1864,7 @@ static int prepare_userns_hook(void)
* inside container due to permissions.
* But you still can set this value if it was unset.
*/
- saved_loginuid = parse_pid_loginuid(pid, &ret);
+ saved_loginuid = parse_pid_loginuid(getpid(), &ret);
if (ret < 0)
return -1;
@@ -1875,6 +1877,9 @@ static int prepare_userns_hook(void)
static void restore_origin_ns_hook(void)
{
+ if (!kdat.has_loginuid)
+ return;
+
/* not critical: it does not affect CT in any way */
if (prepare_loginuid(saved_loginuid) < 0)
pr_err("Restore original /proc/self/loginuid failed");
--
2.6.4
More information about the CRIU
mailing list