From af89a09296e2315085da9ad6b1895e5f9ced9889 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 10:31:08 +0200 Subject: [PATCH 01/11] LibCore: Don't use secure_getenv on Haiku --- Userland/Libraries/LibCore/Environment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibCore/Environment.cpp b/Userland/Libraries/LibCore/Environment.cpp index 343273e747..51bd0cb8d8 100644 --- a/Userland/Libraries/LibCore/Environment.cpp +++ b/Userland/Libraries/LibCore/Environment.cpp @@ -94,7 +94,7 @@ Optional get(StringView name, [[maybe_unused]] SecureOnly secure) // Note the explicit null terminators above. // FreeBSD < 14, and generic BSDs do not support secure_getenv. -#if (defined(__FreeBSD__) && __FreeBSD__ >= 14) || !defined(AK_OS_BSD_GENERIC) +#if (defined(__FreeBSD__) && __FreeBSD__ >= 14) || (!defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_HAIKU)) char* result; if (secure == SecureOnly::Yes) { result = ::secure_getenv(builder.string_view().characters_without_null_termination()); -- 2.45.2 From ea87e27e071b85c88944f26888438e17717d6d20 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:14:47 +0200 Subject: [PATCH 02/11] LibGfx: Link LibGfx to libgnu, the GNU compatibility library, on Haiku --- Userland/Libraries/LibGfx/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Libraries/LibGfx/CMakeLists.txt b/Userland/Libraries/LibGfx/CMakeLists.txt index 3eb91b9954..64d0673c80 100644 --- a/Userland/Libraries/LibGfx/CMakeLists.txt +++ b/Userland/Libraries/LibGfx/CMakeLists.txt @@ -97,6 +97,9 @@ set(SOURCES serenity_lib(LibGfx gfx) target_link_libraries(LibGfx PRIVATE LibCompress LibCore LibCrypto LibFileSystem LibRIFF LibTextCodec LibIPC LibUnicode LibURL) +if (HAIKU) + target_link_libraries(LibGfx PRIVATE gnu) +endif() set(generated_sources TIFFMetadata.h TIFFTagHandler.cpp) list(TRANSFORM generated_sources PREPEND "ImageFormats/") -- 2.45.2 From 3ce44d8dc18ee714fd39669a26119e2dab21f362 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:17:23 +0200 Subject: [PATCH 03/11] LibCore: Remove the Haiku-specific runtime_directory from StandardPaths --- Userland/Libraries/LibCore/StandardPaths.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Userland/Libraries/LibCore/StandardPaths.cpp b/Userland/Libraries/LibCore/StandardPaths.cpp index 77ddbeb953..8a95a5c2f1 100644 --- a/Userland/Libraries/LibCore/StandardPaths.cpp +++ b/Userland/Libraries/LibCore/StandardPaths.cpp @@ -154,8 +154,6 @@ ErrorOr StandardPaths::runtime_directory() #elif defined(AK_OS_MACOS) builder.append(home_directory()); builder.append("/Library/Application Support"sv); -#elif defined(AK_OS_HAIKU) - builder.append("/boot/system/var/shared_memory"sv); #elif defined(AK_OS_LINUX) auto uid = getuid(); builder.appendff("/run/user/{}", uid); -- 2.45.2 From c8a2f49b742d8aa67d62cf1d0b170c8474f2e47d Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:18:44 +0200 Subject: [PATCH 04/11] LibCore: Don't do fchmod at sockets on Haiku --- Userland/Libraries/LibCore/Process.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibCore/Process.cpp b/Userland/Libraries/LibCore/Process.cpp index 41a2ea24fa..beaafbab01 100644 --- a/Userland/Libraries/LibCore/Process.cpp +++ b/Userland/Libraries/LibCore/Process.cpp @@ -431,7 +431,7 @@ ErrorOr IPCProcess::create_ipc_socket(ByteString const& socket_path) TRY(System::fcntl(socket_fd, F_SETFD, FD_CLOEXEC)); #endif -#if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_GNU_HURD) +#if !defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_GNU_HURD) && !defined(AK_OS_HAIKU) TRY(System::fchmod(socket_fd, 0600)); #endif -- 2.45.2 From f79e9fa8629f9f93f8c99d251cc90620f5a103a3 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:21:18 +0200 Subject: [PATCH 05/11] LibCore: Avoid creating existing directories on Haiku --- Userland/Libraries/LibCore/Directory.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Userland/Libraries/LibCore/Directory.cpp b/Userland/Libraries/LibCore/Directory.cpp index 482ae4ecce..4a17a33b35 100644 --- a/Userland/Libraries/LibCore/Directory.cpp +++ b/Userland/Libraries/LibCore/Directory.cpp @@ -74,6 +74,18 @@ ErrorOr Directory::ensure_directory(LexicalPath const& path, mode_t creati TRY(ensure_directory(path.parent(), creation_mode)); +#ifdef AK_OS_HAIKU + // Haiku throws an error when trying to create a directory that already exists, but is part of the read-only packagefs. + // This can be worked-around by checking if the directory exists first, and then return without recreating it. + auto st_or_error = System::stat(path.string()); + if (!st_or_error.is_error()) + { + auto st = st_or_error.release_value(); + if S_ISDIR(st.st_mode) + return {}; + } +#endif + auto return_value = System::mkdir(path.string(), creation_mode); // We don't care if the directory already exists. if (return_value.is_error() && return_value.error().code() != EEXIST) -- 2.45.2 From 53745e9c5e00ca95bb8d3b7a0f804fad3169a4c3 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:23:34 +0200 Subject: [PATCH 06/11] Meta: Link AK to libbsd, the BSD compatibility library, on Haiku --- Meta/Lagom/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 8b60cc63e9..26a592816d 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -374,6 +374,10 @@ install(TARGETS LibC LibCrypt LibSystem NoCoverage EXPORT LagomTargets) # AK add_serenity_subdirectory(AK) lagom_lib(AK ak SOURCES ${AK_SOURCES}) +if (HAIKU) + # Haiku has some BSD-compatibility functions that we need in libbsd + target_link_libraries(AK PRIVATE bsd) +endif() find_package(Backtrace) if (Backtrace_FOUND AND NOT "${Backtrace_LIBRARIES}" STREQUAL "") target_link_libraries(AK PRIVATE ${Backtrace_LIBRARIES}) -- 2.45.2 From 8b44641b2bb4068e271af3665f6fa8d9f6d7bd75 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:24:18 +0200 Subject: [PATCH 07/11] Meta: Link LibCoreMinimal to libnetwork on Haiku --- Meta/Lagom/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 26a592816d..d6767ad6a6 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -390,6 +390,10 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") # NetBSD has its shm_open and shm_unlink functions in librt so we need to link that target_link_libraries(LibCoreMinimal PRIVATE rt) endif() +if (HAIKU) + # Haiku has networking related functions in the network library + target_link_libraries(LibCoreMinimal PRIVATE network) +endif() # LibMain add_serenity_subdirectory(Userland/Libraries/LibMain) -- 2.45.2 From 9552cbb100e02ac3f9fa48e9b4fe8ac5992f5c7f Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 13 Jul 2024 19:33:15 +0200 Subject: [PATCH 08/11] LibCore: Fall back to pipe instead of pipe2 on Haiku --- Userland/Libraries/LibCore/System.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 76e3c89ff7..ec78fd045e 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1620,7 +1620,7 @@ ErrorOr> pipe2(int flags) { Array fds; -#if defined(__unix__) +#if defined(__unix__) && !defined(AK_OS_HAIKU) if (::pipe2(fds.data(), flags) < 0) return Error::from_syscall("pipe2"sv, -errno); #else -- 2.45.2 From 526c24d2f1aa9e238c929486ae2094f7122a30c0 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Wed, 16 Oct 2024 16:15:08 +0200 Subject: [PATCH 09/11] LookupServer: Define sin_len for mdns_addr on Haiku --- Userland/Services/LookupServer/MulticastDNS.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Services/LookupServer/MulticastDNS.h b/Userland/Services/LookupServer/MulticastDNS.h index 65a5580541..8a0845fdea 100644 --- a/Userland/Services/LookupServer/MulticastDNS.h +++ b/Userland/Services/LookupServer/MulticastDNS.h @@ -37,7 +37,7 @@ private: Name m_hostname; static constexpr sockaddr_in mdns_addr { -#if defined(AK_OS_BSD_GENERIC) || defined(AK_OS_GNU_HURD) +#if defined(AK_OS_BSD_GENERIC) || defined(AK_OS_GNU_HURD) || defined(AK_OS_HAIKU) .sin_len = sizeof(struct sockaddr_in), #endif .sin_family = AF_INET, -- 2.45.2 From 2eb8de01b013fc035b71e814ed98a8af2f2ddd19 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Wed, 16 Oct 2024 16:31:37 +0200 Subject: [PATCH 10/11] LookupServer: Link to libnetwork on Haiku --- Userland/Services/LookupServer/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Services/LookupServer/CMakeLists.txt b/Userland/Services/LookupServer/CMakeLists.txt index 185d0a5ecd..d56cdeb5e9 100644 --- a/Userland/Services/LookupServer/CMakeLists.txt +++ b/Userland/Services/LookupServer/CMakeLists.txt @@ -22,3 +22,6 @@ set(GENERATED_SOURCES serenity_bin(LookupServer) target_link_libraries(LookupServer PRIVATE LibCore LibDNS LibIPC LibMain) +if (HAIKU) + target_link_libraries(LookupServer PRIVATE network) +endif() \ No newline at end of file -- 2.45.2 From d596d684e01c5549504cf0b345ecdcf1809fe6d5 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Wed, 16 Oct 2024 16:26:03 +0200 Subject: [PATCH 11/11] LibLine: Don't register VWERASE key handler for Haiku --- Userland/Libraries/LibLine/Editor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 4afe949fed..88b673c427 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -177,8 +177,10 @@ void Editor::set_default_keybinds() register_key_input_callback(Key { 't', Key::Alt }, EDITOR_INTERNAL_FUNCTION(transpose_words)); // Register these last to all the user to override the previous key bindings +#if !defined(AK_OS_HAIKU) // Normally ^W. `stty werase \^n` can change it to ^N (or something else). register_key_input_callback(m_termios.c_cc[VWERASE], EDITOR_INTERNAL_FUNCTION(erase_word_backwards)); +#endif // Normally ^U. `stty kill \^n` can change it to ^N (or something else). register_key_input_callback(m_termios.c_cc[VKILL], EDITOR_INTERNAL_FUNCTION(kill_line)); register_key_input_callback(m_termios.c_cc[VERASE], EDITOR_INTERNAL_FUNCTION(erase_character_backwards)); -- 2.45.2