execfn is _ or else prog

This commit is contained in:
Jōshin 2024-01-07 01:25:39 -05:00
parent f55d67967f
commit d73e77d079
No known key found for this signature in database

View file

@ -954,7 +954,7 @@ int main(int argc, char **argv, char **envp) {
M->lib.dlerror = dlerror;
/* getenv("_") is close enough to at_execfn */
execfn = argc > 0 ? argv[0] : 0;
execfn = 0;
for (i = 0; envp[i]; ++i) {
if (envp[i][0] == '_' && envp[i][1] == '=') {
execfn = envp[i] + 2;
@ -993,9 +993,6 @@ int main(int argc, char **argv, char **envp) {
ln -sf /usr/local/bin/ape /opt/cosmos/bin/bash.ape
and then use #!/opt/cosmos/bin/bash.ape instead. */
M->ps.literally = 0;
if (!execfn) {
execfn = prog;
}
argc = sp[0];
argv = (char **)(sp + 1);
} else if ((M->ps.literally = argc >= 3 && !StrCmp(argv[1], "-"))) {
@ -1019,6 +1016,9 @@ int main(int argc, char **argv, char **envp) {
argc = sp[1] = sp[0] - 1;
argv = (char **)((sp += 1) + 1);
}
if (!execfn) {
execfn = prog;
}
/* allocate ephemeral memory for reading file */
n = sizeof(union ElfEhdrBuf);