@@ -885,7 +885,7 @@ int main(int argc, char **argv, char **envp) {
885
885
long * sp , * sp2 , * auxv ;
886
886
union ElfEhdrBuf * ebuf ;
887
887
int c , islogin , n , fd , rc ;
888
- char * p , * pe , * dash_l , * exe , * prog , * shell , * execfn ;
888
+ char * p , * pe , * exe , * prog , * shell , * execfn ;
889
889
890
890
/* allocate loader memory in program's arg block */
891
891
n = sizeof (struct ApeLoader );
@@ -971,29 +971,17 @@ int main(int argc, char **argv, char **envp) {
971
971
system v abi aligns this on a 16-byte boundary
972
972
grows down the alloc by poking the guard pages */
973
973
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 );
978
975
sp2 = (long * )__builtin_alloca (n );
979
976
if ((long )sp2 & 15 ) ++ sp2 ;
980
977
for (; n > 0 ; n -= pagesz ) {
981
978
((char * )sp2 )[n - 1 ] = 0 ;
982
979
}
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 ));
993
981
994
982
argv = (char * * )(sp2 + 1 );
995
983
envp = (char * * )(sp2 + 1 + argc + 1 );
996
- auxv = sp2 + (auxv - sp ) + 1 ;
984
+ auxv = sp2 + (auxv - sp );
997
985
sp = sp2 ;
998
986
999
987
/* interpret command line arguments */
@@ -1008,13 +996,9 @@ int main(int argc, char **argv, char **envp) {
1008
996
but it will if you say:
1009
997
ln -sf /usr/local/bin/ape /opt/cosmos/bin/bash.ape
1010
998
and then use #!/opt/cosmos/bin/bash.ape instead. */
1011
- prog = (char * )sp [1 ];
999
+ prog = islogin ? shell : (char * )sp [1 ];
1012
1000
argc = sp [0 ];
1013
1001
argv = (char * * )(sp + 1 );
1014
- if (islogin ) {
1015
- ++ argv [0 ];
1016
- prog = shell ;
1017
- }
1018
1002
} else if ((M -> ps .literally = argc >= 3 && !StrCmp (argv [1 ], "-" ))) {
1019
1003
/* if the first argument is a hyphen then we give the user the
1020
1004
power to change argv[0] or omit it entirely. most operating
@@ -1056,9 +1040,13 @@ int main(int argc, char **argv, char **envp) {
1056
1040
}
1057
1041
pe = ebuf -> buf + rc ;
1058
1042
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 */
1062
1050
argv [0 ] = exe ;
1063
1051
}
1064
1052
0 commit comments