From 4967260f111140ac147fd44d2a356886d93e6248 Mon Sep 17 00:00:00 2001 From: Hadi Brais Date: Sun, 9 Apr 2017 00:54:23 +0530 Subject: [PATCH] Fix corerun issue when loaded from PATH (dotnet/coreclr#10745) Commit migrated from https://github.com/dotnet/coreclr/commit/551a7c5563105f7ec9a9d9273204d0a07a02c4fa --- .../coreclr/hosts/unixcoreconsole/coreconsole.cpp | 13 +++---------- .../src/coreclr/hosts/unixcorerun/corerun.cpp | 2 +- .../hosts/unixcoreruncommon/coreruncommon.cpp | 21 +++------------------ 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/coreclr/src/coreclr/hosts/unixcoreconsole/coreconsole.cpp b/src/coreclr/src/coreclr/hosts/unixcoreconsole/coreconsole.cpp index e43124d..d46f6ef 100644 --- a/src/coreclr/src/coreclr/hosts/unixcoreconsole/coreconsole.cpp +++ b/src/coreclr/src/coreclr/hosts/unixcoreconsole/coreconsole.cpp @@ -93,7 +93,6 @@ bool ParseArguments( int main(const int argc, const char* argv[]) { // Make sure we have a full path for argv[0]. - std::string argv0AbsolutePath; std::string entryPointExecutablePath; if (!GetEntrypointExecutableAbsolutePath(entryPointExecutablePath)) @@ -102,15 +101,9 @@ int main(const int argc, const char* argv[]) return -1; } - if (!GetAbsolutePath(entryPointExecutablePath.c_str(), argv0AbsolutePath)) - { - perror("Could not normalize full path to current executable"); - return -1; - } - // We will try to load the managed assembly with the same name as this executable // but with the .dll extension. - std::string programPath(argv0AbsolutePath); + std::string programPath(entryPointExecutablePath); programPath.append(".dll"); const char* managedAssemblyAbsolutePath = programPath.c_str(); @@ -146,13 +139,13 @@ int main(const int argc, const char* argv[]) } std::string clrFilesAbsolutePath; - if(!GetClrFilesAbsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath)) + if(!GetClrFilesAbsolutePath(entryPointExecutablePath.c_str(), clrFilesPath, clrFilesAbsolutePath)) { return -1; } int exitCode = ExecuteManagedAssembly( - argv0AbsolutePath.c_str(), + entryPointExecutablePath.c_str(), clrFilesAbsolutePath.c_str(), managedAssemblyAbsolutePath, managedAssemblyArgc, diff --git a/src/coreclr/src/coreclr/hosts/unixcorerun/corerun.cpp b/src/coreclr/src/coreclr/hosts/unixcorerun/corerun.cpp index da886d4..4e5c9d9 100644 --- a/src/coreclr/src/coreclr/hosts/unixcorerun/corerun.cpp +++ b/src/coreclr/src/coreclr/hosts/unixcorerun/corerun.cpp @@ -127,7 +127,7 @@ int corerun(const int argc, const char* argv[]) // Make sure we have a full path for argv[0]. std::string argv0AbsolutePath; - if (!GetAbsolutePath(argv[0], argv0AbsolutePath)) + if (!GetEntrypointExecutableAbsolutePath(argv0AbsolutePath)) { perror("Could not get full path"); return -1; diff --git a/src/coreclr/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp b/src/coreclr/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp index 5ac7654..d40fb42 100644 --- a/src/coreclr/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp +++ b/src/coreclr/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp @@ -49,21 +49,7 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable) // Get path to the executable for the current process using // platform specific means. -#if defined(__linux__) || (defined(__NetBSD__) && !defined(KERN_PROC_PATHNAME)) - // 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__) +#if defined(__APPLE__) // On Mac, we ask the OS for the absolute path to the entrypoint executable uint32_t lenActualPath = 0; @@ -115,10 +101,9 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable) result = false; } #else - // On non-Mac OS, return the symlink that will be resolved by GetAbsolutePath + // On other OSs, return the symlink that will be resolved by GetAbsolutePath // to fetch the entrypoint EXE absolute path, inclusive of filename. - entrypointExecutable.assign(symlinkEntrypointExecutable); - result = true; + result = GetAbsolutePath(symlinkEntrypointExecutable, entrypointExecutable); #endif return result; -- 2.7.4