From ece6aa1a79413ff4f30b564cc7c0b3794c4ba5ef Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Thu, 19 May 2016 20:23:45 +0800 Subject: [PATCH] set the HOME env correctly when it is not configured Signed-off-by: Lai Jiangshan --- src/container.c | 13 +++++++------ src/exec.c | 6 ++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/container.c b/src/container.c index ff3c268..3e610e9 100644 --- a/src/container.c +++ b/src/container.c @@ -488,7 +488,7 @@ static int hyper_container_init(void *data) goto fail; } - // set additinal env before config so that the config can overwrite it + // set early env. the container env config can overwrite it setenv("HOME", "/root", 1); setenv("HOSTNAME", arg->pod->hostname, 1); if (container->exec.tty) @@ -496,11 +496,6 @@ static int hyper_container_init(void *data) else unsetenv("TERM"); - if (hyper_setup_env(container->exec.envs, container->exec.envs_num) < 0) { - fprintf(stdout, "setup env failed\n"); - goto fail; - } - if (mount("", "/", NULL, MS_SLAVE|MS_REC, NULL) < 0) { perror("mount SLAVE failed"); goto fail; @@ -615,6 +610,12 @@ static int hyper_container_init(void *data) goto fail; } + // set the container env + if (hyper_setup_env(container->exec.envs, container->exec.envs_num) < 0) { + fprintf(stdout, "setup env failed\n"); + goto fail; + } + hyper_send_type(arg->pipe[1], READY); fflush(stdout); diff --git a/src/exec.c b/src/exec.c index d1ec58e..4237d01 100644 --- a/src/exec.c +++ b/src/exec.c @@ -271,6 +271,12 @@ int hyper_setup_exec_user(struct hyper_exec *exec) perror("setuid() fails"); goto fail; } + free(groups); + + // set user related envs. the container env config can overwrite it + setenv("USER", pwd->pw_name, 1); + setenv("HOME", pwd->pw_dir, 1); + return 0; fail: