Fix Platform::ExecutableName on freebsd

Also fix release (but somehow only release) builds failing to link because execinfo is a library on freebsd.
This commit is contained in:
Tamás Bálint Misius 2024-01-15 19:53:11 +01:00
parent 708d543d29
commit 5eb5383f08
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 28 additions and 1 deletions

View File

@ -6,6 +6,9 @@
#include "Config.h"
#include <cstring>
#include <ctime>
#ifdef __FreeBSD__
# include <sys/sysctl.h>
#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<char, 1000> 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()

View File

@ -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