Skip to content

Commit

Permalink
Move AT_EXECFN to fallback for /proc/self/exe (#78958)
Browse files Browse the repository at this point in the history
* Move AT_EXECFN to fallback for /proc/self/exe

* Update src/native/minipal/getexepath.h
  • Loading branch information
am11 authored Nov 30, 2022
1 parent 5553691 commit 8f543a1
Showing 1 changed file with 17 additions and 8 deletions.
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

0 comments on commit 8f543a1

Please sign in to comment.