Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 551a7c5

Browse files
hadibraisdanmoseley
authored andcommitted
Fix corerun issue when loaded from PATH (#10745)
1 parent 1ed5cf1 commit 551a7c5

File tree

3 files changed

+7
-29
lines changed

3 files changed

+7
-29
lines changed

src/coreclr/hosts/unixcoreconsole/coreconsole.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ bool ParseArguments(
9393
int main(const int argc, const char* argv[])
9494
{
9595
// Make sure we have a full path for argv[0].
96-
std::string argv0AbsolutePath;
9796
std::string entryPointExecutablePath;
9897

9998
if (!GetEntrypointExecutableAbsolutePath(entryPointExecutablePath))
@@ -102,15 +101,9 @@ int main(const int argc, const char* argv[])
102101
return -1;
103102
}
104103

105-
if (!GetAbsolutePath(entryPointExecutablePath.c_str(), argv0AbsolutePath))
106-
{
107-
perror("Could not normalize full path to current executable");
108-
return -1;
109-
}
110-
111104
// We will try to load the managed assembly with the same name as this executable
112105
// but with the .dll extension.
113-
std::string programPath(argv0AbsolutePath);
106+
std::string programPath(entryPointExecutablePath);
114107
programPath.append(".dll");
115108
const char* managedAssemblyAbsolutePath = programPath.c_str();
116109

@@ -146,13 +139,13 @@ int main(const int argc, const char* argv[])
146139
}
147140

148141
std::string clrFilesAbsolutePath;
149-
if(!GetClrFilesAbsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath))
142+
if(!GetClrFilesAbsolutePath(entryPointExecutablePath.c_str(), clrFilesPath, clrFilesAbsolutePath))
150143
{
151144
return -1;
152145
}
153146

154147
int exitCode = ExecuteManagedAssembly(
155-
argv0AbsolutePath.c_str(),
148+
entryPointExecutablePath.c_str(),
156149
clrFilesAbsolutePath.c_str(),
157150
managedAssemblyAbsolutePath,
158151
managedAssemblyArgc,

src/coreclr/hosts/unixcorerun/corerun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int corerun(const int argc, const char* argv[])
127127

128128
// Make sure we have a full path for argv[0].
129129
std::string argv0AbsolutePath;
130-
if (!GetAbsolutePath(argv[0], argv0AbsolutePath))
130+
if (!GetEntrypointExecutableAbsolutePath(argv0AbsolutePath))
131131
{
132132
perror("Could not get full path");
133133
return -1;

src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,7 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable)
4949

5050
// Get path to the executable for the current process using
5151
// platform specific means.
52-
#if defined(__linux__) || (defined(__NetBSD__) && !defined(KERN_PROC_PATHNAME))
53-
// On Linux, fetch the entry point EXE absolute path, inclusive of filename.
54-
char exe[PATH_MAX];
55-
ssize_t res = readlink(symlinkEntrypointExecutable, exe, PATH_MAX - 1);
56-
if (res != -1)
57-
{
58-
exe[res] = '\0';
59-
entrypointExecutable.assign(exe);
60-
result = true;
61-
}
62-
else
63-
{
64-
result = false;
65-
}
66-
#elif defined(__APPLE__)
52+
#if defined(__APPLE__)
6753

6854
// On Mac, we ask the OS for the absolute path to the entrypoint executable
6955
uint32_t lenActualPath = 0;
@@ -115,10 +101,9 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable)
115101
result = false;
116102
}
117103
#else
118-
// On non-Mac OS, return the symlink that will be resolved by GetAbsolutePath
104+
// On other OSs, return the symlink that will be resolved by GetAbsolutePath
119105
// to fetch the entrypoint EXE absolute path, inclusive of filename.
120-
entrypointExecutable.assign(symlinkEntrypointExecutable);
121-
result = true;
106+
result = GetAbsolutePath(symlinkEntrypointExecutable, entrypointExecutable);
122107
#endif
123108

124109
return result;

0 commit comments

Comments
 (0)