From ee3044db5a94cb93867f09a3ce8704a958f81439 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 10:31:08 +0200 Subject: [PATCH 1/8] 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.43.2 From 32f6ecc5adf799842f419966783a5127c153f40e Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:14:47 +0200 Subject: [PATCH 2/8] 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 740c9c41dd..5179f203c9 100644 --- a/Userland/Libraries/LibGfx/CMakeLists.txt +++ b/Userland/Libraries/LibGfx/CMakeLists.txt @@ -95,6 +95,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.43.2 From b87b96cbf28e0f125a6c4f37e1988511cab4dacb Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:17:23 +0200 Subject: [PATCH 3/8] 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.43.2 From a9ec9b9cefaa9b27029f94690eac607d4e1444c6 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:18:44 +0200 Subject: [PATCH 4/8] 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.43.2 From 27b05b2cc4b785dabeeb094d24171ee2d775c8ce Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:21:18 +0200 Subject: [PATCH 5/8] 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.43.2 From 76f8228291593f8bd7fa96c6db4c66a3b1cbe717 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:23:34 +0200 Subject: [PATCH 6/8] 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 57e45b0039..80c13d0c87 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -343,6 +343,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.43.2 From 47cafd30579b30d372ed05b283624e7963ccbfdf Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 15 Jun 2024 17:24:18 +0200 Subject: [PATCH 7/8] Meta: Link LibCoreMinimal to libnetwork on Haiku --- Meta/Lagom/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 80c13d0c87..553c00412c 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -371,6 +371,7 @@ endif() if (HAIKU) # Haiku has networking related functions in the network library target_link_libraries(LibCore PRIVATE network) + target_link_libraries(LibCoreMinimal PRIVATE network) endif() target_link_libraries(LibCore PRIVATE LibURL) -- 2.43.2 From c1d6fb017dd0aaf598b36cf2f3391e95db1374a5 Mon Sep 17 00:00:00 2001 From: Niklas Poslovski Date: Sat, 13 Jul 2024 19:33:15 +0200 Subject: [PATCH 8/8] 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 6980f9084d..e2b12666b8 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1574,7 +1574,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.43.2