From 42bf4d2a9f4f931aa2cfe98968456702b545f005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Fri, 15 Dec 2023 17:06:48 +0000 Subject: [PATCH] Prioritize argv[0] Using `COSMOPOLITAN_PROGRAM_EXECUTABLE` without a `sys_faccessat` was rightly causing test failures. Now that it is no longer used by the loader, there seems little value in prioritizing it over argv[0], so just lump it in with "_". --- libc/calls/getprogramexecutablename.greg.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libc/calls/getprogramexecutablename.greg.c b/libc/calls/getprogramexecutablename.greg.c index 42c5b8fd1..05c690b98 100644 --- a/libc/calls/getprogramexecutablename.greg.c +++ b/libc/calls/getprogramexecutablename.greg.c @@ -116,12 +116,6 @@ static inline void InitProgramExecutableNameImpl(void) { goto UseEmpty; } - /* the previous loader supplied the full program path as the first - environment variable. */ - if ((q = __getenv(__envp, "COSMOPOLITAN_PROGRAM_EXECUTABLE").s)) { - goto CopyString; - } - // if argv[0] exists then turn it into an absolute path. we also try // adding a .com suffix since the ape auto-appends it when resolving if ((q = __argv[0])) { @@ -149,8 +143,10 @@ static inline void InitProgramExecutableNameImpl(void) { if (!sys_faccessat(AT_FDCWD, g_prog.u.buf, F_OK, 0)) goto UseBuf; } - // if getenv("_") exists then use that - if ((q = __getenv(__envp, "_").s)) { + /* the previous loader supplied the full program path as the first + environment variable. we also try "_". */ + if ((q = __getenv(__envp, "COSMOPOLITAN_PROGRAM_EXECUTABLE").s) || + (q = __getenv(__envp, "_").s)) { goto CopyString; }