logger.c call log_check_rotate in lock

pull/4/head
yuqing 2015-05-15 11:16:14 +08:00
parent 62f94164c1
commit 8b9bdfd333
3 changed files with 20 additions and 37 deletions

View File

@ -1,9 +1,10 @@
Version 1.14 2015-05-12 Version 1.14 2015-05-15
* fast_task_info support set_buffer_size and realloc_buffer * fast_task_info support set_buffer_size and realloc_buffer
* use file lock when write logger header * use file lock when write logger header
* 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
Version 1.13 2015-02-27 Version 1.13 2015-02-27
* support php extension * support php extension

View File

@ -542,10 +542,8 @@ int log_rotate(LogContext *pContext)
return log_open(pContext); return log_open(pContext);
} }
static int log_check_rotate(LogContext *pContext, const bool bNeedLock) static int log_check_rotate(LogContext *pContext)
{ {
int result;
if (pContext->log_fd == STDERR_FILENO) if (pContext->log_fd == STDERR_FILENO)
{ {
if (pContext->current_size > 0) if (pContext->current_size > 0)
@ -555,27 +553,13 @@ static int log_check_rotate(LogContext *pContext, const bool bNeedLock)
return ENOENT; return ENOENT;
} }
if (bNeedLock)
{
pthread_mutex_lock(&(pContext->log_thread_lock));
}
if (pContext->rotate_immediately) if (pContext->rotate_immediately)
{ {
result = log_rotate(pContext);
pContext->rotate_immediately = false; pContext->rotate_immediately = false;
} return log_rotate(pContext);
else
{
result = 0;
} }
if (bNeedLock) return 0;
{
pthread_mutex_unlock(&(pContext->log_thread_lock));
}
return result;
} }
static int log_fsync(LogContext *pContext, const bool bNeedLock) static int log_fsync(LogContext *pContext, const bool bNeedLock)
@ -593,7 +577,16 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
} }
else else
{ {
return log_check_rotate(pContext, bNeedLock); if (bNeedLock)
{
pthread_mutex_lock(&(pContext->log_thread_lock));
}
result = log_check_rotate(pContext);
if (bNeedLock)
{
pthread_mutex_unlock(&(pContext->log_thread_lock));
}
return result;
} }
} }
@ -612,7 +605,7 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
if (pContext->current_size > pContext->rotate_size) if (pContext->current_size > pContext->rotate_size)
{ {
pContext->rotate_immediately = true; pContext->rotate_immediately = true;
log_check_rotate(pContext, false); log_check_rotate(pContext);
} }
} }
@ -630,23 +623,9 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
break; break;
} }
/*
if (pContext->log_fd != STDERR_FILENO)
{
if (fsync(pContext->log_fd) != 0)
{
result = errno != 0 ? errno : EIO;
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call fsync fail, errno: %d, error info: %s\n",\
__LINE__, result, STRERROR(result));
break;
}
}
*/
if (pContext->rotate_immediately) if (pContext->rotate_immediately)
{ {
result = log_check_rotate(pContext, false); result = log_check_rotate(pContext);
} }
} while (0); } while (0);

View File

@ -115,6 +115,9 @@ int log_init2();
#define log_take_over_stderr() log_take_over_stderr_ex(&g_log_context) #define log_take_over_stderr() log_take_over_stderr_ex(&g_log_context)
#define log_take_over_stdout() log_take_over_stdout_ex(&g_log_context) #define log_take_over_stdout() log_take_over_stdout_ex(&g_log_context)
#define log_header(pContext, header, header_len) \
log_it_ex2(pContext, NULL, header, header_len, false, false)
#define log_destroy() log_destroy_ex(&g_log_context) #define log_destroy() log_destroy_ex(&g_log_context)
/** init function, use stderr for output by default /** init function, use stderr for output by default