1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:47:45 +00:00

Userland: Remove "Inspector" program and related utilities

This program has never lived up to its original idea, and has been
broken for years (property editing, etc). It's also unmaintained and
off-by-default since forever.

At this point, Inspector is more of a maintenance burden than a feature,
so this commit removes it from the system, along with the mechanism in
Core::EventLoop that enables it.

If we decide we want the feature again in the future, it can be
reimplemented better. :^)
This commit is contained in:
Andreas Kling 2023-04-24 10:31:49 +02:00
parent 203e84c378
commit c756e021a7
39 changed files with 11 additions and 1386 deletions

View file

@ -2,7 +2,6 @@ add_subdirectory(ConfigServer)
add_subdirectory(EchoServer)
add_subdirectory(FileOperation)
add_subdirectory(ImageDecoder)
add_subdirectory(InspectorServer)
add_subdirectory(LookupServer)
add_subdirectory(RequestServer)
add_subdirectory(WebServer)

View file

@ -1,22 +0,0 @@
serenity_component(
InspectorServer
REQUIRED
TARGETS InspectorServer
)
compile_ipc(InspectorServer.ipc InspectorServerEndpoint.h)
compile_ipc(InspectorClient.ipc InspectorClientEndpoint.h)
set(SOURCES
ConnectionFromClient.cpp
main.cpp
InspectableProcess.cpp
)
set(GENERATED_SOURCES
InspectorServerEndpoint.h
InspectorClientEndpoint.h
)
serenity_bin(InspectorServer)
target_link_libraries(InspectorServer PRIVATE LibCore LibIPC LibMain)

View file

@ -1,89 +0,0 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "InspectableProcess.h"
#include <AK/JsonObject.h>
#include <InspectorServer/ConnectionFromClient.h>
namespace InspectorServer {
static HashMap<int, RefPtr<ConnectionFromClient>> s_connections;
ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket> socket, int client_id)
: IPC::ConnectionFromClient<InspectorClientEndpoint, InspectorServerEndpoint>(*this, move(socket), client_id)
{
s_connections.set(client_id, *this);
}
void ConnectionFromClient::die()
{
s_connections.remove(client_id());
}
Messages::InspectorServer::GetAllObjectsResponse ConnectionFromClient::get_all_objects(pid_t pid)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return DeprecatedString {};
JsonObject request;
request.set("type", "GetAllObjects");
process->send_request(request);
auto response = process->wait_for_response();
return response;
}
Messages::InspectorServer::SetInspectedObjectResponse ConnectionFromClient::set_inspected_object(pid_t pid, u64 object_id)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return false;
JsonObject request;
request.set("type", "SetInspectedObject");
request.set("address", object_id);
process->send_request(request);
return true;
}
Messages::InspectorServer::SetObjectPropertyResponse ConnectionFromClient::set_object_property(pid_t pid, u64 object_id, DeprecatedString const& name, DeprecatedString const& value)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return false;
JsonObject request;
request.set("type", "SetProperty");
request.set("address", object_id);
request.set("name", name);
request.set("value", value);
process->send_request(request);
return true;
}
Messages::InspectorServer::IdentifyResponse ConnectionFromClient::identify(pid_t pid)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return DeprecatedString {};
JsonObject request;
request.set("type", "Identify");
process->send_request(request);
auto response = process->wait_for_response();
return response;
}
Messages::InspectorServer::IsInspectableResponse ConnectionFromClient::is_inspectable(pid_t pid)
{
auto process = InspectableProcess::from_pid(pid);
if (!process)
return false;
return true;
}
}

View file

@ -1,35 +0,0 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <InspectorServer/InspectorClientEndpoint.h>
#include <InspectorServer/InspectorServerEndpoint.h>
#include <LibIPC/ConnectionFromClient.h>
namespace InspectorServer {
class ConnectionFromClient final
: public IPC::ConnectionFromClient<InspectorClientEndpoint, InspectorServerEndpoint> {
C_OBJECT(ConnectionFromClient);
public:
~ConnectionFromClient() override = default;
virtual void die() override;
private:
explicit ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>, int client_id);
virtual Messages::InspectorServer::GetAllObjectsResponse get_all_objects(pid_t) override;
virtual Messages::InspectorServer::SetInspectedObjectResponse set_inspected_object(pid_t, u64 object_id) override;
virtual Messages::InspectorServer::SetObjectPropertyResponse set_object_property(pid_t, u64 object_id, DeprecatedString const& name, DeprecatedString const& value) override;
virtual Messages::InspectorServer::IdentifyResponse identify(pid_t) override;
virtual Messages::InspectorServer::IsInspectableResponse is_inspectable(pid_t) override;
};
}

View file

@ -1,13 +0,0 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
namespace SymbolServer {
class ConnectionFromClient;
}

View file

@ -1,81 +0,0 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "InspectableProcess.h"
#include <AK/JsonObject.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Socket.h>
namespace InspectorServer {
HashMap<pid_t, NonnullOwnPtr<InspectableProcess>> g_processes;
InspectableProcess* InspectableProcess::from_pid(pid_t pid)
{
return g_processes.get(pid).value_or(nullptr);
}
InspectableProcess::InspectableProcess(pid_t pid, NonnullOwnPtr<Core::LocalSocket> socket)
: m_pid(pid)
, m_socket(move(socket))
{
// FIXME: Propagate errors
MUST(m_socket->set_blocking(true));
m_socket->on_ready_to_read = [this] {
[[maybe_unused]] auto c = m_socket->read_value<char>().release_value_but_fixme_should_propagate_errors();
if (m_socket->is_eof()) {
Core::deferred_invoke([pid = this->m_pid] { g_processes.remove(pid); });
return;
}
};
}
DeprecatedString InspectableProcess::wait_for_response()
{
if (m_socket->is_eof()) {
dbgln("InspectableProcess disconnected: PID {}", m_pid);
m_socket->close();
return {};
}
auto length = m_socket->read_value<u32>().release_value_but_fixme_should_propagate_errors();
auto data_buffer = ByteBuffer::create_uninitialized(length).release_value_but_fixme_should_propagate_errors();
auto remaining_data_buffer = data_buffer.bytes();
while (!remaining_data_buffer.is_empty()) {
auto maybe_bytes_read = m_socket->read_some(remaining_data_buffer);
if (maybe_bytes_read.is_error()) {
dbgln("InspectableProcess::wait_for_response: Failed to read data: {}", maybe_bytes_read.error());
break;
}
auto bytes_read = maybe_bytes_read.release_value();
if (bytes_read.is_empty())
break;
remaining_data_buffer = remaining_data_buffer.slice(bytes_read.size());
}
VERIFY(data_buffer.size() == length);
dbgln("Got data size {} and read that many bytes", length);
return DeprecatedString::copy(data_buffer);
}
void InspectableProcess::send_request(JsonObject const& request)
{
auto serialized = request.to_deprecated_string();
u32 length = serialized.length();
// FIXME: Propagate errors
MUST(m_socket->write_value(length));
MUST(m_socket->write_until_depleted(serialized.bytes()));
}
}

View file

@ -1,31 +0,0 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibCore/Socket.h>
#include <sys/types.h>
namespace InspectorServer {
class InspectableProcess {
public:
InspectableProcess(pid_t, NonnullOwnPtr<Core::LocalSocket>);
~InspectableProcess() = default;
void send_request(JsonObject const& request);
DeprecatedString wait_for_response();
static InspectableProcess* from_pid(pid_t);
private:
pid_t m_pid { 0 };
NonnullOwnPtr<Core::LocalSocket> m_socket;
};
extern HashMap<pid_t, NonnullOwnPtr<InspectorServer::InspectableProcess>> g_processes;
}

View file

@ -1,3 +0,0 @@
endpoint InspectorClient
{
}

View file

@ -1,8 +0,0 @@
endpoint InspectorServer
{
get_all_objects(i32 pid) => (DeprecatedString json)
set_inspected_object(i32 pid, u64 object_id) => (bool success)
set_object_property(i32 pid, u64 object_id, DeprecatedString name, DeprecatedString value) => (bool success)
identify(i32 pid) => (DeprecatedString json)
is_inspectable(i32 pid) => (bool inspectable)
}

View file

@ -1,33 +0,0 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "InspectableProcess.h"
#include <InspectorServer/ConnectionFromClient.h>
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
#include <LibCore/System.h>
#include <LibIPC/ConnectionFromClient.h>
#include <LibIPC/MultiServer.h>
#include <LibMain/Main.h>
ErrorOr<int> serenity_main(Main::Arguments)
{
Core::EventLoop event_loop;
TRY(Core::System::pledge("stdio unix accept rpath"));
auto server = TRY(IPC::MultiServer<InspectorServer::ConnectionFromClient>::try_create("/tmp/session/%sid/portal/inspector"));
auto inspectables_server = TRY(Core::LocalServer::try_create());
TRY(inspectables_server->take_over_from_system_server("/tmp/session/%sid/portal/inspectables"));
inspectables_server->on_accept = [&](auto client_socket) {
auto pid = client_socket->peer_pid().release_value_but_fixme_should_propagate_errors();
InspectorServer::g_processes.set(pid, make<InspectorServer::InspectableProcess>(pid, move(client_socket)));
};
return event_loop.exec();
}