From 1090f03b3429bc1f7b08dc5751d46d90a4c9fc5a Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Wed, 26 Jul 2023 10:03:27 +0800 Subject: [PATCH] Use kcmdline to specify init instead of hardcoding --- services/libs/jinux-std/src/lib.rs | 37 +++++++++--------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/services/libs/jinux-std/src/lib.rs b/services/libs/jinux-std/src/lib.rs index 370dc7747..91489c42d 100644 --- a/services/libs/jinux-std/src/lib.rs +++ b/services/libs/jinux-std/src/lib.rs @@ -25,6 +25,7 @@ use crate::{ process::status::ProcessStatus, thread::{kernel_thread::KernelThreadExt, Thread}, }; +use alloc::sync::Arc; use jinux_frame::{boot, exit_qemu}; use process::Process; @@ -75,11 +76,18 @@ fn init_thread() { ); print_banner(); - let busybox = run_busybox().expect("run busybox fails"); + + let karg = boot::kernel_cmdline(); + + let initproc = Process::spawn_user_process( + karg.get_initproc_path().unwrap(), + karg.get_initproc_argv().unwrap().to_vec(), + karg.get_initproc_envp().unwrap().to_vec(), + ).expect("Run init process failed."); loop { - // If busybox becomes zombie, then exit qemu. - if *busybox.status().lock() == ProcessStatus::Zombie { + // If initproc becomes zombie, then exit qemu. + if *initproc.status().lock() == ProcessStatus::Zombie { println!("Exit jinux."); exit_qemu(jinux_frame::QemuExitCode::Success); } @@ -96,29 +104,6 @@ pub fn run_first_process() -> ! { unreachable!() } -fn run_busybox() -> Result> { - let executable_path = "/usr/bin/busybox"; - let argv = ["sh", "-l"]; - let envp = [ - "SHELL=/bin/sh", - "LOGNAME=root", - "HOME=/", - "USER=root", - "PATH=/bin", - ]; - let argv = argv - .into_iter() - .map(|arg| CString::new(arg).unwrap()) - .collect(); - let envp = envp - .into_iter() - .map(|env| CString::new(env).unwrap()) - .collect(); - println!(""); - println!("BusyBox v1.35.0 built-in shell (ash)\n"); - Process::spawn_user_process(executable_path, argv, envp) -} - fn print_banner() { println!("\x1B[36m"); println!(