Skip to content

Commit

Permalink
Fix bug where log file name might get corrupted after first roll.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmichalek committed Dec 22, 2015
1 parent 786fbd8 commit 6e84bb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 9 additions & 4 deletions symmetric-client-clib/src/common/Log.c
Expand Up @@ -94,8 +94,10 @@ void SymLog_cleanupLogs(char *logFileName) {
time_t timeToKeepInSeconds = SymLog_daysToKeep*24*60*60;
time_t logExpiryTime = nowInSeconds-timeToKeepInSeconds;

char *logFileBaseName = basename(logFileName);
char *logDirName = dirname(logFileName);
char* logFileNameClone1 = SymStringUtils_format("%s", logFileName);
char* logFileNameClone2 = SymStringUtils_format("%s", logFileName);
char *logFileBaseName = basename(logFileNameClone1); // basename() and dirname() may modify the input string.
char *logDirName = dirname(logFileNameClone2);
DIR *logDir;

logDir = opendir(logDirName);
Expand All @@ -122,6 +124,8 @@ void SymLog_cleanupLogs(char *logFileName) {
}
closedir(logDir);
}
free(logFileNameClone1);
free(logFileNameClone2);
}
}

Expand All @@ -135,11 +139,12 @@ void SymLog_rollLogFile(char *logFileName) {

int result = rename(logFileName, rolledFileName);
if (result != 0) {
printf("Failed to rename '%s' to '%s' %s\n", logFileName, dateTimeString,
printf("Failed to rename '%s' to '%s' %s\n", logFileName, rolledFileName,
strerror(errno));
}

SymLog_cleanupLogs(logFileName);
free(rolledFileName);
}

void SymLog_rollIfNeeded(char *logFileName) {
Expand Down Expand Up @@ -196,7 +201,7 @@ void SymLog_log(SymLogLevel logLevel, const char *functionName, const char *file
else {
destination = fopen(SymLog_destination, "a+");
if (!destination) {
printf("Failed to open log file destination '%s'. Check the path our use 'console'\n", SymLog_destination);
printf("Failed to open log file destination '%s'. Check the path or use 'console'\n", SymLog_destination);
destination = stdout;
}
else {
Expand Down
1 change: 0 additions & 1 deletion symmetric-client-clib/src/service/PurgeService.c
Expand Up @@ -307,7 +307,6 @@ SymDate *SymPurgeService_getRetentionCutoff(SymPurgeService *this) {
long SymPurgeService_purgeIncoming(SymPurgeService *this) {
long rowsPurged = 0;
SymDate *retentionCutoff = SymPurgeService_getRetentionCutoff(this);
printf("%s\n", retentionCutoff->dateTimeString);
rowsPurged += SymPurgeService_purgeIncomingBeforeDate(this, retentionCutoff);
retentionCutoff->destroy(retentionCutoff);
return rowsPurged;
Expand Down

0 comments on commit 6e84bb8

Please sign in to comment.