Refactor uc_log_reopen_files

This commit is contained in:
Nils O. Selåsdal
2013-01-15 21:15:21 +01:00
parent 6de7a854ec
commit 128fabd741
+17 -8
View File
@@ -58,6 +58,7 @@ static const struct uc_log_module unknown_module = {
//All destinations. The log_lock must be held while accessing //All destinations. The log_lock must be held while accessing
//this list an anything contained within it. //this list an anything contained within it.
static SLIST_HEAD(, uc_log_destination) destinations; 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) inline const char *uc_ll_2_str(enum UC_LOG_LEVEL l)
{ {
@@ -250,17 +251,10 @@ void uc_log_delete_destination(struct uc_log_destination *dest)
pthread_mutex_unlock(&log_lock); pthread_mutex_unlock(&log_lock);
} }
int uc_log_reopen_files(void) static int uc_log_reopen_file(struct uc_log_destination *dest)
{ {
struct uc_log_destination *dest;
int rc = 0; int rc = 0;
pthread_mutex_lock(&log_lock);
SLIST_FOREACH(dest, &destinations, entry) {
if (dest->dest_type == UC_LDEST_FILE) {
if (dest->type.file.file != NULL) { if (dest->type.file.file != NULL) {
fclose(dest->type.file.file); fclose(dest->type.file.file);
dest->type.file.file = NULL; dest->type.file.file = NULL;
@@ -272,6 +266,21 @@ int uc_log_reopen_files(void)
if (dest->type.file.file == NULL) if (dest->type.file.file == NULL)
rc = errno; rc = errno;
} }
return rc;
}
int uc_log_reopen_files(void)
{
struct uc_log_destination *dest;
int rc = 0;
pthread_mutex_lock(&log_lock);
SLIST_FOREACH(dest, &destinations, entry) {
if (dest->dest_type == UC_LDEST_FILE) {
rc = uc_log_reopen_file(dest);
} }
} }