summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2012-08-16 15:43:34 -0700
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2012-08-19 08:51:49 -0700
commit2141f21d51b0787c8d287bb50d01a6a81e61a634 (patch)
treeb695da93b0d04593c063b30e8e9274a38fcba28d
parent73d62f1aaea4a862cc512048cb6ca59586f4cdb6 (diff)
XQuartz: console_redirect: Set the correct location for reading into the buffer
Prior to this change, it was possible that a large message would have some of its data prepended to subsequent messages due to our not incorrectly setting the location to write into the buffer. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> (cherry picked from commit a32e01802ff1c938c0afe0cc007a273b9ada8610)
-rw-r--r--hw/xquartz/console_redirect.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/hw/xquartz/console_redirect.c b/hw/xquartz/console_redirect.c
index 91d693b67..30e397a6b 100644
--- a/hw/xquartz/console_redirect.c
+++ b/hw/xquartz/console_redirect.c
@@ -110,27 +110,33 @@ _read_redirect(int fd, int flush)
/* Increment our returned number read */
total_read += nbytes;
- nbytes += (aslr->w - aslr->buf);
- aslr->buf[nbytes] = '\0';
+ /* Increment our write location */
+ aslr->w += nbytes;
+ aslr->w[0] = '\0';
/* One line at a time */
- for (p = aslr->buf; *p && (p - aslr->buf) < nbytes; p = s + 1) {
+ for (p = aslr->buf; p < aslr->w; p = s + 1) {
// Find null or \n
for (s = p; *s && *s != '\n'; s++) ;
if (*s == '\n') {
*s = '\0';
+ }
+
+ if (s < aslr->w || aslr->buf == p) {
+ /* Either the first of multiple messages or one message which is larger than our buffer */
asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p);
}
- else if (aslr->buf != p) {
+ else {
+ /* We reached the end of the buffer, move this chunk to the start. */
memmove(aslr->buf, p, BUF_SIZE - (p - aslr->buf));
aslr->w = aslr->buf + (s - p);
break;
}
- else if (nbytes == BUF_SIZE - 1) {
- asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p);
- aslr->w = aslr->buf;
- break;
- }
+ }
+
+ if (p == aslr->w) {
+ /* Start writing at the beginning in the case where we flushed */
+ aslr->w = aslr->buf;
}
}