增加logo以及bug修复

main
阳光少年 1 year ago
parent e3888c4996
commit ec7af3ee22

@ -27,7 +27,15 @@ static mut STACK: [u8; 1024*1024*1] = [0; 1024*1024*1];
static CLONE_FLAG: i32 = 0b1101100000000100000000000000000; // CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWPID | CLONE_NEWIPC | CLONE_NEWNET;
static START_T: OnceLock<time::Instant> = OnceLock::new();
static CONTAINER_INFO: OnceLock<ContainerInfo> = OnceLock::new();
static LOGO: &str = r#"
____ __
/\ _`\ /\ \
\ \ \L\ \ ___ ___\ \ \/'\ __ _ __
\ \ , / / __`\ /'___\ \ , < /'__`\/\`'__\
\ \ \\ \ /\ \L\ \/\ \__/\ \ \\`\ /\ __/\ \ \/
\ \_\ \_\ \____/\ \____\\ \_\ \_\ \____\\ \_\
\/_/\/ /\/___/ \/____/ \/_/\/_/\/____/ \/_/
"#;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
@ -237,7 +245,7 @@ fn init_container_pivot<P: AsRef<Path>>(merged_path: P) -> Result<()> {
std::env::set_current_dir("/")?;
// 卸载 old_root, 并删除临时文件
umount2(".pivot_root", MntFlags::MNT_FORCE).unwrap();
umount2(".pivot_root", MntFlags::MNT_DETACH).unwrap();
std::fs::remove_dir(".pivot_root").unwrap();
Ok(())
}
@ -421,7 +429,9 @@ fn run_container(container_info: &ContainerInfo, is_exec_cmd: Option<&String>) -
init_container_custom_volume(&container_merged_path, &container_info.volume).unwrap();
}
sethostname(USER_NAME).unwrap();
if container_info.env.len() > 0 {
init_container_env(&container_info.env).unwrap();
}
init_container_pivot(&container_merged_path).unwrap();
init_container_mount().unwrap();
init_container_log(container_info.log).unwrap();
@ -594,14 +604,14 @@ fn stop_container(containers_id: &str, is_remove: bool) -> Result<()> {
}
})
.for_each(|s| {
match umount2(s.as_str(), MntFlags::MNT_FORCE) {
match umount2(s.as_str(), MntFlags::MNT_DETACH) {
Ok(_) => println!("卸载自定卷{s}"),
Err(e) => println!("卸载卷{s}失败: {e:?}"),
}
});
}
// 卸载overlayfs
match umount2(container_merged_path.to_str().unwrap(), MntFlags::MNT_FORCE) {
match umount2(container_merged_path.to_str().unwrap(), MntFlags::MNT_DETACH) {
Ok(_) => println!("卸载overlayfs卷: {container_merged_path:?}"),
Err(e) => println!("卸载overlayfs失败: {e:?}"),
}
@ -615,11 +625,11 @@ fn stop_container(containers_id: &str, is_remove: bool) -> Result<()> {
}
}
} else {
println!("容器不存在: {container_id}, 尝试删除");
println!("容器不存在: {container_id}, 强制删除");
// todo 需要强制删除一下目录
match fs::remove_dir_all(container_work_path) {
Ok(_) => println!("删除容器 {container_id} 成功"),
Err(e) => println!("删除容器失败: {e:?}"),
match fs::remove_dir_all(&container_work_path) {
Ok(_) => println!("强制删除 {container_work_path:?} 成功"),
Err(e) => println!("强制删除失败: {e:?}"),
}
}
@ -631,6 +641,7 @@ fn stop_container(containers_id: &str, is_remove: bool) -> Result<()> {
fn main() -> Result<()>{
println!("{LOGO}");
START_T.get_or_init(|| {
time::Instant::now()
});

Loading…
Cancel
Save