Fix corerun issue when loaded from PATH (dotnet/coreclr#10745)
authorHadi Brais <hadi.b@live.com>
Sat, 8 Apr 2017 19:24:23 +0000 (00:54 +0530)
committerDan Moseley <danmose@microsoft.com>
Sat, 8 Apr 2017 19:24:23 +0000 (12:24 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/551a7c5563105f7ec9a9d9273204d0a07a02c4fa

src/coreclr/src/coreclr/hosts/unixcoreconsole/coreconsole.cpp
src/coreclr/src/coreclr/hosts/unixcorerun/corerun.cpp
src/coreclr/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp

index e43124d..d46f6ef 100644 (file)
@@ -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,
index da886d4..4e5c9d9 100644 (file)
@@ -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;
index 5ac7654..d40fb42 100644 (file)
@@ -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;