Merge "libutil: Support getSelfExe on FreeBSD" into main
This commit is contained in:
commit
60a48311e8
1 changed files with 23 additions and 0 deletions
|
@ -15,6 +15,11 @@
|
||||||
# include <sys/resource.h>
|
# include <sys/resource.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __FreeBSD__
|
||||||
|
# include <sys/param.h>
|
||||||
|
# include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <cgroup.hh>
|
#include <cgroup.hh>
|
||||||
|
|
||||||
|
@ -102,6 +107,24 @@ std::optional<Path> getSelfExe()
|
||||||
return buf;
|
return buf;
|
||||||
else
|
else
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
#elif __FreeBSD__
|
||||||
|
int sysctlName[] = {
|
||||||
|
CTL_KERN,
|
||||||
|
KERN_PROC,
|
||||||
|
KERN_PROC_PATHNAME,
|
||||||
|
-1,
|
||||||
|
};
|
||||||
|
size_t pathLen = 0;
|
||||||
|
if (sysctl(sysctlName, sizeof(sysctlName) / sizeof(sysctlName[0]), nullptr, &pathLen, nullptr, 0) < 0) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<char> path(pathLen);
|
||||||
|
if (sysctl(sysctlName, sizeof(sysctlName) / sizeof(sysctlName[0]), path.data(), &pathLen, nullptr, 0) < 0) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Path(path.begin(), path.end());
|
||||||
#else
|
#else
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue