Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 5b7069c

Browse files
committed
Merge pull request #102 from laijs/HOME-env
set the HOME env correctly when it is not configured
2 parents 185cfb9 + ece6aa1 commit 5b7069c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/container.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,19 +488,14 @@ static int hyper_container_init(void *data)
488488
goto fail;
489489
}
490490

491-
// set additinal env before config so that the config can overwrite it
491+
// set early env. the container env config can overwrite it
492492
setenv("HOME", "/root", 1);
493493
setenv("HOSTNAME", arg->pod->hostname, 1);
494494
if (container->exec.tty)
495495
setenv("TERM", "xterm", 1);
496496
else
497497
unsetenv("TERM");
498498

499-
if (hyper_setup_env(container->exec.envs, container->exec.envs_num) < 0) {
500-
fprintf(stdout, "setup env failed\n");
501-
goto fail;
502-
}
503-
504499
if (mount("", "/", NULL, MS_SLAVE|MS_REC, NULL) < 0) {
505500
perror("mount SLAVE failed");
506501
goto fail;
@@ -615,6 +610,12 @@ static int hyper_container_init(void *data)
615610
goto fail;
616611
}
617612

613+
// set the container env
614+
if (hyper_setup_env(container->exec.envs, container->exec.envs_num) < 0) {
615+
fprintf(stdout, "setup env failed\n");
616+
goto fail;
617+
}
618+
618619
hyper_send_type(arg->pipe[1], READY);
619620
fflush(stdout);
620621

src/exec.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ int hyper_setup_exec_user(struct hyper_exec *exec)
271271
perror("setuid() fails");
272272
goto fail;
273273
}
274+
free(groups);
275+
276+
// set user related envs. the container env config can overwrite it
277+
setenv("USER", pwd->pw_name, 1);
278+
setenv("HOME", pwd->pw_dir, 1);
279+
274280
return 0;
275281

276282
fail:

0 commit comments

Comments
 (0)