Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] Move AT_EXECFN to fallback for /proc/self/exe #79057

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/native/minipal/getexepath.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,30 @@ static inline char* minipal_getexepath(void)
// This is a packaging convention that our tooling should enforce.
return strdup("/managed");
#else
#if HAVE_GETAUXVAL && defined(AT_EXECFN)
const char* path = (const char *)(getauxval(AT_EXECFN));
if (path && !errno)
{
return realpath(path, NULL);
}
#endif // HAVE_GETAUXVAL && defined(AT_EXECFN)
#ifdef __linux__
const char* symlinkEntrypointExecutable = "/proc/self/exe";
#else
const char* symlinkEntrypointExecutable = "/proc/curproc/exe";
#endif

// Resolve the symlink to the executable from /proc
return realpath(symlinkEntrypointExecutable, NULL);
char* path = realpath(symlinkEntrypointExecutable, NULL);
if (path)
{
return path;
}

#if HAVE_GETAUXVAL && defined(AT_EXECFN)
// fallback to AT_EXECFN, which does not work properly in rare cases
// when .NET process is set as interpreter (shebang).
const char* exePath = (const char *)(getauxval(AT_EXECFN));
if (exePath && !errno)
{
return realpath(exePath, NULL);
}
#endif // HAVE_GETAUXVAL && defined(AT_EXECFN)

return NULL;
#endif // defined(__APPLE__)
}

Expand Down