lxc/0045-only-set-user-or-image-set-non-empty-HOME.patch
haozi007 1708e9f6f0 only set user or image setting non-empty HOME
Signed-off-by: haozi007 <liuhao27@huawei.com>
(cherry picked from commit e35f3ad3dba97992b16c3299053699d7f90410f6)
2022-08-15 09:37:36 +08:00

42 lines
1.1 KiB
Diff

From 813af4193dd4d2d998c040d020879ea3b5c46100 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Sat, 13 Aug 2022 18:34:04 +0800
Subject: [PATCH] only set user or image set non-empty HOME
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
src/lxc/utils.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 20ca181..ed66935 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -2218,6 +2218,13 @@ int lxc_setup_env_home(uid_t uid)
FILE *stream = NULL;
struct passwd pw, *pwbufp = NULL;
char buf[BUFSIZ];
+ const char *curr_home = NULL;
+
+ curr_home = getenv("HOME");
+ // if user set or image set, just use it.
+ if (curr_home != NULL && strcmp(curr_home, "") != 0) {
+ return 0;
+ }
stream = fopen_cloexec(__PASSWD_FILE__, "r");
if (stream == NULL) {
@@ -2242,7 +2249,8 @@ set_env:
fclose(stream);
// if we didn't configure HOME, set it based on uid
- if (setenv("HOME", homedir, 0) < 0) {
+ // override it if reach here.
+ if (setenv("HOME", homedir, 1) < 0) {
SYSERROR("Unable to set env 'HOME'");
return -1;
}
--
2.25.1