diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2014-05-20 14:51:22 +0400 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2014-05-20 14:51:22 +0400 |
commit | 753dc522b4b0fa1551d08a2b338c6865c0bc11a6 (patch) | |
tree | 7e3fa5c416c6a53dcb816e1bd1fd791fff34cc9b /accel-pppd/logs | |
parent | 799b6ad6d23e9bc32e6af180b6924d30ecd67a60 (diff) | |
download | accel-ppp-753dc522b4b0fa1551d08a2b338c6865c0bc11a6.tar.gz accel-ppp-753dc522b4b0fa1551d08a2b338c6865c0bc11a6.zip |
log_file: restore write message timestamps
Diffstat (limited to 'accel-pppd/logs')
-rw-r--r-- | accel-pppd/logs/log_file.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/accel-pppd/logs/log_file.c b/accel-pppd/logs/log_file.c index cc8c1bc4..9dc88630 100644 --- a/accel-pppd/logs/log_file.c +++ b/accel-pppd/logs/log_file.c @@ -102,7 +102,7 @@ static void *log_thread(void *unused) struct iovec iov[IOV_MAX]; struct log_chunk_t *chunk; struct log_msg_t *msg; - int iov_cnt = 0; + int iov_cnt; while (1) { pthread_mutex_lock(&lock); @@ -115,8 +115,17 @@ static void *log_thread(void *unused) iov_cnt = 0; while (1) { + if (lf->new_fd != -1) { + close(lf->fd); + lf->fd = lf->new_fd; + lf->new_fd = -1; + } + spin_lock(&lf->lock); if (list_empty(&lf->msgs)) { + if (iov_cnt) + writev(lf->fd, iov, iov_cnt); + lf->queued = 0; if (lf->need_free) { spin_unlock(&lf->lock); @@ -124,18 +133,9 @@ static void *log_thread(void *unused) if (lf->new_fd != -1) close(lf->new_fd); mempool_free(lf->lpd); - } else { + } else spin_unlock(&lf->lock); - if (iov_cnt) - writev(lf->fd, iov, iov_cnt); - - if (lf->new_fd != -1) { - close(lf->fd); - lf->fd = lf->new_fd; - lf->new_fd = -1; - } - } break; } @@ -143,6 +143,13 @@ static void *log_thread(void *unused) list_del(&msg->entry); spin_unlock(&lf->lock); + iov[iov_cnt].iov_base = msg->hdr->msg; + iov[iov_cnt].iov_len = msg->hdr->len; + if (++iov_cnt == IOV_MAX) { + writev(lf->fd, iov, iov_cnt); + iov_cnt = 0; + } + list_for_each_entry(chunk, msg->chunks, entry) { iov[iov_cnt].iov_base = chunk->msg; iov[iov_cnt].iov_len = chunk->len; |