From 5eb5383f08a40db05e196f5f192afd08e92aebd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Mon, 15 Jan 2024 19:53:11 +0100 Subject: [PATCH] Fix Platform::ExecutableName on freebsd Also fix release (but somehow only release) builds failing to link because execinfo is a library on freebsd. --- src/common/platform/Linux.cpp | 24 +++++++++++++++++++++- src/common/platform/stacktrace/meson.build | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/common/platform/Linux.cpp b/src/common/platform/Linux.cpp index 0fe6f762e..cdc3d53d2 100644 --- a/src/common/platform/Linux.cpp +++ b/src/common/platform/Linux.cpp @@ -6,6 +6,9 @@ #include "Config.h" #include #include +#ifdef __FreeBSD__ +# include +#endif namespace Platform { @@ -26,7 +29,26 @@ long unsigned int GetTime() ByteString ExecutableNameFirstApprox() { - return "/proc/self/exe"; + if (Stat("/proc/self/exe")) + { + return "/proc/self/exe"; + } +#ifdef __FreeBSD__ + { + int mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + std::array buf; + size_t cb = buf.size(); + if (!sysctl(mib, 4, &buf[0], &cb, NULL, 0)) + { + return ByteString(&buf[0], &buf[0] + cb); + } + } +#endif + return ""; } bool CanUpdate() diff --git a/src/common/platform/stacktrace/meson.build b/src/common/platform/stacktrace/meson.build index 572b90bc2..c2a2c04f5 100644 --- a/src/common/platform/stacktrace/meson.build +++ b/src/common/platform/stacktrace/meson.build @@ -16,6 +16,11 @@ elif host_platform == 'linux' stacktrace_files = files('Execinfo.cpp') # export symbols so backtrace_symbols works, see above bluescreen_export_symbols = true + if host_machine.system() in [ 'freebsd' ] + project_deps += [ + c_compiler.find_library('execinfo'), + ] + endif else stacktrace_files = files('Null.cpp') endif