diff options
author | Manu <manu-silicon@users.noreply.github.com> | 2016-02-16 15:27:04 +0900 |
---|---|---|
committer | Manu <manu-silicon@users.noreply.github.com> | 2016-02-18 10:40:27 +0900 |
commit | b4d8a8d865c2c1eba7166e5d6c822419b6f1a1ea (patch) | |
tree | caee4a24c154b1a3847ff63bf14a72feed4dc8ac /src/coreclr | |
parent | 5a26372691fea92f1ef328f287e1e37243af3e34 (diff) | |
download | coreclr-b4d8a8d865c2c1eba7166e5d6c822419b6f1a1ea.tar.gz coreclr-b4d8a8d865c2c1eba7166e5d6c822419b6f1a1ea.tar.bz2 coreclr-b4d8a8d865c2c1eba7166e5d6c822419b6f1a1ea.zip |
Fix GetEntrypointExecutableAbsolutePath on Linux
Although PR#1818 was supposed to implement this for Linux, only the MacOS X
implementation was correct. We are now using `readlink' on Linux to get
the path of the current running executable.
Diffstat (limited to 'src/coreclr')
-rw-r--r-- | src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp index 9d13377f6a..1125dfb819 100644 --- a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp +++ b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp @@ -16,6 +16,7 @@ #include <string.h> #include <sys/stat.h> #include "coreruncommon.h" +#include <unistd.h> #define SUCCEEDED(Status) ((Status) >= 0) @@ -66,12 +67,20 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable) // Get path to the executable for the current process using // platform specific means. -#if defined(__LINUX__) || !defined(__APPLE__) - - // On non-Mac OS, return the symlink that will be resolved by GetAbsolutePath - // to fetch the entrypoint EXE absolute path, inclusive of filename. - entrypointExecutable.assign(symlinkEntrypointExecutable); - result = true; +#if defined(__LINUX__) + // On Linux, fetch the entry point EXE absolute path, inclusive of filename. + char exe[PATH_MAX]; + ssize_t res = readlink(symlinkEntrypointExecutable, exe, PATH_MAX - 1); + if (res != -1) + { + exe[res] = '\0'; + entrypointExecutable.assign(exe); + result = true; + } + else + { + result = false; + } #elif defined(__APPLE__) // On Mac, we ask the OS for the absolute path to the entrypoint executable @@ -88,7 +97,12 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable) result = true; } } - #endif +#else + // On non-Mac OS, return the symlink that will be resolved by GetAbsolutePath + // to fetch the entrypoint EXE absolute path, inclusive of filename. + entrypointExecutable.assign(symlinkEntrypointExecutable); + result = true; +#endif return result; } @@ -300,12 +314,14 @@ int ExecuteManagedAssembly( // Server GC is off by default, while concurrent GC is on by default. // Actual checking of these string values is done in coreclr_initialize. const char* useServerGc = std::getenv(serverGcVar); - if (useServerGc == nullptr) { + if (useServerGc == nullptr) + { useServerGc = "0"; } const char* useConcurrentGc = std::getenv(concurrentGcVar); - if (useConcurrentGc == nullptr) { + if (useConcurrentGc == nullptr) + { useConcurrentGc = "1"; } |