From 53e0ff91d3e03ee52bf409d52a9d16315984b966 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Wed, 22 Apr 2009 20:12:06 +0000 Subject: [PATCH] * src/login.c: If we cannot get the terminal configuration, do not change the terminal configuration. setup_tty() is just a best effort configuration of the terminal. * src/login.c: Ignore failures when setting the terminal configuration. * src/login.c: Fail if the ERASECHAR or KILLCHAR configurations are not compatible with a cc_t type. --- ChangeLog | 10 ++++++++++ src/login.c | 28 ++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f4ae899..6fcbd8ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-04-22 Nicolas François + + * src/login.c: If we cannot get the terminal configuration, do not + change the terminal configuration. setup_tty() is just a best + effort configuration of the terminal. + * src/login.c: Ignore failures when setting the terminal + configuration. + * src/login.c: Fail if the ERASECHAR or KILLCHAR configurations + are not compatible with a cc_t type. + 2009-04-22 Paul Szabo * src/login.c: utent might be NULL after get_current_utmp(). diff --git a/src/login.c b/src/login.c index 251b526c..3791a0cf 100644 --- a/src/login.c +++ b/src/login.c @@ -165,8 +165,10 @@ static void usage (void) static void setup_tty (void) { TERMIO termio; + int erasechar; + int killchar; - GTTY (0, &termio); /* get terminal characteristics */ + if (GTTY (0, &termio) == 0) { /* get terminal characteristics */ /* * Add your favorite terminal modes here ... @@ -185,14 +187,32 @@ static void setup_tty (void) #endif /* leave these values unchanged if not specified in login.defs */ - termio.c_cc[VERASE] = getdef_num ("ERASECHAR", termio.c_cc[VERASE]); - termio.c_cc[VKILL] = getdef_num ("KILLCHAR", termio.c_cc[VKILL]); + erasechar = getdef_num ("ERASECHAR", (int) termio.c_cc[VERASE]); + killchar = getdef_num ("KILLCHAR", (int) termio.c_cc[VKILL]); + termio.c_cc[VERASE] = (cc_t) erasechar; + termio.c_cc[VKILL] = (cc_t) killchar; + /* Make sure the values were valid. + * getdef_num cannot validate this. + */ + if (erasechar != termio.c_cc[VERASE]) { + fprintf (stderr, + _("configuration error - cannot parse %s value: '%d'"), + "ERASECHAR", erasechar); + exit (1); + } + if (killchar != termio.c_cc[VKILL]) { + fprintf (stderr, + _("configuration error - cannot parse %s value: '%d'"), + "KILLCHAR", killchar); + exit (1); + } /* * ttymon invocation prefers this, but these settings won't come into * effect after the first username login */ - STTY (0, &termio); + (void) STTY (0, &termio); + } }