ssh_terminal: close terminal fd in pthread context

Issue #3682
This commit is contained in:
Alexander Boettcher 2020-11-27 14:12:27 +01:00 committed by Norman Feske
parent 3fac8b106d
commit b6408cec1c

View File

@ -374,20 +374,13 @@ void Ssh::Server::detach_terminal(Ssh::Terminal &conn)
Genode::error("could not detach Terminal for user ", conn.user()); Genode::error("could not detach Terminal for user ", conn.user());
return; return;
} }
auto invalidate_terminal = [&] (Session &sess) {
Libc::with_libc([&] () { auto invalidate_terminal = [&] (Session &sess) {
if (sess.terminal != &conn) { return; } if (sess.terminal != &conn) { return; }
sess.terminal = nullptr; sess.terminal_detached = true;
sess.terminal_detached = true;
});
}; };
_sessions.for_each(invalidate_terminal); _sessions.for_each(invalidate_terminal);
Libc::with_libc([&] () {
Genode::destroy(&_heap, p);
});
_wake_loop(); _wake_loop();
} }
@ -599,6 +592,20 @@ void Ssh::Server::loop()
/* first remove all stale sessions */ /* first remove all stale sessions */
auto cleanup = [&] (Session &s) { 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 if (!s.terminal_detached
&& ssh_is_connected(s.session)) { return ; } && ssh_is_connected(s.session)) { return ; }
_cleanup_session(s); _cleanup_session(s);