ssh_terminal: use Mutex

Isse #3803
This commit is contained in:
Alexander Boettcher 2020-07-06 11:42:52 +02:00 committed by Norman Feske
parent 1609d8a92f
commit 377c6ed0ce
7 changed files with 28 additions and 28 deletions

View File

@ -109,7 +109,7 @@ struct Ssh::Login : Genode::Registry<Ssh::Login>::Element
struct Ssh::Login_registry : Genode::Registry<Ssh::Login>
{
Genode::Allocator &_alloc;
Genode::Lock _lock { };
Genode::Mutex _mutex { };
/**
* Import one login from node
@ -153,9 +153,9 @@ struct Ssh::Login_registry : Genode::Registry<Ssh::Login>
Login_registry(Genode::Allocator &alloc) : _alloc(alloc) { }
/**
* Return registry lock
* Return registry mutex
*/
Genode::Lock &lock() { return _lock; }
Genode::Mutex &mutex() { return _mutex; }
/**
* Import all login information from config

View File

@ -56,7 +56,7 @@ class Terminal::Root_component : public Genode::Root_component<Session_component
if (!_config_rom.valid()) { return; }
{
Genode::Lock::Guard g(_logins.lock());
Genode::Mutex::Guard guard(_logins.mutex());
_logins.import(_config_rom.xml());
}

View File

@ -234,7 +234,7 @@ void Ssh::Server::_parse_config(Genode::Xml_node const &config)
_log_level = config.attribute_value("debug", 0u);
_log_logins = config.attribute_value("log_logins", true);
Genode::Lock::Guard g(_logins.lock());
Genode::Mutex::Guard guard(_logins.mutex());
auto print = [&] (Login const &login) {
Genode::log("Login configured: ", login);
};
@ -330,7 +330,7 @@ void Ssh::Server::_log_login(User const &user, Session const &s, bool pubkey)
void Ssh::Server::attach_terminal(Ssh::Terminal &conn)
{
Genode::Lock::Guard g(_terminals.lock());
Genode::Mutex::Guard guard(_terminals.mutex());
try {
new (&_heap) Terminal_session(_terminals,
@ -358,7 +358,7 @@ void Ssh::Server::attach_terminal(Ssh::Terminal &conn)
void Ssh::Server::detach_terminal(Ssh::Terminal &conn)
{
Genode::Lock::Guard g(_terminals.lock());
Genode::Mutex::Guard guard(_terminals.mutex());
Terminal_session *p = nullptr;
auto lookup = [&] (Terminal_session &t) {
@ -390,7 +390,7 @@ void Ssh::Server::detach_terminal(Ssh::Terminal &conn)
void Ssh::Server::update_config(Genode::Xml_node const &config)
{
Genode::Lock::Guard g(_terminals.lock());
Genode::Mutex::Guard guard(_terminals.mutex());
_parse_config(config);
ssh_bind_options_set(_ssh_bind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &_log_level);
@ -422,7 +422,7 @@ Ssh::Session *Ssh::Server::lookup_session(ssh_session s)
bool Ssh::Server::request_terminal(Session &session,
const char* command)
{
Genode::Lock::Guard g(_logins.lock());
Genode::Mutex::Guard guard(_logins.mutex());
Login const *l = _logins.lookup(session.user().string());
if (!l || !l->request_terminal) {
return false;
@ -502,7 +502,7 @@ bool Ssh::Server::auth_password(ssh_session s, char const *u, char const *pass)
* Even if there is no valid login for the user, let
* the client try anyway and check multi login afterwards.
*/
Genode::Lock::Guard g(_logins.lock());
Genode::Mutex::Guard guard(_logins.mutex());
Login const *l = _logins.lookup(u);
if (l && l->user == u && l->password == pass) {
if (_allow_multi_login(s, *l)) {
@ -563,7 +563,7 @@ bool Ssh::Server::auth_pubkey(ssh_session s, char const *u,
* matches allow authentication to proceed.
*/
if (signature_state == SSH_PUBLICKEY_STATE_VALID) {
Genode::Lock::Guard g(_logins.lock());
Genode::Mutex::Guard guard(_logins.mutex());
Login const *l = _logins.lookup(u);
if (l && !ssh_key_cmp(pubkey, l->pub_key,
SSH_KEY_CMP_PUBLIC)) {
@ -591,7 +591,7 @@ void Ssh::Server::loop()
}
{
Genode::Lock::Guard g(_terminals.lock());
Genode::Mutex::Guard guard(_terminals.mutex());
/* first remove all stale sessions */
auto cleanup = [&] (Session &s) {

View File

@ -60,10 +60,10 @@ struct Ssh::Session : Genode::Registry<Session>::Element
Ssh::Terminal *terminal { nullptr };
Genode::Lock _access_lock { };
Genode::Lock &lock_terminal()
Genode::Mutex _access_mutex { };
Genode::Mutex &mutex_terminal()
{
return _access_lock;
return _access_mutex;
}
bool spawn_terminal { false };
@ -110,8 +110,8 @@ struct Ssh::Terminal_session : Genode::Registry<Terminal_session>::Element
struct Ssh::Terminal_registry : Genode::Registry<Terminal_session>
{
Genode::Lock _lock { };
Genode::Lock &lock() { return _lock; }
Genode::Mutex _mutex { };
Genode::Mutex &mutex() { return _mutex; }
};

View File

@ -36,7 +36,7 @@ int channel_data_cb(ssh_session session, ssh_channel channel,
void *userdata)
{
using Genode::error;
using Genode::Lock;
using Genode::Mutex;
if (len == 0) {
return 0;
@ -60,7 +60,7 @@ int channel_data_cb(ssh_session session, ssh_channel channel,
}
Ssh::Terminal &conn { *p->terminal };
Lock::Guard guard { conn.read_buf.lock() };
Mutex::Guard guard { conn.read_buf.mutex() };
char const *src { reinterpret_cast<char const*>(data) };
size_t num_bytes { 0 };

View File

@ -159,7 +159,7 @@ class Ssh::Terminal
*/
void send(ssh_channel channel)
{
Lock::Guard g(_write_buf.lock());
Mutex::Guard guard(_write_buf.mutex());
if (!_write_buf.read_avail()) { return; }
@ -192,7 +192,7 @@ class Ssh::Terminal
*/
size_t read(char *dst, size_t dst_len)
{
Genode::Lock::Guard g(read_buf.lock());
Mutex::Guard guard(read_buf.mutex());
size_t const num_bytes = min(dst_len, read_buf.read_avail());
Genode::memcpy(dst, read_buf.content(), num_bytes);
@ -214,7 +214,7 @@ class Ssh::Terminal
*/
size_t write(char const *src, Genode::size_t src_len)
{
Lock::Guard g(_write_buf.lock());
Mutex::Guard g(_write_buf.mutex());
size_t num_bytes = 0;
size_t i = 0;
@ -247,7 +247,7 @@ class Ssh::Terminal
*/
bool read_buffer_empty()
{
Genode::Lock::Guard g(read_buf.lock());
Mutex::Guard guard(read_buf.mutex());
return !read_buf.read_avail();
}
};

View File

@ -42,10 +42,10 @@ namespace Util
template <size_t C>
struct Util::Buffer
{
Genode::Lock _lock { };
char _data[C] { };
size_t _head { 0 };
size_t _tail { 0 };
Genode::Mutex _mutex { };
char _data[C] { };
size_t _head { 0 };
size_t _tail { 0 };
size_t read_avail() const { return _head > _tail ? _head - _tail : 0; }
size_t write_avail() const { return _head <= C ? C - _head : 0; }
@ -55,7 +55,7 @@ struct Util::Buffer
void consume(size_t n) { _tail += n; }
void reset() { _head = _tail = 0; }
Genode::Lock &lock() { return _lock; }
Genode::Mutex &mutex() { return _mutex; }
};
#endif /* _SSH_TERMINAL_UTIL_H_ */