提交 8b9bdfd3 编写于 作者: Y yuqing

logger.c call log_check_rotate in lock

上级 62f94164
Version 1.14 2015-05-12
Version 1.14 2015-05-15
* fast_task_info support set_buffer_size and realloc_buffer
* use file lock when write logger header
* bugfixed: sockopt.c correct fsbytes to sbytes in FreeBSD
* 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
* support php extension
......
......@@ -542,10 +542,8 @@ int log_rotate(LogContext *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->current_size > 0)
......@@ -555,27 +553,13 @@ static int log_check_rotate(LogContext *pContext, const bool bNeedLock)
return ENOENT;
}
if (bNeedLock)
{
pthread_mutex_lock(&(pContext->log_thread_lock));
}
if (pContext->rotate_immediately)
{
result = log_rotate(pContext);
pContext->rotate_immediately = false;
}
else
{
result = 0;
}
if (bNeedLock)
{
pthread_mutex_unlock(&(pContext->log_thread_lock));
return log_rotate(pContext);
}
return result;
return 0;
}
static int log_fsync(LogContext *pContext, const bool bNeedLock)
......@@ -593,7 +577,16 @@ static int log_fsync(LogContext *pContext, const bool bNeedLock)
}
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)
{
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;
}
/*
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)
{
result = log_check_rotate(pContext, false);
result = log_check_rotate(pContext);
}
} while (0);
......
......@@ -115,6 +115,9 @@ int log_init2();
#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_header(pContext, header, header_len) \
log_it_ex2(pContext, NULL, header, header_len, false, false)
#define log_destroy() log_destroy_ex(&g_log_context)
/** init function, use stderr for output by default
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册