mirror of
https://github.com/troglobit/finit.git
synced 2026-10-12 10:12:32 +00:00
getty: attempt to steal ctty if don't already have it
This fixes the following classic problem
login: root
-sh: can't access tty; job control turned off
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -198,6 +198,7 @@ static int getty(char *tty, speed_t speed, char *term, char *user)
|
||||
{
|
||||
const char cln[] = "\r\e[2K\n";
|
||||
char name[33]; /* useradd(1) limit at 32 chars */
|
||||
pid_t sid;
|
||||
|
||||
/*
|
||||
* Clean up tty name.
|
||||
@@ -219,6 +220,13 @@ restart:
|
||||
} else
|
||||
strlcpy(name, user, sizeof(name));
|
||||
|
||||
/* check current session associated with our tty */
|
||||
sid = tcgetsid(0);
|
||||
if (sid < 0 || getpid() != sid) {
|
||||
if (ioctl(STDIN_FILENO, TIOCSCTTY, 1) == -1)
|
||||
err(1, "failed stealing controlling TTY");
|
||||
}
|
||||
|
||||
if (term && term[0])
|
||||
setenv("TERM", term, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user