mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 20:24:31 +00:00
rustjail: add the "HOME" env for process
When creating a container process/exec process, it should set the "HOME" env for this process by getting from /etc/passwd. Fixes: #498 Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
This commit is contained in:
parent
5231a3eddf
commit
5c7f0016fb
@ -23,3 +23,4 @@ slog-scope = "4.1.2"
|
||||
scan_fmt = "0.2"
|
||||
regex = "1.1"
|
||||
path-absolutize = "1.2.0"
|
||||
dirs = "3.0.1"
|
||||
|
@ -3,6 +3,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use dirs;
|
||||
use lazy_static;
|
||||
use oci::{Hook, Linux, LinuxNamespace, LinuxResources, POSIXRlimit, Spec};
|
||||
use serde_json;
|
||||
@ -66,6 +67,7 @@ const CRFD_FD: &str = "CRFD_FD";
|
||||
const CWFD_FD: &str = "CWFD_FD";
|
||||
const CLOG_FD: &str = "CLOG_FD";
|
||||
const FIFO_FD: &str = "FIFO_FD";
|
||||
const HOME_ENV_KEY: &str = "HOME";
|
||||
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
pub enum Status {
|
||||
@ -605,6 +607,13 @@ fn do_init_child(cwfd: RawFd) -> Result<()> {
|
||||
env::set_var(v[0], v[1]);
|
||||
}
|
||||
|
||||
// set the "HOME" env getting from "/etc/passwd"
|
||||
if env::var_os(HOME_ENV_KEY).is_none() {
|
||||
if let Some(home_dir) = dirs::home_dir() {
|
||||
env::set_var(HOME_ENV_KEY, home_dir);
|
||||
}
|
||||
}
|
||||
|
||||
let exec_file = Path::new(&args[0]);
|
||||
log_child!(cfd_log, "process command: {:?}", &args);
|
||||
if !exec_file.exists() {
|
||||
|
Loading…
Reference in New Issue
Block a user