diff options
author | Kris Kennaway <kris@FreeBSD.org> | 2001-07-23 22:10:45 +0000 |
---|---|---|
committer | Kris Kennaway <kris@FreeBSD.org> | 2001-07-23 22:10:45 +0000 |
commit | 5ff1744f11aaf52d3ce4a1fae0af4a2956c3995a (patch) | |
tree | 5315bfcdcd1c42ad8f0866b1d2d4bc83213cfbfa /libexec/telnetd/utility.c | |
parent | 61d47fa86656efb2fea404e1a1e9e76c609e4547 (diff) | |
download | src-5ff1744f11aaf52d3ce4a1fae0af4a2956c3995a.tar.gz src-5ff1744f11aaf52d3ce4a1fae0af4a2956c3995a.zip |
MFC^2: Correct semantics of output_data*() and netflush() to ensure
deterministic operation
Notes
Notes:
svn path=/stable/3/; revision=80227
Diffstat (limited to 'libexec/telnetd/utility.c')
-rw-r--r-- | libexec/telnetd/utility.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/libexec/telnetd/utility.c b/libexec/telnetd/utility.c index 69a61b3b88c1..677dadbdae68 100644 --- a/libexec/telnetd/utility.c +++ b/libexec/telnetd/utility.c @@ -62,10 +62,9 @@ static const char rcsid[] = void ttloop() { - void netflush(); DIAG(TD_REPORT, output_data("td: ttloop\r\n")); - if (nfrontp-nbackp) { + if (nfrontp - nbackp > 0) { netflush(); } ncc = read(net, netibuf, sizeof netibuf); @@ -242,10 +241,13 @@ netflush() int n; extern int not42; - if ((n = nfrontp - nbackp) > 0) { + while ((n = nfrontp - nbackp) > 0) { +#if 0 + /* XXX This causes output_data() to recurse and die */ DIAG(TD_REPORT, { n += output_data("td: netflush %d chars\r\n", n); }); +#endif /* * if no urgent data, or if the other side appears to be an * old 4.2 client (and thus unable to survive TCP urgent data), @@ -269,18 +271,19 @@ netflush() n = send(net, nbackp, n, MSG_OOB); /* URGENT data */ } } - } - if (n < 0) { - if (errno == EWOULDBLOCK || errno == EINTR) - return; - cleanup(0); - } - nbackp += n; - if (nbackp >= neturg) { - neturg = 0; - } - if (nbackp == nfrontp) { - nbackp = nfrontp = netobuf; + if (n == -1) { + if (errno == EWOULDBLOCK || errno == EINTR) + continue; + cleanup(0); + /* NOTREACHED */ + } + nbackp += n; + if (nbackp >= neturg) { + neturg = 0; + } + if (nbackp == nfrontp) { + nbackp = nfrontp = netobuf; + } } return; } /* end of netflush */ |