diff --git a/src/ucore_logging.c b/src/ucore_logging.c index 034ee21..beecadf 100644 --- a/src/ucore_logging.c +++ b/src/ucore_logging.c @@ -58,6 +58,7 @@ static const struct uc_log_module unknown_module = { //All destinations. The log_lock must be held while accessing //this list an anything contained within it. static SLIST_HEAD(, uc_log_destination) destinations; +static int uc_log_reopen_file(struct uc_log_destination *dest); inline const char *uc_ll_2_str(enum UC_LOG_LEVEL l) { @@ -250,6 +251,25 @@ void uc_log_delete_destination(struct uc_log_destination *dest) pthread_mutex_unlock(&log_lock); } +static int uc_log_reopen_file(struct uc_log_destination *dest) +{ + int rc = 0; + + if (dest->type.file.file != NULL) { + fclose(dest->type.file.file); + dest->type.file.file = NULL; + } + + if (dest->type.file.file_name != NULL) { + dest->type.file.file = fopen(dest->type.file.file_name, "a"); + + if (dest->type.file.file == NULL) + rc = errno; + } + + return rc; +} + int uc_log_reopen_files(void) { struct uc_log_destination *dest; @@ -260,18 +280,7 @@ int uc_log_reopen_files(void) SLIST_FOREACH(dest, &destinations, entry) { if (dest->dest_type == UC_LDEST_FILE) { - - if (dest->type.file.file != NULL) { - fclose(dest->type.file.file); - dest->type.file.file = NULL; - } - - if (dest->type.file.file_name != NULL) { - dest->type.file.file = fopen(dest->type.file.file_name, "a"); - - if (dest->type.file.file == NULL) - rc = errno; - } + rc = uc_log_reopen_file(dest); } }