GetProgramExecutableName handles old loaders

This commit is contained in:
Jōshin 2023-12-15 14:56:18 +00:00
parent 860bf7ec17
commit 3b58dbbe0c
No known key found for this signature in database

View file

@ -97,14 +97,18 @@ static inline void InitProgramExecutableNameImpl(void) {
}
cmd[3] = -1; // current process
if (sys_sysctl(cmd, ARRAYLEN(cmd), b, &n, 0, 0) != -1) {
goto UseBuf;
if (strcmp(b, "/usr/bin/ape")) { // XX old loader; warn?
goto UseBuf;
}
}
}
if (IsLinux()) {
if ((got = sys_readlinkat(AT_FDCWD, "/proc/self/exe", b, n)) > 0 ||
(got = sys_readlinkat(AT_FDCWD, "/proc/curproc/file", b, n)) > 0) {
b[got] = 0;
goto UseBuf;
if (strcmp(b, "/usr/bin/ape")) {
goto UseBuf;
}
}
}