mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
rustjail: fix the issue of missing default home env
first get the "HOME" env from "/etc/passwd", if there's no corresponding uid entry in /etc/passwd, then set "/" as the home env. Fixes: #1643 Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
This commit is contained in:
parent
0b87fd436f
commit
a938d90310
@ -634,12 +634,12 @@ fn do_init_child(cwfd: RawFd) -> Result<()> {
|
||||
env::set_var(v[0], v[1]);
|
||||
}
|
||||
|
||||
// set the "HOME" env getting from "/etc/passwd"
|
||||
// set the "HOME" env getting from "/etc/passwd", if
|
||||
// there's no uid entry in /etc/passwd, set "/" as the
|
||||
// home env.
|
||||
if env::var_os(HOME_ENV_KEY).is_none() {
|
||||
match utils::home_dir(guser.uid) {
|
||||
Ok(home_dir) => env::set_var(HOME_ENV_KEY, home_dir),
|
||||
Err(e) => log_child!(cfd_log, "failed to get home dir: {:?}", e),
|
||||
}
|
||||
let home_dir = utils::home_dir(guser.uid).unwrap_or_else(|_| String::from("/"));
|
||||
env::set_var(HOME_ENV_KEY, home_dir);
|
||||
}
|
||||
|
||||
let exec_file = Path::new(&args[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user