X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Flog.c;h=4edead714c092adb10916647fac14bc21cc0dfde;hp=e3c8dc85ebc5c4abcf2a505a2f193d81e9d5bafd;hb=240156e69d3a6390699644756e367fffd42891d1;hpb=3fd941dda9cb4fc873abbd9f94cb998b7e0bda50 diff --git a/src/log.c b/src/log.c index e3c8dc8..4edead7 100644 --- a/src/log.c +++ b/src/log.c @@ -103,14 +103,18 @@ static struct { static unsigned int next_log_bit = YLOG_LAST_BIT<<1; /* first dynamic bit */ +static int yaz_log_reopen_flag = 0; + static YAZ_MUTEX log_mutex = 0; -static void yaz_log_lock(void) +static void yaz_log_open(void); + +void yaz_log_lock(void) { yaz_mutex_enter(log_mutex); } -static void yaz_log_unlock(void) +void yaz_log_unlock(void) { yaz_mutex_leave(log_mutex); } @@ -150,6 +154,15 @@ void yaz_log_close(void) } } +void yaz_log_deinit_globals(void) +{ + if (log_mutex) + { + yaz_mutex_destroy(&log_mutex); + yaz_log_close(); + } +} + void yaz_log_init_file(const char *fname) { yaz_init_globals(); @@ -169,7 +182,7 @@ void yaz_log_init_file(const char *fname) yaz_log_info.type = use_none; /* NULL name; use no file at all */ yaz_log_info.l_fname[0] = '\0'; } - yaz_log_reopen(); + yaz_log_open(); } static void rotate_log(const char *cur_fname) @@ -216,7 +229,7 @@ void yaz_log_init_level(int level) if ( (l_level & YLOG_FLUSH) != (level & YLOG_FLUSH) ) { l_level = level; - yaz_log_reopen(); /* make sure we set buffering right */ + yaz_log_open(); /* make sure we set buffering right */ } else l_level = level; @@ -306,6 +319,11 @@ static void yaz_log_open_check(struct tm *tm, int force, const char *filemode) if (yaz_log_info.type != use_file) return; + if (yaz_log_reopen_flag) + { + force = 1; + yaz_log_reopen_flag = 0; + } if (*yaz_log_info.l_fname) { strftime(new_filename, sizeof(new_filename)-1, yaz_log_info.l_fname, @@ -340,8 +358,6 @@ static void yaz_log_open_check(struct tm *tm, int force, const char *filemode) { yaz_log_close(); yaz_log_info.log_file = new_file; - if (l_level & YLOG_FLUSH) - setvbuf(yaz_log_info.log_file, 0, _IONBF, 0); } else { @@ -370,9 +386,13 @@ static void yaz_log_do_reopen(const char *filemode) yaz_log_unlock(); } - void yaz_log_reopen() { + yaz_log_reopen_flag = 1; +} + +static void yaz_log_open() +{ yaz_log_do_reopen("a"); }