diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-13 01:19:11 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-13 01:19:11 +0300 |
commit | d162a7b978a98b910e410dc10a40d5de12db0419 (patch) | |
tree | 63271dbbe027b26692befba9944d0554b00968d0 /loginutils | |
parent | 004cefa918483513a9eca13e7701c74dff160e95 (diff) |
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>
Diffstat (limited to 'loginutils')
-rw-r--r-- | loginutils/sulogin.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 69d8b5ec7..5f1c1178f 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -28,6 +28,7 @@ int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int sulogin_main(int argc UNUSED_PARAM, char **argv) { + int tsid; int timeout = 0; struct passwd *pwd; const char *shell; @@ -88,6 +89,28 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) if (!shell) shell = pwd->pw_shell; + /* util-linux 2.36.1 compat: cd to root's HOME, set a few envvars */ + setup_environment(shell, SETUP_ENV_CHANGEENV | SETUP_ENV_CHANGEENV_LOGNAME, pwd); + // no SETUP_ENV_CLEARENV + // SETUP_ENV_CHANGEENV[+LOGNAME] - set HOME, SHELL, USER,and LOGNAME + // no SETUP_ENV_NO_CHDIR - IOW: cd to $HOME + + /* util-linux 2.36.1 compat: steal ctty if we don't have it yet + * (yes, util-linux uses force=1) */ + tsid = tcgetsid(STDIN_FILENO); + if (tsid < 0 || getpid() != tsid) { + if (ioctl(STDIN_FILENO, TIOCSCTTY, /*force:*/ (long)1) != 0) { +// bb_perror_msg("TIOCSCTTY1 tsid:%d", tsid); + if (setsid() > 0) { +// bb_error_msg("done setsid()"); + /* If it still does not work, ignore */ + if (ioctl(STDIN_FILENO, TIOCSCTTY, /*force:*/ (long)1) != 0) { +// bb_perror_msg("TIOCSCTTY2 tsid:%d", tsid); + } + } + } + } + /* Exec login shell with no additional parameters. Never returns. */ exec_login_shell(shell); } |