From d785a260d97806e0c7314aea2890d25dbd912fc0 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Mon, 13 Mar 2023 15:46:41 +0100 Subject: [PATCH] close logfile at exit --- log.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/log.cpp b/log.cpp index c4e375a..0ad9099 100644 --- a/log.cpp +++ b/log.cpp @@ -35,6 +35,8 @@ void setlog(const char *lf, const log_level_t ll_file, const log_level_t ll_scre log_level_file = ll_file; log_level_screen = ll_screen; + + atexit(closelog); } void setloguid(const int uid, const int gid) @@ -45,9 +47,11 @@ void setloguid(const int uid, const int gid) void closelog() { - fclose(lfh); + if (lfh) { + fclose(lfh); - lfh = nullptr; + lfh = nullptr; + } } void dolog(const log_level_t ll, const char *fmt, ...)