修改shell执行exec时传参错误问题 (#399)

* 修改shell执行exec时传参错误问题
This commit is contained in:
GnoCiYeH 2023-10-09 01:10:14 +08:00 committed by GitHub
parent b7b843bedd
commit 865f4ba4cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -197,6 +197,7 @@ pub fn load_binary_file(param: &mut ExecParam) -> Result<BinaryLoaderResult, Sys
/// 程序初始化信息,这些信息会被压入用户栈中
#[derive(Debug)]
pub struct ProcInitInfo {
pub proc_name: String,
pub args: Vec<String>,
pub envs: Vec<String>,
pub auxv: BTreeMap<u8, usize>,
@ -205,6 +206,7 @@ pub struct ProcInitInfo {
impl ProcInitInfo {
pub fn new() -> Self {
Self {
proc_name: String::new(),
args: Vec::new(),
envs: Vec::new(),
auxv: BTreeMap::new(),
@ -222,7 +224,7 @@ impl ProcInitInfo {
ustack: &mut UserStack,
) -> Result<(VirtAddr, VirtAddr), SystemError> {
// 先把程序的名称压入栈中
self.push_str(ustack, self.args[0].as_str())?;
self.push_str(ustack, &self.proc_name)?;
// 然后把环境变量压入栈中
let envps = self

View File

@ -630,8 +630,8 @@ impl ProcessControlBlock {
}
/// 生成进程的名字
pub fn generate_name(_program_path: &str, args: &Vec<String>) -> String {
let mut name = "".to_string();
pub fn generate_name(program_path: &str, args: &Vec<String>) -> String {
let mut name = program_path.to_string();
for arg in args {
name.push_str(arg);
name.push(' ');

View File

@ -508,7 +508,12 @@ int shell_cmd_exec(int argc, char **argv)
char *file_path = get_target_filepath(argv[1], &path_len);
// printf("before execv, path=%s, argc=%d\n", file_path, argc);
execv(file_path, argv);
char **real_argv;
if (argc > 2)
{
real_argv = &argv[2];
}
execv(file_path, real_argv);
// printf("after execv, path=%s, argc=%d\n", file_path, argc);
free(argv);
free(file_path);