From 568cfdbda778291ba306ba7cd23a827e35404ec3 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 12 Nov 2021 04:20:31 +0100 Subject: [PATCH] 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'). --- src/cmd/ksh93/sh/init.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 1a7f686fe..5e263730c 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -1164,16 +1164,16 @@ int sh_type(register const char *path) } break; } +#if _WINIX + if (!(t & SH_TYPE_KSH) && *s == 's' && *(s+1) == 'h' && (!*(s+2) || *(s+2) == '.')) +#else + if (!(t & SH_TYPE_KSH) && *s == 's' && *(s+1) == 'h' && !*(s+2)) +#endif + t |= SH_TYPE_POSIX; if (*s++ == 's' && (*s == 'h' || *s == 'u')) { s++; t |= SH_TYPE_SH; -#if _WINIX - if (!(t & SH_TYPE_KSH) && (!*s || *s == '.')) -#else - if (!(t & SH_TYPE_KSH) && !*s) -#endif - t |= SH_TYPE_POSIX; if ((t & SH_TYPE_KSH) && *s == '9' && *(s+1) == '3') s += 2; #if _WINIX