From ec7af3ee22a895dd07b1271fadd815671a9d8a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=B0=91=E5=B9=B4?= <849317537@qq.com> Date: Sat, 10 Aug 2024 08:43:59 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0logo=E4=BB=A5=E5=8F=8Abug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index aaf7957..6fdc17c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = OnceLock::new(); -static CONTAINER_INFO: OnceLock = 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>(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(); - init_container_env(&container_info.env).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() });