diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-10-10 20:56:28 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-10-10 20:56:28 +0000 |
commit | 5b4971dc6b595a8130a272926cdd66a9d3de88f0 (patch) | |
tree | eab078c3d97f8925d8eb47f1e3ba24ed2afdc71b /libexec/identd/parse.c | |
parent | de0429a09cb344980883e035261f491cb109060b (diff) |
do not rely on a single read() to get us sufficient data. Read till newline
Diffstat (limited to 'libexec/identd/parse.c')
-rw-r--r-- | libexec/identd/parse.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/libexec/identd/parse.c b/libexec/identd/parse.c index b86a6ee0cd7..0646d607448 100644 --- a/libexec/identd/parse.c +++ b/libexec/identd/parse.c @@ -61,19 +61,38 @@ timed_read(fd, buf, siz, timeout) size_t siz; time_t timeout; { - int error; + int error, tot = 0, i, r; + char *p = buf; fd_set readfds; - struct timeval tv; - - FD_ZERO(&readfds); - FD_SET(fd, &readfds); + struct timeval tv, start, after, duration, tmp; tv.tv_sec = timeout; tv.tv_usec = 0; - if ((error = select(fd + 1, &readfds, 0, 0, &tv)) <= 0) - return error; - return(read(fd, buf, siz)); + while (1) { + FD_ZERO(&readfds); + FD_SET(fd, &readfds); + + gettimeofday(&start, NULL); + if ((error = select(fd + 1, &readfds, 0, 0, &tv)) <= 0) + return error; + r = read(fd, p, siz - tot); + if (r == -1) + return (r); + for (i = 0; i < r; i++) + if (p[i] == '\r' || p[i] == '\n') { + tot += r; + return (tot); + } + gettimeofday(&after, NULL); + timersub(&start, &after, &duration); + timersub(&tv, &duration, &tmp); + tv = tmp; + if (tv.tv_sec < 0 || !timerisset(&tv)) + return (tot); + tot += r; + p += r; + } } /* |