diff --git a/Ladybird/main.cpp b/Ladybird/main.cpp index 1cb503b56f..d8302b65c3 100644 --- a/Ladybird/main.cpp +++ b/Ladybird/main.cpp @@ -5,6 +5,7 @@ */ #include "BrowserWindow.h" +#include "HelperProcess.h" #include "Settings.h" #include "Utilities.h" #include "WebContentView.h" @@ -99,7 +100,8 @@ ErrorOr serenity_main(Main::Arguments arguments) return app.exec(); } - auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client("./SQLServer/SQLServer"sv)); + auto sql_server_paths = TRY(get_paths_for_helper_process("SQLServer"sv)); + auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client(move(sql_server_paths))); auto database = TRY(Browser::Database::create(move(sql_client))); auto cookie_jar = TRY(Browser::CookieJar::create(*database)); diff --git a/Userland/Libraries/LibSQL/SQLClient.cpp b/Userland/Libraries/LibSQL/SQLClient.cpp index 506b972895..bab488ef0f 100644 --- a/Userland/Libraries/LibSQL/SQLClient.cpp +++ b/Userland/Libraries/LibSQL/SQLClient.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #if !defined(AK_OS_SERENITY) @@ -50,7 +51,7 @@ static ErrorOr create_database_socket(DeprecatedString const& socket_path) return socket_fd; } -static ErrorOr launch_server(DeprecatedString const& socket_path, DeprecatedString const& pid_path, StringView server_path) +static ErrorOr launch_server(DeprecatedString const& socket_path, DeprecatedString const& pid_path, Vector 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 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 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 should_launch_server(DeprecatedString const& pid_path) return false; } -ErrorOr> SQLClient::launch_server_and_create_client(StringView server_path) +ErrorOr> SQLClient::launch_server_and_create_client(Vector 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)); diff --git a/Userland/Libraries/LibSQL/SQLClient.h b/Userland/Libraries/LibSQL/SQLClient.h index ed8c597baa..76c4a94f7e 100644 --- a/Userland/Libraries/LibSQL/SQLClient.h +++ b/Userland/Libraries/LibSQL/SQLClient.h @@ -22,7 +22,7 @@ class SQLClient public: #if !defined(AK_OS_SERENITY) - static ErrorOr> launch_server_and_create_client(StringView server_path); + static ErrorOr> launch_server_and_create_client(Vector candidate_server_paths); #endif virtual ~SQLClient() = default; diff --git a/Userland/Utilities/sql.cpp b/Userland/Utilities/sql.cpp index cb5c599e22..b263973b01 100644 --- a/Userland/Utilities/sql.cpp +++ b/Userland/Utilities/sql.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -361,8 +362,8 @@ ErrorOr serenity_main(Main::Arguments arguments) #if defined(AK_OS_SERENITY) auto sql_client = TRY(SQL::SQLClient::try_create()); #else - VERIFY(sql_server_path != nullptr); - auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client(sql_server_path)); + VERIFY(!sql_server_path.is_empty()); + auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client({ TRY(String::from_utf8(sql_server_path)) })); #endif SQLRepl repl(loop, database_name, move(sql_client));