Platform (OpenBSD): uses getexecpath(3) if available

Fixes https://github.com/fastfetch-cli/fastfetch/issues/2195#issuecomment-6095513342
This commit is contained in:
Carter Li
2026-10-10 18:33:05 +08:00
parent e0361fdcf6
commit cc435d2b70
2 changed files with 13 additions and 1 deletions
+7
View File
@@ -1689,6 +1689,13 @@ if(FreeBSD OR OpenBSD OR NetBSD)
unset(CMAKE_REQUIRED_DEFINITIONS) unset(CMAKE_REQUIRED_DEFINITIONS)
endif() endif()
if(OpenBSD)
check_symbol_exists("getexecpath" "unistd.h" HAVE_GETEXECPATH)
if(HAVE_GETEXECPATH)
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_GETEXECPATH=1)
endif()
endif()
if(HAVE_PIPE2) if(HAVE_PIPE2)
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_PIPE2) target_compile_definitions(libfastfetch PUBLIC FF_HAVE_PIPE2)
endif() endif()
+6 -1
View File
@@ -64,7 +64,11 @@ static void getExePath(FFPlatform* platform) {
exePathLen--; // remove terminating NUL exePathLen--; // remove terminating NUL
} }
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
// OpenBSD doesn't have a reliable way to get the executable path. #if FF_HAVE_GETEXECPATH
// https://man.openbsd.org/getexecpath.3
size_t exePathLen = getexecpath(exePath, sizeof(exePath)) == 0 ? strlen(exePath) : 0;
#else
// OpenBSD (before 8.0) doesn't have a reliable way to get the executable path.
// Current implementation uses argv[0], which can be easily spoofed. // Current implementation uses argv[0], which can be easily spoofed.
// See #2195 // See #2195
size_t exePathLen = 0; size_t exePathLen = 0;
@@ -165,6 +169,7 @@ static void getExePath(FFPlatform* platform) {
} }
} }
} }
#endif
#elif defined(__sun) #elif defined(__sun)
ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1); ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1);
if (exePathLen > 0) { if (exePathLen > 0) {