diff options
author | Jostein Kjønigsen <jostein@kjonigsen.net> | 2016-07-19 15:00:25 +0200 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2016-07-19 15:00:25 +0200 |
commit | b306172d0545e2a292619b880a3c8d07bb46d396 (patch) | |
tree | 62665a209d5caa2e7c4daf45b93981da598df558 /src | |
parent | 93f09db0fb3aa1682549fe42f64b76c3418663bc (diff) | |
download | coreclr-b306172d0545e2a292619b880a3c8d07bb46d396.tar.gz coreclr-b306172d0545e2a292619b880a3c8d07bb46d396.tar.bz2 coreclr-b306172d0545e2a292619b880a3c8d07bb46d396.zip |
Fix self-process identification for FreeBSD (#6314)
FreeBSD does not come with procfs enabled by default, and should use
sysctl() for this purpose.
While it has similarities with NetBSD's implementation, there are a
few subtle differences, which justifies leaving this implementation
under its own guard.
It's also worth noting that on FreeBSD sysctl.h MUST be present, which
is unlike NetBSD. Therefore the HAVE_SYS_SYSCTL_H define is not
checked for or used.
This commit fixes https://github.com/dotnet/coreclr/issues/6184.
This commit is based on the following commit from core-setup:
https://github.com/dotnet/core-setup/commit/d5ce08014a174b006a3b409b8bb93d003ae583a0
Diffstat (limited to 'src')
-rw-r--r-- | src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp index 92581faa64..b4c54ca6e3 100644 --- a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp +++ b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp @@ -16,7 +16,11 @@ #include <string> #include <string.h> #include <sys/stat.h> -#ifdef HAVE_SYS_SYSCTL_H +#if defined(__FreeBSD__) +#include <sys/types.h> +#include <sys/param.h> +#endif +#if defined(HAVE_SYS_SYSCTL_H) || defined(__FreeBSD__) #include <sys/sysctl.h> #endif #include "coreruncommon.h" @@ -75,6 +79,24 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable) result = true; } } +#elif defined (__FreeBSD__) + static const int name[] = { + CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 + }; + char path[PATH_MAX]; + size_t len; + + len = sizeof(path); + if (sysctl(name, 4, path, &len, nullptr, 0) == 0) + { + entrypointExecutable.assign(path); + result = true; + } + else + { + // ENOMEM + result = false; + } #elif defined(__NetBSD__) && defined(KERN_PROC_PATHNAME) static const int name[] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME, |