diff --git a/kernel/libk/src/task/binary/mod.rs b/kernel/libk/src/task/binary/mod.rs index 54f8edf4..9e0a55b8 100644 --- a/kernel/libk/src/task/binary/mod.rs +++ b/kernel/libk/src/task/binary/mod.rs @@ -30,6 +30,7 @@ pub mod elf; pub type LoadedProcess = (Arc, Arc); +#[derive(Debug)] pub struct LoadOptions<'e, P: AsRef> { pub parent: Option>, pub group_id: ProcessGroupId, diff --git a/kernel/libk/src/task/process.rs b/kernel/libk/src/task/process.rs index 5f378387..6af0ce4b 100644 --- a/kernel/libk/src/task/process.rs +++ b/kernel/libk/src/task/process.rs @@ -1,4 +1,5 @@ use core::{ + fmt, sync::atomic::{AtomicU32, AtomicUsize, Ordering}, task::{Context, Poll}, }; @@ -646,6 +647,12 @@ impl Process { } } +impl fmt::Debug for Process { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.id, f) + } +} + impl Drop for Process { fn drop(&mut self) { log::debug!("Drop Process {}", self.id); diff --git a/kernel/src/syscall/imp/sys_process.rs b/kernel/src/syscall/imp/sys_process.rs index 8ea98fb0..2b66749c 100644 --- a/kernel/src/syscall/imp/sys_process.rs +++ b/kernel/src/syscall/imp/sys_process.rs @@ -95,19 +95,6 @@ pub(crate) fn spawn_process(options: &SpawnOptions<'_>) -> Result(|entry| { - // if let &SpawnOption::AttachDebug(fd) = entry { - // let channel = io.files.file(fd)?; - // let channel = channel.as_message_channel()?.clone(); - - // Ok(Some(channel)) - // } else { - // Ok(None) - // } - // })?; // Setup a new process from the file let load_options = LoadOptions { @@ -115,7 +102,7 @@ pub(crate) fn spawn_process(options: &SpawnOptions<'_>) -> Result) -> Result Option { diff --git a/userspace/tools/shell/src/main.rs b/userspace/tools/shell/src/main.rs index 7ef24bbf..856bc2f5 100644 --- a/userspace/tools/shell/src/main.rs +++ b/userspace/tools/shell/src/main.rs @@ -127,25 +127,32 @@ fn run(mut input: ShellInput, env: &Env) -> Result<(), Error> { } } -fn open_script>(arg: P) -> io::Result { +fn find_script>(arg: &P) -> &Path { #[cfg(any(target_os = "yggdrasil", rust_analyzer))] { let from_auxv = std::os::yggdrasil::real_binary_path(); if from_auxv.exists() { - return File::open(from_auxv); + return from_auxv; } } - File::open(arg) + arg.as_ref() } -fn run_wrapper(args: ShellArgs, env: &Env) -> Result<(), Error> { +fn run_wrapper(args: ShellArgs, env: &mut Env) -> Result<(), Error> { match args.script { Some(script) => { - let script = BufReader::new(open_script(&script)?); + let script_path = find_script(&script); + let script_path_str = script_path.to_str().unwrap(); + env.put_var("0", script_path_str.into()); + let script = BufReader::new(File::open(script_path)?); run(ShellInput::File(script), env) } - None => run(ShellInput::Interactive, env), + None => { + let shell_name = std::env::args().next().unwrap(); + env.put_var("0", shell_name.into()); + run(ShellInput::Interactive, env) + } } } @@ -156,7 +163,7 @@ fn main() -> ExitCode { let args = ShellArgs::parse(); let mut env = Env::new(); - env.setup_builtin(); + env.setup_builtin(&args.args); builtin::register_default(); if args.login { @@ -171,7 +178,7 @@ fn main() -> ExitCode { } } - match run_wrapper(args, &env) { + match run_wrapper(args, &mut env) { Ok(()) => ExitCode::SUCCESS, Err(error) => { eprintln!("{error}"); diff --git a/userspace/tools/shell/src/syntax/lex.rs b/userspace/tools/shell/src/syntax/lex.rs index 77bf537f..05a657c6 100644 --- a/userspace/tools/shell/src/syntax/lex.rs +++ b/userspace/tools/shell/src/syntax/lex.rs @@ -138,7 +138,7 @@ impl FromStr for Keyword { } fn lex_identifier(i: &str) -> IResult<&str, &str> { - recognize(many1_count(alt((alphanumeric1, is_a("-_")))))(i) + recognize(many1_count(alt((alphanumeric1, is_a("-_@?*")))))(i) } fn lex_filename(i: &str) -> IResult<&str, &str> { recognize(many1_count(alt((alphanumeric1, is_a("./-_:+,")))))(i) diff --git a/xtask/src/build/userspace.rs b/xtask/src/build/userspace.rs index f98561a1..657e1d15 100644 --- a/xtask/src/build/userspace.rs +++ b/xtask/src/build/userspace.rs @@ -128,6 +128,20 @@ fn build_rootfs, D: AsRef>( util::copy_file(src_path, dst_path)?; } + if let Ok(read_dir) = fs::read_dir("userspace/scripts") { + for entry in read_dir { + let Ok(entry) = entry else { + continue; + }; + let path = entry.path(); + let Some(filename) = path.file_name() else { + continue; + }; + + fs::copy(&path, rootfs_dir.join("bin").join(filename))?; + } + } + // TODO this is a temporary hack fs::create_dir_all(rootfs_dir.join("lib"))?; // TODO other architectures