From: Michael Meffie Date: Sun, 13 Mar 2016 21:27:59 +0000 (-0400) Subject: util: fix log file renaming of mrafs-style logs X-Git-Tag: upstream/1.8.0_pre1^2~119 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=db74758924b4d889e1c713a46be898d47f4ae6a9;p=packages%2Fo%2Fopenafs.git util: fix log file renaming of mrafs-style logs Do not make timestamped log files with an invalid number of seconds when renaming old mrsafs-style log files, i.e., more than 59 seconds in the seconds field. Replace the goto used in the mrafs-style make file name retries with a regular, bounded loop. Change-Id: I16d032197e4b1e227b1f005fbc395a013e099561 Reviewed-on: https://gerrit.openafs.org/12220 Reviewed-by: Benjamin Kaduk Tested-by: BuildBot --- diff --git a/src/util/serverLog.c b/src/util/serverLog.c index e9ad82e3a..90dd45238 100644 --- a/src/util/serverLog.c +++ b/src/util/serverLog.c @@ -332,8 +332,6 @@ OpenLog(const char *fileName) int tempfd, isfifo = 0; int code; char *nextName = NULL; - struct timeval Start; - struct tm *TimeFields; #ifndef AFS_NT40_ENV struct stat statbuf; @@ -362,24 +360,27 @@ OpenLog(const char *fileName) if (mrafsStyleLogs) { time_t t; struct stat buf; - gettimeofday(&Start, NULL); - t = Start.tv_sec; - TimeFields = localtime(&t); - makefilename: - code = asprintf(&nextName, "%s.%d%02d%02d%02d%02d%02d", - fileName, TimeFields->tm_year + 1900, - TimeFields->tm_mon + 1, TimeFields->tm_mday, - TimeFields->tm_hour, TimeFields->tm_min, - TimeFields->tm_sec); - if (code < 0) { - nextName = NULL; - } else if (lstat(nextName, &buf) == 0) { - /* avoid clobbering a log */ - TimeFields->tm_sec++; - free(nextName); - nextName = NULL; - goto makefilename; - } + int tries; + struct tm *timeFields; + + time(&t); + for (tries = 0; nextName == NULL && tries < 100; t++, tries++) { + timeFields = localtime(&t); + code = asprintf(&nextName, "%s.%d%02d%02d%02d%02d%02d", + fileName, timeFields->tm_year + 1900, + timeFields->tm_mon + 1, timeFields->tm_mday, + timeFields->tm_hour, timeFields->tm_min, + timeFields->tm_sec); + if (code < 0) { + nextName = NULL; + break; + } + if (lstat(nextName, &buf) == 0) { + /* Avoid clobbering a log. */ + free(nextName); + nextName = NULL; + } + } } else { code = asprintf(&nextName, "%s.old", fileName); if (code < 0) {