(current_directory: &Path, path: &Path, args: Vec<&str>)
| 14 | syscalls::{self, SyscallError, VFS}}; |
| 15 | |
| 16 | fn exec_path(current_directory: &Path, path: &Path, args: Vec<&str>) -> Result<(), SyscallError> { |
| 17 | // Read binary from file |
| 18 | let bin = { |
| 19 | let mut bin: Vec<u8> = Vec::new(); |
| 20 | let mut file = File::open(path)?; |
| 21 | file.read_to_end(&mut bin)?; |
| 22 | bin |
| 23 | }; |
| 24 | |
| 25 | // Create a communication handle for the input |
| 26 | let (exe_input, exe_input2) = syscalls::new_rendezvous()?; |
| 27 | |
| 28 | // Make an environment with the working directory |
| 29 | let mut env_string = String::from("PWD="); |
| 30 | env_string.push_str(current_directory |
| 31 | .as_os_str().to_str().unwrap()); |
| 32 | |
| 33 | syscalls::exec( |
| 34 | &bin, |
| 35 | 0, // Permission flags |
| 36 | exe_input2, |
| 37 | syscalls::STDOUT.clone(), |
| 38 | VFS::shared(), |
| 39 | args, |
| 40 | &env_string |
| 41 | )?; |
| 42 | |
| 43 | loop { |
| 44 | // Wait for keyboard input |
| 45 | match syscalls::receive(&syscalls::STDIN) { |
| 46 | Ok(syscalls::Message::Short( |
| 47 | message::CHAR, ch, _)) => { |
| 48 | // Received a character |
| 49 | if let Err((err, _)) = syscalls::send(&exe_input, |
| 50 | syscalls::Message::Short( |
| 51 | message::CHAR, ch, 0)) { |
| 52 | println!("Received error: {}", err); |
| 53 | return Ok(()); |
| 54 | } |
| 55 | }, |
| 56 | _ => { |
| 57 | // Ignore |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | fn help() { |
| 64 | println!( |
no test coverage detected