From 3b58dbbe0c83b81dd5ad1654bb2f6330f8e0f2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Fri, 15 Dec 2023 14:56:18 +0000 Subject: [PATCH] GetProgramExecutableName handles old loaders --- libc/calls/getprogramexecutablename.greg.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libc/calls/getprogramexecutablename.greg.c b/libc/calls/getprogramexecutablename.greg.c index 32422e9e8..1717ed091 100644 --- a/libc/calls/getprogramexecutablename.greg.c +++ b/libc/calls/getprogramexecutablename.greg.c @@ -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; + } } }