Stop the terminal emulator when the shell exits

This commit is contained in:
pjht 2024-11-20 14:01:08 -06:00
parent 964ca333b6
commit c22f840b55
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
3 changed files with 64 additions and 17 deletions

39
Cargo.lock generated
View File

@ -46,9 +46,9 @@ checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15"
[[package]]
name = "critical-section"
version = "1.1.3"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f64009896348fc5af4222e9cf7d7d82a95a256c634ebcf61c53e4ea461422242"
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
[[package]]
name = "embedded-io"
@ -100,15 +100,16 @@ name = "init_phase2"
version = "0.1.0"
dependencies = [
"file_rpc",
"proc_man_rpc",
"syslog_msg_ipc",
"syslog_rpc",
]
[[package]]
name = "libc"
version = "0.2.159"
version = "0.2.164"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"
[[package]]
name = "lock_api"
@ -170,13 +171,29 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.86"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "proc_man_rpc"
version = "0.1.0"
dependencies = [
"parking_lot",
"postcard",
"proc_man_structs",
]
[[package]]
name = "proc_man_structs"
version = "0.1.0"
dependencies = [
"serde",
]
[[package]]
name = "quote"
version = "1.0.37"
@ -229,7 +246,7 @@ version = "1.0.210"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.79",
"syn 2.0.87",
]
[[package]]
@ -266,9 +283,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.79"
version = "2.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d"
dependencies = [
"proc-macro2",
"quote",
@ -302,9 +319,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
version = "1.0.13"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "windows-targets"

View File

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
file_rpc = { version = "0.1.0", path = "../file_rpc" }
proc_man_rpc = { version = "0.1.0", path = "../proc_man/proc_man_rpc" }
syslog_msg_ipc = { version = "0.1.0", path = "../syslog/syslog_msg_ipc" }
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }

View File

@ -48,6 +48,14 @@ fn main() {
};
let syslog_client = syslog_rpc::Client::new(syslog_pid);
syslog_client.subscribe_to_binary("devfs".to_string(), vec![1]);
let proc_man_pid = loop {
if let Some(pid) = syscalls::try_get_registered(3) {
break pid;
}
};
let proc_man_client = proc_man_rpc::Client::new(proc_man_pid);
Command::new("/bin/ps2").spawn().unwrap();
Command::new("/bin/pty_server").spawn().unwrap();
@ -63,15 +71,21 @@ fn main() {
let pts = File::open("/dev/pts0").unwrap();
match Command::new("/bin/psh")
let shell = match Command::new("/bin/psh")
.stdin(pts.try_clone().unwrap())
.stdout(pts.try_clone().unwrap())
.stderr(pts)
.spawn() {
Ok(_) => (),
Err(e) => writeln!(display, "Unable to start shell (/bin/psh): {}", e).unwrap(),
.spawn()
{
Ok(x) => x,
Err(e) => {
writeln!(display, "Unable to start shell (/bin/psh): {}", e).unwrap();
return;
}
};
let psh_wait = proc_man_client.wait_async(shell.id() as u64);
let mut kbd_buf = [0u8; 512];
let mut pty_buf = [0u8; 512];
@ -81,16 +95,31 @@ fn main() {
let kbd_pid_client = file_rpc::Client::new(kbd_pid);
let pty_pid_client = file_rpc::Client::new(pty_pid);
let mut psh_wait_res;
loop {
let kbd_len = kbd.read(&mut kbd_buf).unwrap();
let pty_len = pty.read(&mut pty_buf).unwrap();
if kbd_len == 0 && pty_len == 0 {
let kbd_poll = kbd_pid_client.poll(kbd_fd, PollEvents::POLLIN);
let pty_poll = pty_pid_client.poll(pty_fd, PollEvents::POLLIN);
PendingPoll::get_list_result(&[kbd_poll, pty_poll]);
loop {
psh_wait_res = psh_wait.try_get_return().unwrap();
if PendingPoll::try_get_list_result(&[kbd_poll, pty_poll]).is_some()
|| psh_wait_res.is_some()
{
break;
}
ipc::process_messages();
}
if psh_wait_res.is_some() {
break;
}
continue;
}
pty.write_all(&kbd_buf[..kbd_len]).unwrap();
display.write_all(&pty_buf[..pty_len]).unwrap();
}
writeln!(display, "\nShell exited with code {}", psh_wait_res.unwrap().exit_code).unwrap();
}