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

diff --git a/loginutils/getty.c b/loginutils/getty.c
index 0398ea3..24a182f 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -165,12 +165,7 @@
 		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 @@
 /* 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 @@
 	/* 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 @@
 				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);
 		}
 	}