Repository: trafficserver Updated Branches: refs/heads/master 29c25d7de -> cce321c35
TS-4165 Logging breaks if changing log format. This closes #446. TS wasn't calling `open_file()` on the LogFile it was trying to rotate away. This was occurring when an existing log file's formatting was changed in logs_xml.config and TS was restarted. The result was TS not updating/creating the updated log file. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/cce321c3 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/cce321c3 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/cce321c3 Branch: refs/heads/master Commit: cce321c35dedc1485e887fa23aa39c0dbac5bae7 Parents: 29c25d7 Author: Daniel Xu <[email protected]> Authored: Fri Jan 29 22:38:11 2016 +0000 Committer: Alan M. Carroll <[email protected]> Committed: Mon Feb 1 14:35:52 2016 -0600 ---------------------------------------------------------------------- proxy/logging/LogObject.cc | 31 +++++++++++++++++++++---------- proxy/logging/LogObject.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cce321c3/proxy/logging/LogObject.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc index dd272b6..3afe70d 100644 --- a/proxy/logging/LogObject.cc +++ b/proxy/logging/LogObject.cc @@ -1024,16 +1024,17 @@ LogObjectManager::_solve_filename_conflicts(LogObject *log_object, int maxConfli "filename", filename); LogFile logfile(filename, NULL, LOG_FILE_ASCII, 0); - long time_now = LogUtils::timestamp(); - - if (logfile.roll(time_now - log_object->get_rolling_interval(), time_now) == 0) { - // an error happened while trying to roll the file - // - const char *msg = "Cannot roll log file %s to fix log " - "filename conflicts"; - - Error(msg, filename); - LogUtils::manager_alarm(LogUtils::LOG_ALARM_ERROR, msg, filename); + if (logfile.open_file() == LogFile::LOG_FILE_NO_ERROR) { + long time_now = LogUtils::timestamp(); + + if (logfile.roll(time_now - log_object->get_rolling_interval(), time_now) == 0) { + // an error happened while trying to roll the file + // + _filename_resolution_abort(filename); + retVal = CANNOT_SOLVE_FILENAME_CONFLICTS; + } + } else { + _filename_resolution_abort(filename); retVal = CANNOT_SOLVE_FILENAME_CONFLICTS; } } @@ -1043,6 +1044,16 @@ LogObjectManager::_solve_filename_conflicts(LogObject *log_object, int maxConfli return retVal; } +void +LogObjectManager::_filename_resolution_abort(const char *filename) +{ + const char *msg = "Cannot roll log file %s to fix log " + "conflicts (filename or log format): %s"; + const char *err = strerror(errno); + Error(msg, filename, err); + LogUtils::manager_alarm(LogUtils::LOG_ALARM_ERROR, msg, filename, err); +} + bool LogObjectManager::_has_internal_filename_conflict(const char *filename, LogObjectList &objects) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cce321c3/proxy/logging/LogObject.h ---------------------------------------------------------------------- diff --git a/proxy/logging/LogObject.h b/proxy/logging/LogObject.h index bfbb8a6..4f73b6c 100644 --- a/proxy/logging/LogObject.h +++ b/proxy/logging/LogObject.h @@ -379,6 +379,7 @@ private: static bool _has_internal_filename_conflict(const char *filename, LogObjectList &objects); int _solve_filename_conflicts(LogObject *log_obj, int maxConflicts); int _solve_internal_filename_conflicts(LogObject *log_obj, int maxConflicts, int fileNum = 0); + void _filename_resolution_abort(const char *fname); public: LogObjectManager();
