diff --git a/src/getty.c b/src/getty.c index ab937486..b1313180 100644 --- a/src/getty.c +++ b/src/getty.c @@ -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);