LibSQL+Ladybird: Accept a list of paths for spawning SQLServer in Lagom

Use the new get_paths_for_helper_process method in Ladybird to query
Qt for the runtime path of the current executable as well as the build
directory paths.
This commit is contained in:
Andrew Kaster 2023-02-02 03:03:46 -07:00 committed by Andrew Kaster
parent 3e6d790cf0
commit ae9dc95b1f
Notes: sideshowbarker 2024-07-17 00:54:48 +09:00
4 changed files with 23 additions and 15 deletions

View file

@ -6,6 +6,7 @@
*/
#include <AK/DeprecatedString.h>
#include <AK/String.h>
#include <LibSQL/SQLClient.h>
#if !defined(AK_OS_SERENITY)
@ -50,7 +51,7 @@ static ErrorOr<int> create_database_socket(DeprecatedString const& socket_path)
return socket_fd;
}
static ErrorOr<void> launch_server(DeprecatedString const& socket_path, DeprecatedString const& pid_path, StringView server_path)
static ErrorOr<void> launch_server(DeprecatedString const& socket_path, DeprecatedString const& pid_path, Vector<String> candidate_server_paths)
{
auto server_fd_or_error = create_database_socket(socket_path);
if (server_fd_or_error.is_error()) {
@ -77,15 +78,19 @@ static ErrorOr<void> launch_server(DeprecatedString const& socket_path, Deprecat
auto takeover_string = DeprecatedString::formatted("SQLServer:{}", server_fd);
TRY(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true));
auto arguments = Array {
server_path,
"--pid-file"sv,
pid_path,
};
auto result = Core::System::exec(arguments[0], arguments, Core::System::SearchInPath::Yes);
ErrorOr<void> result;
for (auto const& server_path : candidate_server_paths) {
auto arguments = Array {
server_path.bytes_as_string_view(),
"--pid-file"sv,
pid_path,
};
auto result = Core::System::exec(arguments[0], arguments, Core::System::SearchInPath::Yes);
if (!result.is_error())
break;
}
if (result.is_error()) {
warnln("Could not launch {}: {}", server_path, result.error());
warnln("Could not launch any of {}: {}", candidate_server_paths, result.error());
TRY(Core::System::unlink(pid_path));
}
@ -132,14 +137,14 @@ static ErrorOr<bool> should_launch_server(DeprecatedString const& pid_path)
return false;
}
ErrorOr<NonnullRefPtr<SQLClient>> SQLClient::launch_server_and_create_client(StringView server_path)
ErrorOr<NonnullRefPtr<SQLClient>> SQLClient::launch_server_and_create_client(Vector<String> candidate_server_paths)
{
auto runtime_directory = TRY(Core::StandardPaths::runtime_directory());
auto socket_path = DeprecatedString::formatted("{}/SQLServer.socket", runtime_directory);
auto pid_path = DeprecatedString::formatted("{}/SQLServer.pid", runtime_directory);
if (TRY(should_launch_server(pid_path)))
TRY(launch_server(socket_path, pid_path, server_path));
TRY(launch_server(socket_path, pid_path, move(candidate_server_paths)));
auto socket = TRY(Core::Stream::LocalSocket::connect(move(socket_path)));
TRY(socket->set_blocking(true));