LibIPC: Stop exchanging client/server PIDs in greeting handshake

The PIDs were used for sharing shbufs between processes, but now that
we have migrated to file descriptor passing, we no longer need to know
the PID of the other side.
This commit is contained in:
Andreas Kling 2021-01-31 09:24:46 +01:00
parent 50092ea0ca
commit 1b5be4a342
Notes: sideshowbarker 2024-07-18 22:42:46 +09:00
9 changed files with 11 additions and 39 deletions

View file

@ -45,7 +45,6 @@ public:
{
ASSERT(this->socket().is_connected());
this->socket().on_ready_to_read = [this] { this->drain_messages_from_peer(); };
this->initialize_peer_info();
}
virtual ~ClientConnection() override
@ -54,21 +53,18 @@ public:
void did_misbehave()
{
dbgln("{} (id={}, pid={}) misbehaved, disconnecting.", *this, m_client_id, client_pid());
dbgln("{} (id={}) misbehaved, disconnecting.", *this, m_client_id);
this->shutdown();
}
void did_misbehave(const char* message)
{
dbgln("{} (id={}, pid={}) misbehaved ({}), disconnecting.", *this, m_client_id, client_pid(), message);
dbgln("{} (id={}) misbehaved ({}), disconnecting.", *this, m_client_id, message);
this->shutdown();
}
int client_id() const { return m_client_id; }
pid_t client_pid() const { return this->peer_pid(); }
void set_client_pid(pid_t pid) { this->set_peer_pid(pid); }
virtual void die() = 0;
private:

View file

@ -60,8 +60,6 @@ public:
};
}
pid_t peer_pid() const { return m_peer_pid; }
template<typename MessageType>
OwnPtr<MessageType> wait_for_specific_message()
{
@ -141,7 +139,6 @@ public:
protected:
Core::LocalSocket& socket() { return *m_socket; }
void set_peer_pid(pid_t pid) { m_peer_pid = pid; }
template<typename MessageType, typename Endpoint>
OwnPtr<MessageType> wait_for_specific_endpoint_message()
@ -257,17 +254,6 @@ protected:
}
protected:
void initialize_peer_info()
{
ucred creds;
socklen_t creds_size = sizeof(creds);
if (getsockopt(this->socket().fd(), SOL_SOCKET, SO_PEERCRED, &creds, &creds_size) < 0) {
// FIXME: We should handle this more gracefully.
ASSERT_NOT_REACHED();
}
m_peer_pid = creds.pid;
}
LocalEndpoint& m_local_endpoint;
NonnullRefPtr<Core::LocalSocket> m_socket;
RefPtr<Core::Timer> m_responsiveness_timer;
@ -275,7 +261,6 @@ protected:
RefPtr<Core::Notifier> m_notifier;
NonnullOwnPtrVector<Message> m_unprocessed_messages;
ByteBuffer m_unprocessed_bytes;
pid_t m_peer_pid { -1 };
};
}

View file

@ -45,15 +45,10 @@ public:
}
ASSERT(this->socket().is_connected());
this->initialize_peer_info();
}
virtual void handshake() = 0;
pid_t server_pid() const { return this->peer_pid(); }
void set_server_pid(pid_t pid) { this->set_peer_pid(pid); }
void set_my_client_id(int id) { m_my_client_id = id; }
int my_client_id() const { return m_my_client_id; }

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -37,9 +37,8 @@ Client::Client()
void Client::handshake()
{
auto response = send_sync<Messages::ImageDecoderServer::Greet>(getpid());
auto response = send_sync<Messages::ImageDecoderServer::Greet>();
set_my_client_id(response->client_id());
set_server_pid(response->server_pid());
}
void Client::handle(const Messages::ImageDecoderClient::Dummy&)

View file

@ -45,9 +45,8 @@ void WebContentClient::die()
void WebContentClient::handshake()
{
auto response = send_sync<Messages::WebContentServer::Greet>(getpid());
auto response = send_sync<Messages::WebContentServer::Greet>();
set_my_client_id(response->client_id());
set_server_pid(response->server_pid());
}
void WebContentClient::handle(const Messages::WebContentClient::DidPaint& message)

View file

@ -51,10 +51,9 @@ void ClientConnection::die()
exit(0);
}
OwnPtr<Messages::ImageDecoderServer::GreetResponse> ClientConnection::handle(const Messages::ImageDecoderServer::Greet& message)
OwnPtr<Messages::ImageDecoderServer::GreetResponse> ClientConnection::handle(const Messages::ImageDecoderServer::Greet&)
{
set_client_pid(message.client_pid());
return make<Messages::ImageDecoderServer::GreetResponse>(client_id(), getpid());
return make<Messages::ImageDecoderServer::GreetResponse>(client_id());
}
OwnPtr<Messages::ImageDecoderServer::DecodeImageResponse> ClientConnection::handle(const Messages::ImageDecoderServer::DecodeImage& message)

View file

@ -1,6 +1,6 @@
endpoint ImageDecoderServer = 7001
{
Greet(i32 client_pid) => (i32 client_id, i32 server_pid)
Greet() => (i32 client_id)
DecodeImage(Core::AnonymousBuffer data) => (bool is_animated, u32 loop_count, Vector<Gfx::ShareableBitmap> bitmaps, Vector<u32> durations)
}

View file

@ -76,10 +76,9 @@ const Web::Page& ClientConnection::page() const
return m_page_host->page();
}
OwnPtr<Messages::WebContentServer::GreetResponse> ClientConnection::handle(const Messages::WebContentServer::Greet& message)
OwnPtr<Messages::WebContentServer::GreetResponse> ClientConnection::handle(const Messages::WebContentServer::Greet&)
{
set_client_pid(message.client_pid());
return make<Messages::WebContentServer::GreetResponse>(client_id(), getpid());
return make<Messages::WebContentServer::GreetResponse>(client_id());
}
void ClientConnection::handle(const Messages::WebContentServer::UpdateSystemTheme& message)

View file

@ -1,6 +1,6 @@
endpoint WebContentServer = 89
{
Greet(i32 client_pid) => (i32 client_id, i32 server_pid)
Greet() => (i32 client_id)
UpdateSystemTheme(Core::AnonymousBuffer theme_buffer) =|