sulogin: increase util-linux compatibility

Change to root's HOME. Set some envvars. Steal ctty if necessary and possible.

function                                             old     new   delta
sulogin_main                                         240     340    +100
setup_environment                                    225     233      +8
su_main                                              479     474      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 108/-5)            Total: 103 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2022-01-12 23:19:11 +01:00
parent 004cefa918
commit d162a7b978
3 changed files with 37 additions and 12 deletions

View File

@@ -54,15 +54,15 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass
xsetenv("TERM", term);
xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path));
goto shortcut;
// No, gcc (4.2.1) is not clever enougn to do it itself.
// No, gcc (4.2.1) is not clever enough to do it itself.
//xsetenv("USER", pw->pw_name);
//xsetenv("LOGNAME", pw->pw_name);
//xsetenv("HOME", pw->pw_dir);
//xsetenv("SHELL", shell);
} else if (flags & SETUP_ENV_CHANGEENV) {
/* Set HOME, SHELL, and if not becoming a super-user,
* USER and LOGNAME. */
if (pw->pw_uid) {
/* Set HOME, SHELL, and if not becoming a super-user
* or if SETUP_ENV_CHANGEENV_LOGNAME, USER and LOGNAME. */
if ((flags & SETUP_ENV_CHANGEENV_LOGNAME) || pw->pw_uid != 0) {
shortcut:
xsetenv("USER", pw->pw_name);
xsetenv("LOGNAME", pw->pw_name);