watch: fix warning

getty: fix breakage; fix excessive stack usage
This commit is contained in:
Denis Vlasenko 2006-10-23 22:43:02 +00:00
parent 4e70bf4359
commit 703aa13ff5
2 changed files with 25 additions and 23 deletions

View File

@ -58,8 +58,9 @@ int watch_main(int argc, char **argv)
time_t t; time_t t;
get_terminal_width_height(STDOUT_FILENO, &width, 0); get_terminal_width_height(STDOUT_FILENO, &width, 0);
if (width < 1) width = 1; // paranoia
header = xrealloc(header, width--); header = xrealloc(header, width--);
// We pad with spaces entire length // '%-*s' pads header with spaces to the full width
snprintf(header, width, "Every %ds: %-*s", period, width, cmd); snprintf(header, width, "Every %ds: %-*s", period, width, cmd);
time(&t); time(&t);
thyme = ctime(&t); thyme = ctime(&t);
@ -75,4 +76,5 @@ int watch_main(int argc, char **argv)
system(cmd); system(cmd);
sleep(period); sleep(period);
} }
return 0; // gcc thinks we can reach this :)
} }

View File

@ -409,12 +409,11 @@ static void termio_init(struct termio *tp, int speed, struct options *op)
} }
/* auto_baud - extract baud rate from modem status message */ /* auto_baud - extract baud rate from modem status message */
static void auto_baud(struct termio *tp) static void auto_baud(char *buf, unsigned size_buf, struct termio *tp)
{ {
int speed; int speed;
int vmin; int vmin;
unsigned iflag; unsigned iflag;
char buf[BUFSIZ];
char *bp; char *bp;
int nread; int nread;
@ -450,7 +449,7 @@ static void auto_baud(struct termio *tp)
*/ */
sleep(1); sleep(1);
nread = read(0, buf, sizeof(buf) - 1); nread = read(0, buf, size_buf - 1);
if (nread > 0) { if (nread > 0) {
buf[nread] = '\0'; buf[nread] = '\0';
for (bp = buf; bp < buf + nread; bp++) { for (bp = buf; bp < buf + nread; bp++) {
@ -504,10 +503,10 @@ static int caps_lock(const char *s)
} }
#endif #endif
#define logname bb_common_bufsiz1
/* get_logname - get user name, establish parity, speed, erase, kill, eol */ /* get_logname - get user name, establish parity, speed, erase, kill, eol */
/* return NULL on failure, logname on success */ /* return NULL on failure, logname on success */
static char *get_logname(struct options *op, struct chardata *cp, struct termio *tp) static char *get_logname(char *logname, unsigned size_logname,
struct options *op, struct chardata *cp, struct termio *tp)
{ {
char *bp; char *bp;
char c; /* input character, full eight bits */ char c; /* input character, full eight bits */
@ -532,8 +531,8 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio
/* Prompt for and read a login name. */ /* Prompt for and read a login name. */
*logname = 0; logname[0] = '\0';
while (*logname) { while (!logname[0]) {
/* Write issue file and prompt, with "parity" bit == 0. */ /* Write issue file and prompt, with "parity" bit == 0. */
@ -542,37 +541,39 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio
/* Read name, watch for break, parity, erase, kill, end-of-line. */ /* Read name, watch for break, parity, erase, kill, end-of-line. */
bp = logname; bp = logname;
cp->eol = 0; cp->eol = '\0';
while (cp->eol == 0) { while (cp->eol == '\0') {
/* Do not report trivial EINTR/EIO errors. */ /* Do not report trivial EINTR/EIO errors. */
if (read(0, &c, 1) < 1) { if (read(0, &c, 1) < 1) {
if (errno == EINTR || errno == EIO) if (errno == EINTR || errno == EIO)
exit(0); exit(0);
bb_perror_msg_and_die("%s: read", op->tty); bb_perror_msg_and_die("%s: read", op->tty);
} }
/* Do BREAK handling elsewhere. */
if (c == 0 && op->numspeed > 1) /* Do BREAK handling elsewhere. */
if (c == '\0' && op->numspeed > 1)
return NULL; return NULL;
/* Do parity bit handling. */ /* Do parity bit handling. */
ascval = c & 0177; ascval = c & 0177;
if (c != ascval) { /* "parity" bit on ? */ if (c != ascval) { /* "parity" bit on ? */
for (bits = 1, mask = 1; mask & 0177; mask <<= 1) bits = 1;
mask = 1;
while (mask & 0177) {
if (mask & ascval) if (mask & ascval)
bits++; /* count "1" bits */ bits++; /* count "1" bits */
mask <<= 1;
}
/* ... |= 2 - even, 1 - odd */ /* ... |= 2 - even, 1 - odd */
cp->parity |= 2 - (bits & 1); cp->parity |= 2 - (bits & 1);
} }
/* Do erase, kill and end-of-line processing. */
/* Do erase, kill and end-of-line processing. */
switch (ascval) { switch (ascval) {
case CR: case CR:
case NL: case NL:
*bp = 0; /* terminate logname */ *bp = '\0'; /* terminate logname */
cp->eol = ascval; /* set end-of-line char */ cp->eol = ascval; /* set end-of-line char */
break; break;
case BS: case BS:
@ -596,8 +597,8 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio
exit(0); exit(0);
default: default:
if (!isascii(ascval) || !isprint(ascval)) { if (!isascii(ascval) || !isprint(ascval)) {
/* ignore garbage characters */ ; /* ignore garbage characters */
} else if (bp - logname >= sizeof(logname) - 1) { } else if (bp - logname >= size_logname - 1) {
bb_error_msg_and_die("%s: input overrun", op->tty); bb_error_msg_and_die("%s: input overrun", op->tty);
} else { } else {
write(1, &c, 1); /* echo the character */ write(1, &c, 1); /* echo the character */
@ -747,7 +748,6 @@ static void update_utmp(char *line)
#endif /* SYSV_STYLE */ #endif /* SYSV_STYLE */
#undef logname
int getty_main(int argc, char **argv) int getty_main(int argc, char **argv)
{ {
int nullfd; int nullfd;
@ -847,7 +847,7 @@ int getty_main(int argc, char **argv)
/* Optionally detect the baud rate from the modem status message. */ /* Optionally detect the baud rate from the modem status message. */
debug("before autobaud\n"); debug("before autobaud\n");
if (options.flags & F_PARSE) if (options.flags & F_PARSE)
auto_baud(&termio); auto_baud(bb_common_bufsiz1, sizeof(bb_common_bufsiz1), &termio);
/* Set the optional timer. */ /* Set the optional timer. */
if (options.timeout) if (options.timeout)
@ -872,8 +872,8 @@ int getty_main(int argc, char **argv)
if (!(options.flags & F_NOPROMPT)) { if (!(options.flags & F_NOPROMPT)) {
/* Read the login name. */ /* Read the login name. */
debug("reading login name\n"); debug("reading login name\n");
/* while ((logname = get_logname(&options, &chardata, &termio)) == 0) */ logname = get_logname(bb_common_bufsiz1, sizeof(bb_common_bufsiz1),
logname = get_logname(&options, &chardata, &termio); &options, &chardata, &termio);
while (logname == NULL) while (logname == NULL)
next_speed(&termio, &options); next_speed(&termio, &options);
} }