Skip to content

Commit d160abc

Browse files
committed
sh_type(): Do not set POSIX mode when invoked as su
On Linux, the 'su' program sets $0 to '-su' when doing 'su -' or 'su - username'. When ksh is the target account's default shell, this caused ksh to consider itself to be launched as a standard POSIX sh, which (among other things) disables the default aliases on interactive shells. This caused confusion for at least one user as they lost their 'history' alias after 'su -': https://www.linuxquestions.org/questions/slackware-14/in-current-with-downgrade-to-ksh93-lost-the-alias-history-4175703408/ bash does not consider itself to be sh when invoked as su, so ksh probably shouldn't, either. The behaviour was also undocumented, making it even more surprising. src/cmd/ksh93/sh/init.c: sh_type(): - Only set the SH_TYPE_POSIX bit if we're invoked as 'sh' (or, on windows, as 'sh.exe').
1 parent 4e151e3 commit d160abc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/cmd/ksh93/sh/init.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,16 +1164,16 @@ int sh_type(register const char *path)
11641164
}
11651165
break;
11661166
}
1167+
#if _WINIX
1168+
if (!(t & SH_TYPE_KSH) && *s == 's' && *(s+1) == 'h' && (!*(s+2) || *(s+2) == '.'))
1169+
#else
1170+
if (!(t & SH_TYPE_KSH) && *s == 's' && *(s+1) == 'h' && !*(s+2))
1171+
#endif
1172+
t |= SH_TYPE_POSIX;
11671173
if (*s++ == 's' && (*s == 'h' || *s == 'u'))
11681174
{
11691175
s++;
11701176
t |= SH_TYPE_SH;
1171-
#if _WINIX
1172-
if (!(t & SH_TYPE_KSH) && (!*s || *s == '.'))
1173-
#else
1174-
if (!(t & SH_TYPE_KSH) && !*s)
1175-
#endif
1176-
t |= SH_TYPE_POSIX;
11771177
if ((t & SH_TYPE_KSH) && *s == '9' && *(s+1) == '3')
11781178
s += 2;
11791179
#if _WINIX

0 commit comments

Comments
 (0)