From 933f0b2980b375cadc58b2ef5669bc34475a7be6 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Tue, 26 Apr 2011 13:34:57 -0700 Subject: launchd: console_redirect: Actually read and log the remaining data when we get EV_EOF Signed-off-by: Jeremy Huddleston --- launchd/console_redirect.c | 16 +++++++++++----- 1 file 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); + } + } } } -- cgit v1.2.3