1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

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').
This commit is contained in:
Martijn Dekker 2021-11-12 04:20:31 +01:00
parent 3a5752218d
commit 568cfdbda7

View file

@ -1164,16 +1164,16 @@ int sh_type(register const char *path)
} }
break; 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')) if (*s++ == 's' && (*s == 'h' || *s == 'u'))
{ {
s++; s++;
t |= SH_TYPE_SH; 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') if ((t & SH_TYPE_KSH) && *s == '9' && *(s+1) == '3')
s += 2; s += 2;
#if _WINIX #if _WINIX