From b7c7ad92833f836b28f4ba09c5f390aab1ec9260 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 15 Jan 2017 12:37:01 +0100 Subject: [PATCH] use SIGHUP for reopening log file --- contrib/etc/logrotate.d/ebusd | 4 +++- src/ebusd/main.cpp | 4 ++++ src/lib/utils/log.cpp | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/etc/logrotate.d/ebusd b/contrib/etc/logrotate.d/ebusd index a1854f39..c969d679 100644 --- a/contrib/etc/logrotate.d/ebusd +++ b/contrib/etc/logrotate.d/ebusd @@ -1,4 +1,4 @@ -/var/log/ebusd.log { +/var/log/ebusd*.log { rotate 7 size 1M copytruncate @@ -6,4 +6,6 @@ missingok notifempty daily + postrotate + /usr/bin/killall -HUP ebusd } diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index ea87ae2e..d7b7b759 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -590,6 +590,10 @@ void signalHandler(int sig) { switch (sig) { case SIGHUP: logNotice(lf_main, "SIGHUP received"); + if (!opt.foreground) { + closeLogFile(); + setLogFile(opt.logFile); + } break; case SIGINT: logNotice(lf_main, "SIGINT received"); diff --git a/src/lib/utils/log.cpp b/src/lib/utils/log.cpp index c4f9984d..bf15dc44 100644 --- a/src/lib/utils/log.cpp +++ b/src/lib/utils/log.cpp @@ -141,6 +141,9 @@ bool needsLog(const LogFacility facility, const LogLevel level) { } void logWrite(const char* facility, const char* level, const char* message, va_list ap) { + if (s_logFile == NULL) { + return; + } struct timespec ts; struct tm td; clockGettime(&ts);