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>
This commit is contained in:
parent
ad5fe2d961
commit
a32e01802f
|
@ -110,27 +110,33 @@ _read_redirect(int fd, int flush)
|
||||||
/* Increment our returned number read */
|
/* Increment our returned number read */
|
||||||
total_read += nbytes;
|
total_read += nbytes;
|
||||||
|
|
||||||
nbytes += (aslr->w - aslr->buf);
|
/* Increment our write location */
|
||||||
aslr->buf[nbytes] = '\0';
|
aslr->w += nbytes;
|
||||||
|
aslr->w[0] = '\0';
|
||||||
|
|
||||||
/* One line at a time */
|
/* 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
|
// Find null or \n
|
||||||
for (s = p; *s && *s != '\n'; s++) ;
|
for (s = p; *s && *s != '\n'; s++) ;
|
||||||
if (*s == '\n') {
|
if (*s == '\n') {
|
||||||
*s = '\0';
|
*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);
|
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));
|
memmove(aslr->buf, p, BUF_SIZE - (p - aslr->buf));
|
||||||
aslr->w = aslr->buf + (s - p);
|
aslr->w = aslr->buf + (s - p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (nbytes == BUF_SIZE - 1) {
|
}
|
||||||
asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p);
|
|
||||||
aslr->w = aslr->buf;
|
if (p == aslr->w) {
|
||||||
break;
|
/* Start writing at the beginning in the case where we flushed */
|
||||||
}
|
aslr->w = aslr->buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue