From b6408cec1c28370396853d4447c86596dfe1a965 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Fri, 27 Nov 2020 14:12:27 +0100 Subject: [PATCH] ssh_terminal: close terminal fd in pthread context Issue #3682 --- repos/gems/src/server/ssh_terminal/server.cc | 27 ++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/repos/gems/src/server/ssh_terminal/server.cc b/repos/gems/src/server/ssh_terminal/server.cc index 4ca61373da..49eff03210 100644 --- a/repos/gems/src/server/ssh_terminal/server.cc +++ b/repos/gems/src/server/ssh_terminal/server.cc @@ -374,20 +374,13 @@ void Ssh::Server::detach_terminal(Ssh::Terminal &conn) Genode::error("could not detach Terminal for user ", conn.user()); return; } - auto invalidate_terminal = [&] (Session &sess) { - Libc::with_libc([&] () { - if (sess.terminal != &conn) { return; } - sess.terminal = nullptr; - sess.terminal_detached = true; - }); + auto invalidate_terminal = [&] (Session &sess) { + if (sess.terminal != &conn) { return; } + sess.terminal_detached = true; }; _sessions.for_each(invalidate_terminal); - Libc::with_libc([&] () { - Genode::destroy(&_heap, p); - }); - _wake_loop(); } @@ -599,6 +592,20 @@ void Ssh::Server::loop() /* first remove all stale sessions */ auto cleanup = [&] (Session &s) { + if (s.terminal_detached) { + Terminal_session *p = nullptr; + auto lookup = [&] (Terminal_session &t) { + if (&t.conn == s.terminal) { + p = &t; + s.terminal = nullptr; + } + }; + _terminals.for_each(lookup); + + if (p) + Genode::destroy(&_heap, p); + } + if (!s.terminal_detached && ssh_is_connected(s.session)) { return ; } _cleanup_session(s);