summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-06 13:27:25 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-06 13:30:11 +0200
commit6f059ee83056098652f3acb4f43c13cd898b3d0a (patch)
tree9fb38d2912aca53d172099da46f43d5ee6490a3e
parenta122a544da0f05263cfb8fe7841325ef58364bb8 (diff)
downloadserenity-6f059ee83056098652f3acb4f43c13cd898b3d0a.zip
ProtocolServer: Turn this into a multi-instance service
Everyone who connects to ProtocolServer now gets his own instance. This means that different users can no longer talk to the same exact ProtocolServer process, enhanching security and stability.
-rw-r--r--Base/etc/SystemServer.ini4
-rw-r--r--Services/ProtocolServer/ClientConnection.cpp2
-rw-r--r--Services/ProtocolServer/main.cpp17
3 files changed, 8 insertions, 15 deletions
diff --git a/Base/etc/SystemServer.ini b/Base/etc/SystemServer.ini
index 329cd9b4ef..5af26951f8 100644
--- a/Base/etc/SystemServer.ini
+++ b/Base/etc/SystemServer.ini
@@ -2,10 +2,10 @@
Socket=/tmp/portal/protocol
SocketPermissions=660
Lazy=1
-Priority=low
-KeepAlive=1
User=protocol
BootModes=text,graphical
+MultiInstance=1
+AcceptSocketConnections=1
[WebContent]
Socket=/tmp/portal/webcontent
diff --git a/Services/ProtocolServer/ClientConnection.cpp b/Services/ProtocolServer/ClientConnection.cpp
index 2b72ef0025..cbe21dd1ef 100644
--- a/Services/ProtocolServer/ClientConnection.cpp
+++ b/Services/ProtocolServer/ClientConnection.cpp
@@ -48,6 +48,8 @@ ClientConnection::~ClientConnection()
void ClientConnection::die()
{
s_connections.remove(client_id());
+ if (s_connections.is_empty())
+ Core::EventLoop::current().quit(0);
}
OwnPtr<Messages::ProtocolServer::IsSupportedProtocolResponse> ClientConnection::handle(const Messages::ProtocolServer::IsSupportedProtocol& message)
diff --git a/Services/ProtocolServer/main.cpp b/Services/ProtocolServer/main.cpp
index 37dcb2d80c..8b26df2c73 100644
--- a/Services/ProtocolServer/main.cpp
+++ b/Services/ProtocolServer/main.cpp
@@ -56,18 +56,9 @@ int main(int, char**)
(void)*new ProtocolServer::GeminiProtocol;
(void)*new ProtocolServer::HttpProtocol;
(void)*new ProtocolServer::HttpsProtocol;
- auto server = Core::LocalServer::construct();
- bool ok = server->take_over_from_system_server();
- ASSERT(ok);
- server->on_ready_to_accept = [&] {
- auto client_socket = server->accept();
- if (!client_socket) {
- dbg() << "ProtocolServer: accept failed.";
- return;
- }
- static int s_next_client_id = 0;
- int client_id = ++s_next_client_id;
- IPC::new_client_connection<ProtocolServer::ClientConnection>(*client_socket, client_id);
- };
+
+ auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
+ ASSERT(socket);
+ IPC::new_client_connection<ProtocolServer::ClientConnection>(socket.release_nonnull(), 1);
return event_loop.exec();
}