bug fixed: log header correctly when rotate

pull/4/head
yuqing 2015-05-15 14:02:39 +08:00
parent 8b9bdfd333
commit 0fd3425fb6
2 changed files with 7 additions and 6 deletions

View File

@ -5,6 +5,7 @@ Version 1.14 2015-05-15
* bugfixed: sockopt.c correct fsbytes to sbytes in FreeBSD * bugfixed: sockopt.c correct fsbytes to sbytes in FreeBSD
* macro FDFS_WRITE_BUFF_SIZE change to FAST_WRITE_BUFF_SIZE * macro FDFS_WRITE_BUFF_SIZE change to FAST_WRITE_BUFF_SIZE
* logger.c call log_check_rotate in lock * logger.c call log_check_rotate in lock
* bug fixed: log header correctly when rotate
Version 1.13 2015-02-27 Version 1.13 2015-02-27
* support php extension * support php extension

View File

@ -567,9 +567,9 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
int result; int result;
int lock_res; int lock_res;
int write_bytes; int write_bytes;
int written;
write_bytes = pContext->pcurrent_buff - pContext->log_buff; if (pContext->pcurrent_buff - pContext->log_buff == 0)
if (write_bytes == 0)
{ {
if (!pContext->rotate_immediately) if (!pContext->rotate_immediately)
{ {
@ -599,6 +599,7 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
__LINE__, lock_res, STRERROR(lock_res)); __LINE__, lock_res, STRERROR(lock_res));
} }
write_bytes = pContext->pcurrent_buff - pContext->log_buff;
pContext->current_size += write_bytes; pContext->current_size += write_bytes;
if (pContext->rotate_size > 0) if (pContext->rotate_size > 0)
{ {
@ -612,9 +613,9 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
result = 0; result = 0;
do do
{ {
write_bytes = pContext->pcurrent_buff - pContext->log_buff; written = write(pContext->log_fd, pContext->log_buff, write_bytes);
if (write(pContext->log_fd, pContext->log_buff, write_bytes) != \ pContext->pcurrent_buff = pContext->log_buff;
write_bytes) if (written != write_bytes)
{ {
result = errno != 0 ? errno : EIO; result = errno != 0 ? errno : EIO;
fprintf(stderr, "file: "__FILE__", line: %d, " \ fprintf(stderr, "file: "__FILE__", line: %d, " \
@ -629,7 +630,6 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
} }
} while (0); } while (0);
pContext->pcurrent_buff = pContext->log_buff;
if (bNeedLock && ((lock_res=pthread_mutex_unlock( \ if (bNeedLock && ((lock_res=pthread_mutex_unlock( \
&(pContext->log_thread_lock))) != 0)) &(pContext->log_thread_lock))) != 0))
{ {