Refactor uc_log_reopen_files
This commit is contained in:
+21
-12
@@ -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,6 +251,25 @@ void uc_log_delete_destination(struct uc_log_destination *dest)
|
|||||||
pthread_mutex_unlock(&log_lock);
|
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)
|
int uc_log_reopen_files(void)
|
||||||
{
|
{
|
||||||
struct uc_log_destination *dest;
|
struct uc_log_destination *dest;
|
||||||
@@ -260,18 +280,7 @@ int uc_log_reopen_files(void)
|
|||||||
SLIST_FOREACH(dest, &destinations, entry) {
|
SLIST_FOREACH(dest, &destinations, entry) {
|
||||||
|
|
||||||
if (dest->dest_type == UC_LDEST_FILE) {
|
if (dest->dest_type == UC_LDEST_FILE) {
|
||||||
|
rc = uc_log_reopen_file(dest);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user