aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-12 13:05:40 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-12 13:05:40 +0000
commit32a385f5b0a74ca886e69472aaa1de8045a1ddbd (patch)
treee23b4fba7e4a7264f642e7577a669469feedbf9a
parent5c3299300905698c45d1ace64a61a431312993a4 (diff)
downloadbusybox-w32-32a385f5b0a74ca886e69472aaa1de8045a1ddbd.tar.gz
busybox-w32-32a385f5b0a74ca886e69472aaa1de8045a1ddbd.tar.bz2
busybox-w32-32a385f5b0a74ca886e69472aaa1de8045a1ddbd.zip
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
-rw-r--r--loginutils/getty.c24
1 files changed, 14 insertions, 10 deletions
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)
165 op->speeds[op->numspeed] = bcode(cp); 165 op->speeds[op->numspeed] = bcode(cp);
166 if (op->speeds[op->numspeed] < 0) 166 if (op->speeds[op->numspeed] < 0)
167 bb_error_msg_and_die("bad speed: %s", cp); 167 bb_error_msg_and_die("bad speed: %s", cp);
168 else if (op->speeds[op->numspeed] == 0) { 168 /* note: arg "0" turns into speed B0 */
169 struct termios tio;
170 if (tcgetattr(1, &tio) != 0)
171 bb_error_msg_and_die("auto baudrate detection failed");
172 op->speeds[op->numspeed] = cfgetospeed(&tio);
173 }
174 op->numspeed++; 169 op->numspeed++;
175 if (op->numspeed > MAX_SPEED) 170 if (op->numspeed > MAX_SPEED)
176 bb_error_msg_and_die("too many alternate speeds"); 171 bb_error_msg_and_die("too many alternate speeds");
@@ -276,6 +271,7 @@ static void open_tty(const char *tty)
276/* termios_init - initialize termios settings */ 271/* termios_init - initialize termios settings */
277static void termios_init(struct termios *tp, int speed, struct options *op) 272static void termios_init(struct termios *tp, int speed, struct options *op)
278{ 273{
274 speed_t ispeed, ospeed;
279 /* 275 /*
280 * Initial termios settings: 8-bit characters, raw-mode, blocking i/o. 276 * Initial termios settings: 8-bit characters, raw-mode, blocking i/o.
281 * Special characters are set after we have read the login name; all 277 * 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)
286 /* flush input and output queues, important for modems! */ 282 /* flush input and output queues, important for modems! */
287 ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */ 283 ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */
288#endif 284#endif
289 285 ispeed = ospeed = speed;
290 tp->c_cflag = CS8 | HUPCL | CREAD | speed; 286 if (speed == B0) {
287 /* Speed was specified as "0" on command line.
288 * Just leave it unchanged */
289 ispeed = cfgetispeed(tp);
290 ospeed = cfgetospeed(tp);
291 }
292 tp->c_cflag = CS8 | HUPCL | CREAD;
291 if (op->flags & F_LOCAL) 293 if (op->flags & F_LOCAL)
292 tp->c_cflag |= CLOCAL; 294 tp->c_cflag |= CLOCAL;
295 cfsetispeed(tp, ispeed);
296 cfsetospeed(tp, ospeed);
293 297
294 tp->c_iflag = tp->c_lflag = tp->c_line = 0; 298 tp->c_iflag = tp->c_lflag = tp->c_line = 0;
295 tp->c_oflag = OPOST | ONLCR; 299 tp->c_oflag = OPOST | ONLCR;
@@ -759,8 +763,8 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
759 break; 763 break;
760 /* we are here only if options.numspeed > 1 */ 764 /* we are here only if options.numspeed > 1 */
761 baud_index = (baud_index + 1) % options.numspeed; 765 baud_index = (baud_index + 1) % options.numspeed;
762 termios.c_cflag &= ~CBAUD; 766 cfsetispeed(&termios, options.speeds[baud_index]);
763 termios.c_cflag |= options.speeds[baud_index]; 767 cfsetospeed(&termios, options.speeds[baud_index]);
764 tcsetattr_stdin_TCSANOW(&termios); 768 tcsetattr_stdin_TCSANOW(&termios);
765 } 769 }
766 } 770 }