Skip to content

Commit 0bb5bcd

Browse files
committed
back out dash_l insertion
1 parent eddc8c7 commit 0bb5bcd

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

ape/ape-m1.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ int main(int argc, char **argv, char **envp) {
885885
long *sp, *sp2, *auxv;
886886
union ElfEhdrBuf *ebuf;
887887
int c, islogin, n, fd, rc;
888-
char *p, *pe, *dash_l, *exe, *prog, *shell, *execfn;
888+
char *p, *pe, *exe, *prog, *shell, *execfn;
889889

890890
/* allocate loader memory in program's arg block */
891891
n = sizeof(struct ApeLoader);
@@ -971,29 +971,17 @@ int main(int argc, char **argv, char **envp) {
971971
system v abi aligns this on a 16-byte boundary
972972
grows down the alloc by poking the guard pages */
973973

974-
if (islogin) {
975-
dash_l = __builtin_alloca(3);
976-
}
977-
n = (auxv - sp + islogin + AUXV_WORDS + 1) * sizeof(long);
974+
n = (auxv - sp + AUXV_WORDS + 1) * sizeof(long);
978975
sp2 = (long *)__builtin_alloca(n);
979976
if ((long)sp2 & 15) ++sp2;
980977
for (; n > 0; n -= pagesz) {
981978
((char *)sp2)[n - 1] = 0;
982979
}
983-
if (islogin) {
984-
memmove(sp2, sp, 2 * sizeof(long));
985-
memmove(dash_l, "-l", 3);
986-
*((char **)sp2 + 2) = dash_l;
987-
memmove(sp2 + 3, sp + 2, (auxv - sp - 2) * sizeof(long));
988-
++argc;
989-
sp2[0] = argc;
990-
} else {
991-
memmove(sp2, sp, (auxv - sp) * sizeof(long));
992-
}
980+
memmove(sp2, sp, (auxv - sp) * sizeof(long));
993981

994982
argv = (char **)(sp2 + 1);
995983
envp = (char **)(sp2 + 1 + argc + 1);
996-
auxv = sp2 + (auxv - sp) + 1;
984+
auxv = sp2 + (auxv - sp);
997985
sp = sp2;
998986

999987
/* interpret command line arguments */
@@ -1008,13 +996,9 @@ int main(int argc, char **argv, char **envp) {
1008996
but it will if you say:
1009997
ln -sf /usr/local/bin/ape /opt/cosmos/bin/bash.ape
1010998
and then use #!/opt/cosmos/bin/bash.ape instead. */
1011-
prog = (char *)sp[1];
999+
prog = islogin ? shell : (char *)sp[1];
10121000
argc = sp[0];
10131001
argv = (char **)(sp + 1);
1014-
if (islogin) {
1015-
++argv[0];
1016-
prog = shell;
1017-
}
10181002
} else if ((M->ps.literally = argc >= 3 && !StrCmp(argv[1], "-"))) {
10191003
/* if the first argument is a hyphen then we give the user the
10201004
power to change argv[0] or omit it entirely. most operating
@@ -1056,9 +1040,13 @@ int main(int argc, char **argv, char **envp) {
10561040
}
10571041
pe = ebuf->buf + rc;
10581042

1059-
/* resolve argv[0] to reflect path search */
1060-
if (argc > 0 && ((*prog != '/' && *exe == '/' && !StrCmp(prog, argv[0])) ||
1061-
M->ps.indirect || !StrCmp(BaseName(prog), argv[0]))) {
1043+
if (islogin) {
1044+
/* TODO: this does not work: setenv("_", exe, 1); */
1045+
argv[0] = exe;
1046+
} else if (argc > 0 &&
1047+
((*prog != '/' && *exe == '/' && !StrCmp(prog, argv[0])) ||
1048+
!StrCmp(BaseName(prog), argv[0]))) {
1049+
/* resolve argv[0] to reflect path search */
10621050
argv[0] = exe;
10631051
}
10641052

0 commit comments

Comments
 (0)