mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
WebDriver: Remove the WebContent socket file when closing the session
Otherwise it is left on disk forever.
This commit is contained in:
parent
956fa84f12
commit
cbbaf8ea2c
3 changed files with 14 additions and 11 deletions
|
@ -31,12 +31,12 @@ Session::~Session()
|
||||||
warnln("Failed to stop session {}: {}", m_id, error.error());
|
warnln("Failed to stop session {}: {}", m_id, error.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Core::LocalServer>> Session::create_server(DeprecatedString const& socket_path, NonnullRefPtr<ServerPromise> promise)
|
ErrorOr<NonnullRefPtr<Core::LocalServer>> Session::create_server(NonnullRefPtr<ServerPromise> promise)
|
||||||
{
|
{
|
||||||
dbgln("Listening for WebDriver connection on {}", socket_path);
|
dbgln("Listening for WebDriver connection on {}", *m_web_content_socket_path);
|
||||||
|
|
||||||
auto server = TRY(Core::LocalServer::try_create());
|
auto server = TRY(Core::LocalServer::try_create());
|
||||||
server->listen(socket_path);
|
server->listen(*m_web_content_socket_path);
|
||||||
|
|
||||||
server->on_accept = [this, promise](auto client_socket) {
|
server->on_accept = [this, promise](auto client_socket) {
|
||||||
auto maybe_connection = adopt_nonnull_ref_or_enomem(new (nothrow) WebContentConnection(move(client_socket), m_client, session_id()));
|
auto maybe_connection = adopt_nonnull_ref_or_enomem(new (nothrow) WebContentConnection(move(client_socket), m_client, session_id()));
|
||||||
|
@ -62,13 +62,13 @@ ErrorOr<void> Session::start(LaunchBrowserCallbacks const& callbacks)
|
||||||
{
|
{
|
||||||
auto promise = TRY(ServerPromise::try_create());
|
auto promise = TRY(ServerPromise::try_create());
|
||||||
|
|
||||||
auto web_content_socket_path = DeprecatedString::formatted("{}/webdriver/session_{}_{}", TRY(Core::StandardPaths::runtime_directory()), getpid(), m_id);
|
m_web_content_socket_path = DeprecatedString::formatted("{}/webdriver/session_{}_{}", TRY(Core::StandardPaths::runtime_directory()), getpid(), m_id);
|
||||||
auto web_content_server = TRY(create_server(web_content_socket_path, promise));
|
auto web_content_server = TRY(create_server(promise));
|
||||||
|
|
||||||
if (m_options.headless)
|
if (m_options.headless)
|
||||||
m_browser_pid = TRY(callbacks.launch_headless_browser(web_content_socket_path));
|
m_browser_pid = TRY(callbacks.launch_headless_browser(*m_web_content_socket_path));
|
||||||
else
|
else
|
||||||
m_browser_pid = TRY(callbacks.launch_browser(web_content_socket_path));
|
m_browser_pid = TRY(callbacks.launch_browser(*m_web_content_socket_path));
|
||||||
|
|
||||||
// FIXME: Allow this to be more asynchronous. For now, this at least allows us to propagate
|
// FIXME: Allow this to be more asynchronous. For now, this at least allows us to propagate
|
||||||
// errors received while accepting the Browser and WebContent sockets.
|
// errors received while accepting the Browser and WebContent sockets.
|
||||||
|
@ -96,6 +96,10 @@ Web::WebDriver::Response Session::stop()
|
||||||
MUST(Core::System::kill(*m_browser_pid, SIGTERM));
|
MUST(Core::System::kill(*m_browser_pid, SIGTERM));
|
||||||
m_browser_pid = {};
|
m_browser_pid = {};
|
||||||
}
|
}
|
||||||
|
if (m_web_content_socket_path.has_value()) {
|
||||||
|
MUST(Core::System::unlink(*m_web_content_socket_path));
|
||||||
|
m_web_content_socket_path = {};
|
||||||
|
}
|
||||||
|
|
||||||
m_started = false;
|
m_started = false;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using ServerPromise = Core::Promise<ErrorOr<void>>;
|
using ServerPromise = Core::Promise<ErrorOr<void>>;
|
||||||
ErrorOr<NonnullRefPtr<Core::LocalServer>> create_server(DeprecatedString const& socket_path, NonnullRefPtr<ServerPromise> promise);
|
ErrorOr<NonnullRefPtr<Core::LocalServer>> create_server(NonnullRefPtr<ServerPromise> promise);
|
||||||
|
|
||||||
NonnullRefPtr<Client> m_client;
|
NonnullRefPtr<Client> m_client;
|
||||||
Web::WebDriver::LadybirdOptions m_options;
|
Web::WebDriver::LadybirdOptions m_options;
|
||||||
|
@ -48,6 +48,7 @@ private:
|
||||||
unsigned m_id { 0 };
|
unsigned m_id { 0 };
|
||||||
|
|
||||||
RefPtr<WebContentConnection> m_web_content_connection;
|
RefPtr<WebContentConnection> m_web_content_connection;
|
||||||
|
Optional<DeprecatedString> m_web_content_socket_path;
|
||||||
Optional<pid_t> m_browser_pid;
|
Optional<pid_t> m_browser_pid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto webdriver_socket_path = DeprecatedString::formatted("{}/webdriver", TRY(Core::StandardPaths::runtime_directory()));
|
auto webdriver_socket_path = DeprecatedString::formatted("{}/webdriver", TRY(Core::StandardPaths::runtime_directory()));
|
||||||
TRY(Core::Directory::create(webdriver_socket_path, Core::Directory::CreateDirectories::Yes));
|
TRY(Core::Directory::create(webdriver_socket_path, Core::Directory::CreateDirectories::Yes));
|
||||||
|
|
||||||
TRY(Core::System::pledge("stdio accept rpath recvfd inet unix proc exec fattr"));
|
|
||||||
|
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
|
|
||||||
auto server = TRY(Core::TCPServer::try_create());
|
auto server = TRY(Core::TCPServer::try_create());
|
||||||
|
@ -106,6 +104,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
TRY(Core::System::unveil(webdriver_socket_path, "rwc"sv));
|
TRY(Core::System::unveil(webdriver_socket_path, "rwc"sv));
|
||||||
TRY(Core::System::unveil(nullptr, nullptr));
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
|
|
||||||
TRY(Core::System::pledge("stdio accept rpath recvfd unix proc exec fattr"));
|
TRY(Core::System::pledge("stdio accept cpath rpath recvfd unix proc exec fattr"));
|
||||||
return loop.exec();
|
return loop.exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue