mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
Services: Add InspectorServer to reverse the direction of Inspector
This service daemon will act as an intermediary between the Inspector program and the inspectable programs it wants to inspect. Programs can make themselves available for inspection by connecting to /tmp/portal/inspectables using the Core::EventLoop RPC protocol.
This commit is contained in:
parent
3c3b384c80
commit
3d3a5b431f
11 changed files with 332 additions and 0 deletions
57
Userland/Services/InspectorServer/main.cpp
Normal file
57
Userland/Services/InspectorServer/main.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "InspectableProcess.h"
|
||||
#include <InspectorServer/ClientConnection.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/LocalServer.h>
|
||||
#include <LibIPC/ClientConnection.h>
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
Core::EventLoop event_loop(Core::EventLoop::MakeInspectable::No);
|
||||
auto server = Core::LocalServer::construct();
|
||||
|
||||
if (pledge("stdio unix accept", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool ok = server->take_over_from_system_server("/tmp/portal/inspector");
|
||||
VERIFY(ok);
|
||||
server->on_ready_to_accept = [&] {
|
||||
auto client_socket = server->accept();
|
||||
if (!client_socket) {
|
||||
dbgln("accept failed.");
|
||||
return;
|
||||
}
|
||||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
IPC::new_client_connection<InspectorServer::ClientConnection>(client_socket.release_nonnull(), client_id);
|
||||
};
|
||||
|
||||
auto inspectables_server = Core::LocalServer::construct();
|
||||
if (!inspectables_server->take_over_from_system_server("/tmp/portal/inspectables"))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
inspectables_server->on_ready_to_accept = [&] {
|
||||
auto client_socket = inspectables_server->accept();
|
||||
if (!client_socket) {
|
||||
dbgln("backdoor accept failed.");
|
||||
return;
|
||||
}
|
||||
struct ucred creds = {};
|
||||
socklen_t creds_size = sizeof(creds);
|
||||
if (getsockopt(client_socket->fd(), SOL_SOCKET, SO_PEERCRED, &creds, &creds_size) < 0) {
|
||||
dbgln("SO_PEERCRED failed");
|
||||
return;
|
||||
}
|
||||
|
||||
InspectorServer::g_processes.set(creds.pid, make<InspectorServer::InspectableProcess>(creds.pid, client_socket.release_nonnull()));
|
||||
};
|
||||
|
||||
return event_loop.exec();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue