aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xquartz/console_redirect.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/hw/xquartz/console_redirect.c')
-rw-r--r--xorg-server/hw/xquartz/console_redirect.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/xorg-server/hw/xquartz/console_redirect.c b/xorg-server/hw/xquartz/console_redirect.c
index 91d693b67..8fdce4699 100644
--- a/xorg-server/hw/xquartz/console_redirect.c
+++ b/xorg-server/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;
}
}
@@ -359,8 +365,8 @@ xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd)
BLOCK_DONE;
}
redirect_fds = new_array;
- memset(redirect_fds + n_redirect_fds, 0, new_n -
- n_redirect_fds);
+ memset(redirect_fds + n_redirect_fds, 0, (new_n -
+ n_redirect_fds) * sizeof(*redirect_fds));
n_redirect_fds = new_n;
}