kernel: hosted: print pid of a process that exited

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-10-30 10:14:02 +08:00
parent 39c9ef30b7
commit 5f6b42d534

View file

@ -85,13 +85,13 @@ fn handle_connection(
ServerPacketWithData([usize; 9], Vec<u8>), ServerPacketWithData([usize; 9], Vec<u8>),
} }
fn conn_thread(mut conn: TcpStream, sender: Sender<ServerMessage>) { fn conn_thread(mut conn: TcpStream, sender: Sender<ServerMessage>, pid: PID) {
loop { loop {
let mut raw_data = [0u8; 9 * std::mem::size_of::<usize>()]; let mut raw_data = [0u8; 9 * std::mem::size_of::<usize>()];
if let Err(_e) = conn.read_exact(&mut raw_data) { if let Err(e) = conn.read_exact(&mut raw_data) {
println!( println!(
"KERNEL(?): Client disconnected: {} ({:?}). Shutting down virtual process.", "KERNEL({}): client disconnected: {} -- shutting down virtual process",
_e, _e pid, e
); );
sender.send(ServerMessage::Exit).ok(); sender.send(ServerMessage::Exit).ok();
return; return;
@ -140,7 +140,7 @@ fn handle_connection(
std::thread::Builder::new() std::thread::Builder::new()
.name(format!("PID {}: client connection thread", pid)) .name(format!("PID {}: client connection thread", pid))
.spawn(move || { .spawn(move || {
conn_thread(conn, conn_sender); conn_thread(conn, conn_sender, pid);
}) })
.unwrap(); .unwrap();