aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-23 22:43:02 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-23 22:43:02 +0000
commit703aa13ff5e2b795319a3e900c1f8df6e3da47b5 (patch)
tree861026de3497f90795ef52dfd196097a37b754c7
parent4e70bf4359676b1ecaf658c7550d60a15ec1a02a (diff)
downloadbusybox-w32-703aa13ff5e2b795319a3e900c1f8df6e3da47b5.tar.gz
busybox-w32-703aa13ff5e2b795319a3e900c1f8df6e3da47b5.tar.bz2
busybox-w32-703aa13ff5e2b795319a3e900c1f8df6e3da47b5.zip
watch: fix warning
getty: fix breakage; fix excessive stack usage
-rw-r--r--coreutils/watch.c4
-rw-r--r--loginutils/getty.c44
2 files changed, 25 insertions, 23 deletions
diff --git a/coreutils/watch.c b/coreutils/watch.c
index e3e9e06bb..b188b4176 100644
--- a/coreutils/watch.c
+++ b/coreutils/watch.c
@@ -58,8 +58,9 @@ int watch_main(int argc, char **argv)
58 time_t t; 58 time_t t;
59 59
60 get_terminal_width_height(STDOUT_FILENO, &width, 0); 60 get_terminal_width_height(STDOUT_FILENO, &width, 0);
61 if (width < 1) width = 1; // paranoia
61 header = xrealloc(header, width--); 62 header = xrealloc(header, width--);
62 // We pad with spaces entire length 63 // '%-*s' pads header with spaces to the full width
63 snprintf(header, width, "Every %ds: %-*s", period, width, cmd); 64 snprintf(header, width, "Every %ds: %-*s", period, width, cmd);
64 time(&t); 65 time(&t);
65 thyme = ctime(&t); 66 thyme = ctime(&t);
@@ -75,4 +76,5 @@ int watch_main(int argc, char **argv)
75 system(cmd); 76 system(cmd);
76 sleep(period); 77 sleep(period);
77 } 78 }
79 return 0; // gcc thinks we can reach this :)
78} 80}
diff --git a/loginutils/getty.c b/loginutils/getty.c
index 9e7cb7a10..e9b4f0755 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -409,12 +409,11 @@ static void termio_init(struct termio *tp, int speed, struct options *op)
409} 409}
410 410
411/* auto_baud - extract baud rate from modem status message */ 411/* auto_baud - extract baud rate from modem status message */
412static void auto_baud(struct termio *tp) 412static void auto_baud(char *buf, unsigned size_buf, struct termio *tp)
413{ 413{
414 int speed; 414 int speed;
415 int vmin; 415 int vmin;
416 unsigned iflag; 416 unsigned iflag;
417 char buf[BUFSIZ];
418 char *bp; 417 char *bp;
419 int nread; 418 int nread;
420 419
@@ -450,7 +449,7 @@ static void auto_baud(struct termio *tp)
450 */ 449 */
451 450
452 sleep(1); 451 sleep(1);
453 nread = read(0, buf, sizeof(buf) - 1); 452 nread = read(0, buf, size_buf - 1);
454 if (nread > 0) { 453 if (nread > 0) {
455 buf[nread] = '\0'; 454 buf[nread] = '\0';
456 for (bp = buf; bp < buf + nread; bp++) { 455 for (bp = buf; bp < buf + nread; bp++) {
@@ -504,10 +503,10 @@ static int caps_lock(const char *s)
504} 503}
505#endif 504#endif
506 505
507#define logname bb_common_bufsiz1
508/* get_logname - get user name, establish parity, speed, erase, kill, eol */ 506/* get_logname - get user name, establish parity, speed, erase, kill, eol */
509/* return NULL on failure, logname on success */ 507/* return NULL on failure, logname on success */
510static char *get_logname(struct options *op, struct chardata *cp, struct termio *tp) 508static char *get_logname(char *logname, unsigned size_logname,
509 struct options *op, struct chardata *cp, struct termio *tp)
511{ 510{
512 char *bp; 511 char *bp;
513 char c; /* input character, full eight bits */ 512 char c; /* input character, full eight bits */
@@ -532,8 +531,8 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio
532 531
533 /* Prompt for and read a login name. */ 532 /* Prompt for and read a login name. */
534 533
535 *logname = 0; 534 logname[0] = '\0';
536 while (*logname) { 535 while (!logname[0]) {
537 536
538 /* Write issue file and prompt, with "parity" bit == 0. */ 537 /* Write issue file and prompt, with "parity" bit == 0. */
539 538
@@ -542,37 +541,39 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio
542 /* Read name, watch for break, parity, erase, kill, end-of-line. */ 541 /* Read name, watch for break, parity, erase, kill, end-of-line. */
543 542
544 bp = logname; 543 bp = logname;
545 cp->eol = 0; 544 cp->eol = '\0';
546 while (cp->eol == 0) { 545 while (cp->eol == '\0') {
547 546
548 /* Do not report trivial EINTR/EIO errors. */ 547 /* Do not report trivial EINTR/EIO errors. */
549
550 if (read(0, &c, 1) < 1) { 548 if (read(0, &c, 1) < 1) {
551 if (errno == EINTR || errno == EIO) 549 if (errno == EINTR || errno == EIO)
552 exit(0); 550 exit(0);
553 bb_perror_msg_and_die("%s: read", op->tty); 551 bb_perror_msg_and_die("%s: read", op->tty);
554 } 552 }
555 /* Do BREAK handling elsewhere. */
556 553
557 if (c == 0 && op->numspeed > 1) 554 /* Do BREAK handling elsewhere. */
555 if (c == '\0' && op->numspeed > 1)
558 return NULL; 556 return NULL;
559 557
560 /* Do parity bit handling. */ 558 /* Do parity bit handling. */
561
562 ascval = c & 0177; 559 ascval = c & 0177;
563 if (c != ascval) { /* "parity" bit on ? */ 560 if (c != ascval) { /* "parity" bit on ? */
564 for (bits = 1, mask = 1; mask & 0177; mask <<= 1) 561 bits = 1;
562 mask = 1;
563 while (mask & 0177) {
565 if (mask & ascval) 564 if (mask & ascval)
566 bits++; /* count "1" bits */ 565 bits++; /* count "1" bits */
566 mask <<= 1;
567 }
567 /* ... |= 2 - even, 1 - odd */ 568 /* ... |= 2 - even, 1 - odd */
568 cp->parity |= 2 - (bits & 1); 569 cp->parity |= 2 - (bits & 1);
569 } 570 }
570 /* Do erase, kill and end-of-line processing. */
571 571
572 /* Do erase, kill and end-of-line processing. */
572 switch (ascval) { 573 switch (ascval) {
573 case CR: 574 case CR:
574 case NL: 575 case NL:
575 *bp = 0; /* terminate logname */ 576 *bp = '\0'; /* terminate logname */
576 cp->eol = ascval; /* set end-of-line char */ 577 cp->eol = ascval; /* set end-of-line char */
577 break; 578 break;
578 case BS: 579 case BS:
@@ -596,8 +597,8 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio
596 exit(0); 597 exit(0);
597 default: 598 default:
598 if (!isascii(ascval) || !isprint(ascval)) { 599 if (!isascii(ascval) || !isprint(ascval)) {
599 /* ignore garbage characters */ ; 600 /* ignore garbage characters */
600 } else if (bp - logname >= sizeof(logname) - 1) { 601 } else if (bp - logname >= size_logname - 1) {
601 bb_error_msg_and_die("%s: input overrun", op->tty); 602 bb_error_msg_and_die("%s: input overrun", op->tty);
602 } else { 603 } else {
603 write(1, &c, 1); /* echo the character */ 604 write(1, &c, 1); /* echo the character */
@@ -747,7 +748,6 @@ static void update_utmp(char *line)
747#endif /* SYSV_STYLE */ 748#endif /* SYSV_STYLE */
748 749
749 750
750#undef logname
751int getty_main(int argc, char **argv) 751int getty_main(int argc, char **argv)
752{ 752{
753 int nullfd; 753 int nullfd;
@@ -847,7 +847,7 @@ int getty_main(int argc, char **argv)
847 /* Optionally detect the baud rate from the modem status message. */ 847 /* Optionally detect the baud rate from the modem status message. */
848 debug("before autobaud\n"); 848 debug("before autobaud\n");
849 if (options.flags & F_PARSE) 849 if (options.flags & F_PARSE)
850 auto_baud(&termio); 850 auto_baud(bb_common_bufsiz1, sizeof(bb_common_bufsiz1), &termio);
851 851
852 /* Set the optional timer. */ 852 /* Set the optional timer. */
853 if (options.timeout) 853 if (options.timeout)
@@ -872,8 +872,8 @@ int getty_main(int argc, char **argv)
872 if (!(options.flags & F_NOPROMPT)) { 872 if (!(options.flags & F_NOPROMPT)) {
873 /* Read the login name. */ 873 /* Read the login name. */
874 debug("reading login name\n"); 874 debug("reading login name\n");
875 /* while ((logname = get_logname(&options, &chardata, &termio)) == 0) */ 875 logname = get_logname(bb_common_bufsiz1, sizeof(bb_common_bufsiz1),
876 logname = get_logname(&options, &chardata, &termio); 876 &options, &chardata, &termio);
877 while (logname == NULL) 877 while (logname == NULL)
878 next_speed(&termio, &options); 878 next_speed(&termio, &options);
879 } 879 }