Skip to content

Commit

Permalink
修复exec时未关闭raw模式的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
MemoryShore committed Aug 23, 2024
1 parent 92aabeb commit 69d798d
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions src/shell/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ impl Shell {
return Err(CommandError::NotFile(real_path.clone()));
}

// let name = &real_path[real_path.rfind('/').map(|pos| pos + 1).unwrap_or(0)..];
// *args.get_mut(0).unwrap() = name.to_string();
let mut args = args.split_first().unwrap().1;
let run_backend = if let Some(last) = args.last() {
if last == "&" {
Expand All @@ -307,6 +305,8 @@ impl Shell {
false
};

crossterm::terminal::disable_raw_mode().expect("failed to disable raw mode");

let mut child = std::process::Command::new(real_path)
.args(args)
.current_dir(Env::current_dir())
Expand All @@ -320,36 +320,7 @@ impl Shell {
self.add_backend_task(child);
}

// let pid: libc::pid_t = unsafe {
// libc::syscall(libc::SYS_fork, 0, 0, 0, 0, 0, 0)
// .try_into()
// .unwrap()
// };

// let mut retval = 0;
// if pid == 0 {
// let path_cstr = std::ffi::CString::new(real_path).unwrap();
// let args_cstr = args
// .iter()
// .map(|str| std::ffi::CString::new(str.as_str()).unwrap())
// .collect::<Vec<std::ffi::CString>>();
// let mut args_ptr = args_cstr
// .iter()
// .map(|c_str| c_str.as_ptr())
// .collect::<Vec<*const i8>>();
// args_ptr.push(std::ptr::null());
// let argv = args_ptr.as_ptr();

// unsafe {
// libc::execv(path_cstr.as_ptr(), argv);
// }
// } else {
// if args.last().unwrap() != &"&" {
// unsafe { libc::waitpid(pid, &mut retval as *mut i32, 0) };
// } else {
// println!("[1] {}", pid);
// }
// }
crossterm::terminal::enable_raw_mode().expect("failed to enable raw mode");
return Ok(());
}

Expand Down

0 comments on commit 69d798d

Please sign in to comment.