diff --git a/HISTORY b/HISTORY index 8636a723e25228bcf3436789aabeebe8684aeb7d..455df0ce5d95c9ae4146a11b63f2f9f558137d67 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.06 2014-08-26 +Version 1.06 2014-08-27 * update source code from FastDFS V5.02 * add function short2buff and buff2short * add object memory pool (fast_mblock.h and fast_mblock.c) @@ -25,6 +25,7 @@ Version 1.06 2014-08-26 * add function ioevent_remove * add function log_reopen_ex * extern function log_rotate + * add function log_set_fd_flags Version 1.05 2012-07-08 * update source code from FastDFS V3.09 diff --git a/src/logger.c b/src/logger.c index c5a0c053722cbeed1d01b3e839f072d5ccb75149..3c32f254e01e56063abdf1ce55c061979f766bc2 100644 --- a/src/logger.c +++ b/src/logger.c @@ -106,7 +106,7 @@ int log_init_ex(LogContext *pContext) static int log_open(LogContext *pContext) { if ((pContext->log_fd = open(pContext->log_filename, O_WRONLY | \ - O_CREAT | O_APPEND, 0644)) < 0) + O_CREAT | O_APPEND | pContext->fd_flags, 0644)) < 0) { fprintf(stderr, "open log file \"%s\" to write fail, " \ "errno: %d, error info: %s\n", \ @@ -234,6 +234,11 @@ void log_take_over_stdout_ex(LogContext *pContext) pContext->take_over_stdout = true; } +void log_set_fd_flags(LogContext *pContext, const int flags) +{ + pContext->fd_flags = flags; +} + void log_destroy_ex(LogContext *pContext) { if (pContext->log_fd >= 0 && pContext->log_fd != STDERR_FILENO) diff --git a/src/logger.h b/src/logger.h index 869e10c3839c39fd63429d8348c7c7ae3dadf40e..7b1b462008cae441fe7b1232ad3b22dd5d9bb218 100644 --- a/src/logger.h +++ b/src/logger.h @@ -81,6 +81,9 @@ typedef struct log_context /* keep days for rotated log files */ int keep_days; + /* log fd flags */ + int fd_flags; + /* * log the header (title line) callback * */ @@ -197,6 +200,14 @@ void log_take_over_stderr_ex(LogContext *pContext); */ void log_take_over_stdout_ex(LogContext *pContext); +/** set log fd flags + * parameters: + * pContext: the log context + * flags: the fd flags + * return: none +*/ +void log_set_fd_flags(LogContext *pContext, const int flags); + /** destroy function * parameters: * pContext: the log context