When launched, check fd 0 (stdin) using isatty(), bail out if not. When the tty device is re-opened, check it using isatty(), leave if not. This will help to prevent some possible races. Signed-off-by: Yann Droneaud <yann@xxxxxxxxxxx> --- login-utils/login.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index fdc8078..6918db6 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -495,6 +495,12 @@ main(int argc, char **argv) for (cnt = getdtablesize(); cnt > 2; cnt--) close(cnt); + if (!isatty(0)) { + syslog(LOG_ERR, _("FATAL: bad tty")); + sleep(1); + exit(1); + } + ttyn = ttyname(0); if (ttyn == NULL || *ttyn == '\0') { @@ -554,6 +560,12 @@ main(int argc, char **argv) openlog("login", LOG_ODELAY, LOG_AUTHPRIV); + if (!isatty(0)) { + syslog(LOG_ERR, _("FATAL: bad tty")); + sleep(1); + exit(1); + } + #if 0 /* other than iso-8859-1 */ printf("\033(K"); @@ -1216,6 +1228,13 @@ Michael Riepe <michael@xxxxxxxxxxxxxxxxxxxx> */ if (ioctl(0, TIOCSCTTY, 1)) syslog(LOG_ERR, _("TIOCSCTTY failed: %m")); + + if (!isatty(0)) { + syslog(LOG_ERR, _("FATAL: bad tty")); + sleep(1); + exit(1); + } + #endif signal(SIGINT, SIG_DFL); -- 1.6.2.5 -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html