From 32a385f5b0a74ca886e69472aaa1de8045a1ddbd Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 12 Apr 2009 13:05:40 +0000 Subject: getty: fix handling of speed 0; stop using non-portable way of setting speeds. function old new delta cfsetispeed - 76 +76 cfsetospeed - 57 +57 cfgetispeed - 20 +20 --- loginutils/getty.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'loginutils') diff --git a/loginutils/getty.c b/loginutils/getty.c index 0398ea3f9..24a182ff4 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -165,12 +165,7 @@ static void parse_speeds(struct options *op, char *arg) op->speeds[op->numspeed] = bcode(cp); if (op->speeds[op->numspeed] < 0) bb_error_msg_and_die("bad speed: %s", cp); - else if (op->speeds[op->numspeed] == 0) { - struct termios tio; - if (tcgetattr(1, &tio) != 0) - bb_error_msg_and_die("auto baudrate detection failed"); - op->speeds[op->numspeed] = cfgetospeed(&tio); - } + /* note: arg "0" turns into speed B0 */ op->numspeed++; if (op->numspeed > MAX_SPEED) bb_error_msg_and_die("too many alternate speeds"); @@ -276,6 +271,7 @@ static void open_tty(const char *tty) /* termios_init - initialize termios settings */ static void termios_init(struct termios *tp, int speed, struct options *op) { + speed_t ispeed, ospeed; /* * Initial termios settings: 8-bit characters, raw-mode, blocking i/o. * Special characters are set after we have read the login name; all @@ -286,10 +282,18 @@ static void termios_init(struct termios *tp, int speed, struct options *op) /* flush input and output queues, important for modems! */ ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */ #endif - - tp->c_cflag = CS8 | HUPCL | CREAD | speed; + ispeed = ospeed = speed; + if (speed == B0) { + /* Speed was specified as "0" on command line. + * Just leave it unchanged */ + ispeed = cfgetispeed(tp); + ospeed = cfgetospeed(tp); + } + tp->c_cflag = CS8 | HUPCL | CREAD; if (op->flags & F_LOCAL) tp->c_cflag |= CLOCAL; + cfsetispeed(tp, ispeed); + cfsetospeed(tp, ospeed); tp->c_iflag = tp->c_lflag = tp->c_line = 0; tp->c_oflag = OPOST | ONLCR; @@ -759,8 +763,8 @@ int getty_main(int argc UNUSED_PARAM, char **argv) break; /* we are here only if options.numspeed > 1 */ baud_index = (baud_index + 1) % options.numspeed; - termios.c_cflag &= ~CBAUD; - termios.c_cflag |= options.speeds[baud_index]; + cfsetispeed(&termios, options.speeds[baud_index]); + cfsetospeed(&termios, options.speeds[baud_index]); tcsetattr_stdin_TCSANOW(&termios); } } -- cgit v1.2.3