summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@apple.com>2011-04-26 13:34:57 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2011-04-26 13:34:57 -0700
commit933f0b2980b375cadc58b2ef5669bc34475a7be6 (patch)
tree55285497fe3d67cb9a28a4d80fd214eac8089834
parent0881b1f2082b26995c24212e1e54ac4391d23fcd (diff)
downloadxorg-app-xinit-933f0b2980b375cadc58b2ef5669bc34475a7be6.tar.gz
launchd: console_redirect: Actually read and log the remaining data when we get EV_EOF
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r--launchd/console_redirect.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/launchd/console_redirect.c b/launchd/console_redirect.c
index dda84f1..2a758d1 100644
--- a/launchd/console_redirect.c
+++ b/launchd/console_redirect.c
@@ -84,9 +84,9 @@ static void *redirect_thread(void *ctx) {
int fd = ev->ident;
asl_redirect *aslr;
- if(fd == fds[0].fd) {
+ if(fd == fds[0].fd && !fds[0].closed) {
aslr = &fds[0];
- } else if(fd == fds[1].fd) {
+ } else if(fd == fds[1].fd && !fds[1].closed) {
aslr = &fds[1];
} else {
asl_log(fds[1].aslc, fds[1].aslm, ASL_LEVEL_ERR, "unexpected file descriptor: %d", fd);
@@ -96,12 +96,10 @@ static void *redirect_thread(void *ctx) {
if(ev->flags & EV_EOF) {
EV_SET(&ev[1], aslr->fd, EVFILT_READ, EV_DELETE, 0, 0, 0);
kevent(kq, &ev[1], 1, NULL, 0, NULL);
- close(aslr->fd);
aslr->closed = 1;
- continue;
}
- nbytes = read(fd, aslr->w, BUF_SIZE - (aslr->w - aslr->buf) - 1);
+ nbytes = read(aslr->fd, aslr->w, BUF_SIZE - (aslr->w - aslr->buf) - 1);
if(nbytes > 0) {
nbytes += (aslr->w - aslr->buf);
aslr->buf[nbytes] = '\0';
@@ -124,6 +122,14 @@ static void *redirect_thread(void *ctx) {
}
}
}
+
+ if(aslr->closed) {
+ close(aslr->fd);
+ if(aslr->w > aslr->buf) {
+ *aslr->w = '\0';
+ asl_log(aslr->aslc, aslr->aslm, aslr->level, "%s", aslr->buf);
+ }
+ }
}
}