Support cmdline_args when sys_exec.
This commit is contained in:
parent
c43ec12175
commit
c8d851fc2b
16 changed files with 132 additions and 24 deletions
|
@ -12,6 +12,7 @@ const DL: u8 = 0x7fu8;
|
|||
const BS: u8 = 0x08u8;
|
||||
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use user_lib::{fork, exec, waitpid};
|
||||
use user_lib::console::getchar;
|
||||
|
||||
|
@ -26,11 +27,29 @@ pub fn main() -> i32 {
|
|||
LF | CR => {
|
||||
println!("");
|
||||
if !line.is_empty() {
|
||||
line.push('\0');
|
||||
let args: Vec<_> = line.as_str().split(' ').collect();
|
||||
let mut args_copy: Vec<String> = args
|
||||
.iter()
|
||||
.map(|&arg| {
|
||||
let mut string = String::new();
|
||||
string.push_str(arg);
|
||||
string
|
||||
})
|
||||
.collect();
|
||||
args_copy
|
||||
.iter_mut()
|
||||
.for_each(|string| {
|
||||
string.push('\0');
|
||||
});
|
||||
let mut args_addr: Vec<*const u8> = args_copy
|
||||
.iter()
|
||||
.map(|arg| arg.as_ptr())
|
||||
.collect();
|
||||
args_addr.push(0 as *const u8);
|
||||
let pid = fork();
|
||||
if pid == 0 {
|
||||
// child process
|
||||
if exec(line.as_str()) == -1 {
|
||||
if exec(args_copy[0].as_str(), args_addr.as_slice()) == -1 {
|
||||
println!("Error when executing!");
|
||||
return -4;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue