aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-01-24 00:16:50 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-01-24 00:16:50 +0100
commit1f0840450e3934cc65520ee6605b9b72df2d53f5 (patch)
treead8045e0a635f69b5523e8efe09d7b38e00b7841
parent658a437d4bd97d4897a9d0183570634a90ae6773 (diff)
downloadbusybox-w32-1f0840450e3934cc65520ee6605b9b72df2d53f5.tar.gz
busybox-w32-1f0840450e3934cc65520ee6605b9b72df2d53f5.tar.bz2
busybox-w32-1f0840450e3934cc65520ee6605b9b72df2d53f5.zip
getty: use cfsetspeed to save some bytes; cosmetic fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--loginutils/getty.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/loginutils/getty.c b/loginutils/getty.c
index 015f077d6..e60af3aa3 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -1,8 +1,7 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* agetty.c - another getty program for Linux. By W. Z. Venema 1989 2/* Based on agetty - another getty program for Linux. By W. Z. Venema 1989
3 * Ported to Linux by Peter Orbaek <poe@daimi.aau.dk> 3 * Ported to Linux by Peter Orbaek <poe@daimi.aau.dk>
4 * This program is freely distributable. The entire man-page used to 4 * This program is freely distributable.
5 * be here. Now read the real man-page agetty.8 instead.
6 * 5 *
7 * option added by Eric Rasmussen <ear@usfirst.org> - 12/28/95 6 * option added by Eric Rasmussen <ear@usfirst.org> - 12/28/95
8 * 7 *
@@ -184,7 +183,7 @@ static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:wn";
184#define F_NOPROMPT (1 << 10) /* -n */ 183#define F_NOPROMPT (1 << 10) /* -n */
185 184
186 185
187/* bcode - convert speed string to speed code; return <= 0 on failure */ 186/* convert speed string to speed code; return <= 0 on failure */
188static int bcode(const char *s) 187static int bcode(const char *s)
189{ 188{
190 int value = bb_strtou(s, NULL, 10); /* yes, int is intended! */ 189 int value = bb_strtou(s, NULL, 10); /* yes, int is intended! */
@@ -193,7 +192,7 @@ static int bcode(const char *s)
193 return tty_value_to_baud(value); 192 return tty_value_to_baud(value);
194} 193}
195 194
196/* parse_speeds - parse alternate baud rates */ 195/* parse alternate baud rates */
197static void parse_speeds(struct options *op, char *arg) 196static void parse_speeds(struct options *op, char *arg)
198{ 197{
199 char *cp; 198 char *cp;
@@ -212,7 +211,7 @@ static void parse_speeds(struct options *op, char *arg)
212 debug("exiting parse_speeds\n"); 211 debug("exiting parse_speeds\n");
213} 212}
214 213
215/* parse_args - parse command-line arguments */ 214/* parse command-line arguments */
216static void parse_args(char **argv, struct options *op, char **fakehost_p) 215static void parse_args(char **argv, struct options *op, char **fakehost_p)
217{ 216{
218 char *ts; 217 char *ts;
@@ -247,7 +246,7 @@ static void parse_args(char **argv, struct options *op, char **fakehost_p)
247 debug("exiting parse_args\n"); 246 debug("exiting parse_args\n");
248} 247}
249 248
250/* open_tty - set up tty as standard { input, output, error } */ 249/* set up tty as standard input, output, error */
251static void open_tty(const char *tty) 250static void open_tty(const char *tty)
252{ 251{
253 /* Set up new standard input, unless we are given an already opened port. */ 252 /* Set up new standard input, unless we are given an already opened port. */
@@ -273,7 +272,7 @@ static void open_tty(const char *tty)
273 } 272 }
274} 273}
275 274
276/* termios_init - initialize termios settings */ 275/* initialize termios settings */
277static void termios_init(struct termios *tp, int speed) 276static void termios_init(struct termios *tp, int speed)
278{ 277{
279 /* Flush input and output queues, important for modems! */ 278 /* Flush input and output queues, important for modems! */
@@ -282,10 +281,9 @@ static void termios_init(struct termios *tp, int speed)
282 tcflush(0, TCIOFLUSH); 281 tcflush(0, TCIOFLUSH);
283 282
284 /* Set speed if it wasn't specified as "0" on command line. */ 283 /* Set speed if it wasn't specified as "0" on command line. */
285 if (speed != B0) { 284 if (speed != B0)
286 cfsetispeed(tp, speed); 285 cfsetspeed(tp, speed);
287 cfsetospeed(tp, speed); 286
288 }
289 /* 287 /*
290 * Initial termios settings: 8-bit characters, raw-mode, blocking i/o. 288 * Initial termios settings: 8-bit characters, raw-mode, blocking i/o.
291 * Special characters are set after we have read the login name; all 289 * Special characters are set after we have read the login name; all
@@ -315,7 +313,7 @@ static void termios_init(struct termios *tp, int speed)
315 debug("term_io 2\n"); 313 debug("term_io 2\n");
316} 314}
317 315
318/* auto_baud - extract baud rate from modem status message */ 316/* extract baud rate from modem status message */
319static void auto_baud(char *buf, unsigned size_buf, struct termios *tp) 317static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
320{ 318{
321 int speed; 319 int speed;
@@ -373,19 +371,8 @@ static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
373 tcsetattr_stdin_TCSANOW(tp); 371 tcsetattr_stdin_TCSANOW(tp);
374} 372}
375 373
376/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
377static void do_prompt(struct options *op)
378{
379#ifdef ISSUE
380 if (!(option_mask32 & F_NOISSUE))
381 print_login_issue(op->issue, op->tty);
382#endif
383 print_login_prompt();
384}
385
386#ifdef HANDLE_ALLCAPS 374#ifdef HANDLE_ALLCAPS
387/* all_is_upcase - string contains upper case without lower case */ 375/* does string contain upper case without lower case? */
388/* returns 1 if true, 0 if false */
389static int all_is_upcase(const char *s) 376static int all_is_upcase(const char *s)
390{ 377{
391 while (*s) 378 while (*s)
@@ -395,7 +382,7 @@ static int all_is_upcase(const char *s)
395} 382}
396#endif 383#endif
397 384
398/* get_logname - get user name, establish parity, speed, erase, kill, eol; 385/* get user name, establish parity, speed, erase, kill, eol;
399 * return NULL on BREAK, logname on success */ 386 * return NULL on BREAK, logname on success */
400static char *get_logname(char *logname, unsigned size_logname, 387static char *get_logname(char *logname, unsigned size_logname,
401 struct options *op, struct chardata *cp) 388 struct options *op, struct chardata *cp)
@@ -422,7 +409,11 @@ static char *get_logname(char *logname, unsigned size_logname,
422 logname[0] = '\0'; 409 logname[0] = '\0';
423 while (!logname[0]) { 410 while (!logname[0]) {
424 /* Write issue file and prompt. */ 411 /* Write issue file and prompt. */
425 do_prompt(op); 412#ifdef ISSUE
413 if (!(option_mask32 & F_NOISSUE))
414 print_login_issue(op->issue, op->tty);
415#endif
416 print_login_prompt();
426 417
427 /* Read name, watch for break, parity, erase, kill, end-of-line. */ 418 /* Read name, watch for break, parity, erase, kill, end-of-line. */
428 bp = logname; 419 bp = logname;
@@ -522,7 +513,7 @@ static char *get_logname(char *logname, unsigned size_logname,
522 return logname; 513 return logname;
523} 514}
524 515
525/* termios_final - set the final tty mode bits */ 516/* set the final tty mode bits */
526static void termios_final(struct termios *tp, struct chardata *cp) 517static void termios_final(struct termios *tp, struct chardata *cp)
527{ 518{
528 /* General terminal-independent stuff. */ 519 /* General terminal-independent stuff. */
@@ -730,8 +721,7 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
730 break; 721 break;
731 /* we are here only if options.numspeed > 1 */ 722 /* we are here only if options.numspeed > 1 */
732 baud_index = (baud_index + 1) % options.numspeed; 723 baud_index = (baud_index + 1) % options.numspeed;
733 cfsetispeed(&termios, options.speeds[baud_index]); 724 cfsetspeed(&termios, options.speeds[baud_index]);
734 cfsetospeed(&termios, options.speeds[baud_index]);
735 tcsetattr_stdin_TCSANOW(&termios); 725 tcsetattr_stdin_TCSANOW(&termios);
736 } 726 }
737 } 727 }