diff --git a/tools/cpp/logger/main.cpp b/tools/cpp/logger/main.cpp index 2113efb6..f86d820e 100644 --- a/tools/cpp/logger/main.cpp +++ b/tools/cpp/logger/main.cpp @@ -32,6 +32,7 @@ using namespace std; #include "platform.hpp" static atomic_int done {0}; +static atomic_int got_sighup {0}; struct Args { @@ -207,7 +208,9 @@ struct Args } if (rotate > 0 && auto_increment) { - cerr << "ERROR. --increment and --rotate can't both be used" << endl; + cerr << "ERROR. --increment and --rotate can't both be used." << endl + << "Note that if you don't want --increment, you must" << endl + << "specify a log filename." << endl; return false; } @@ -580,6 +583,19 @@ struct Logger } } + // Did we get a SIGHUP and the user wants a new logfile? + if (got_sighup) { + log->close(); + if (args.rotate > 0) + rotate_logfiles(); + if (!openLogfile()) exit(1); + num_splits++; + logsize = 0; + last_report_logsize = 0; + + got_sighup = 0; + } + if (log->writeEvent(le) != 0) { static u64 last_spew_utime = 0; string reason = strerror(errno); @@ -650,6 +666,13 @@ void sighandler(int signal) if (done == 3) exit(1); } +void sighup_handler(int signal) +{ + if (!logger.args.auto_increment && logger.args.rotate <= 0) return; + got_sighup = 1; + logger.wakeup(); +} + int main(int argc, char *argv[]) { Platform::setstreambuf(); @@ -683,6 +706,7 @@ int main(int argc, char *argv[]) signal(SIGINT, sighandler); signal(SIGQUIT, sighandler); signal(SIGTERM, sighandler); + signal(SIGHUP, sighup_handler); ZCM_DEBUG("Starting zcms"); for (auto& z : zcms) z->start();