This has only effect when used in combination with \fBcompress\fR.
--- logrotate.c
+++ logrotate.c
-@@ -10,6 +10,7 @@
- #include <sys/stat.h>
+@@ -11,6 +11,7 @@
+ #include <sys/wait.h>
#include <time.h>
#include <unistd.h>
+#include <glob.h>
#ifdef WITH_SELINUX
#include <selinux/selinux.h>
-@@ -21,6 +22,10 @@
+@@ -22,6 +23,10 @@
#include "log.h"
#include "logrotate.h"
typedef struct {
char * fn;
struct tm lastRotated; /* only tm.mon, tm_mday, tm_year are good! */
-@@ -64,6 +69,14 @@
- return newstr;
- }
+@@ -42,6 +47,14 @@
+ char * mailCommand = DEFAULT_MAIL_COMMAND;
+ time_t nowSecs = 0;
+static int globerr(const char * pathname, int theerr) {
+ message(MESS_ERROR, "error accessing %s: %s\n", pathname,
+ return 1;
+}
+
- static logState * findState(const char * fn, logState ** statesPtr,
- int * numStatesPtr) {
+ static logState * findState(const char * fn, struct stateSet * sip) {
int i;
-@@ -72,9 +85,11 @@
+ logState * states = sip->states;
+@@ -49,9 +62,11 @@
struct tm now = *localtime(&nowSecs);
time_t lr_time;
if (i == numStates) {
i = numStates++;
states = realloc(states, sizeof(*states) * numStates);
-@@ -465,6 +480,9 @@
+@@ -458,6 +473,9 @@
char * baseName;
char * dirName;
char * firstRotated;
size_t alloc_size;
int rotateCount = log->rotateCount ? log->rotateCount : 1;
int logStart = (log->logStart == -1) ? 1 : log->logStart;
-@@ -501,7 +519,7 @@
+@@ -488,7 +506,7 @@
alloc_size = strlen(dirName) + strlen(baseName) +
strlen(log->files[logNum]) + strlen(fileext) +
oldName = alloca(alloc_size);
newName = alloca(alloc_size);
-@@ -523,18 +541,95 @@
- /* First compress the previous log when necessary */
- if (log->flags & LOG_FLAG_COMPRESS &&
+@@ -512,27 +530,45 @@
log->flags & LOG_FLAG_DELAYCOMPRESS) {
-- sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
-- hasErrors = compress_log(log, oldName, "previous", errorFile);
+ struct stat sbprev;
+
+- sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
+- if (stat(oldName, &sbprev)) {
+- message(MESS_DEBUG, "previous log %s does not exist\n",
+- oldName);
+- } else {
+- hasErrors = compressLogFile(oldName, log);
+ if(log->flags & LOG_FLAG_DATEEXT) {
+ /* glob for uncompressed files with our pattern */
+ glob_pattern = malloc(strlen(dirName) + strlen(baseName)
+ if (!rc && globResult.gl_pathc > 0) {
+ for (i = 0; i < globResult.gl_pathc && !hasErrors; i++) {
+ sprintf(oldName,"%s",(globResult.gl_pathv)[i]);
-+ hasErrors = compress_log(log, oldName, "previous", errorFile);
++ if (stat(oldName, &sbprev)) {
++ message(MESS_DEBUG, "previous log %s does not exist\n",
++ oldName);
++ } else {
++ hasErrors = compressLogFile(oldName, log);
++ }
+ }
+ } else {
+ message (MESS_DEBUG, "glob finding logs to compress failed\n");
+ free(glob_pattern);
+ } else {
+ sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
-+ hasErrors = compress_log(log, oldName, "previous", errorFile);
-+ }
++ if (stat(oldName, &sbprev)) {
++ message(MESS_DEBUG, "previous log %s does not exist\n",
++ oldName);
++ } else {
++ hasErrors = compressLogFile(oldName, log);
++ }
+ }
}
+
+- sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
+- logStart + rotateCount, fileext, compext);
+- strcpy(newName, oldName);
+-
+- strcpy(disposeName, oldName);
+-
+ firstRotated = alloca(strlen(dirName) + strlen(baseName) +
+ strlen(fileext) + strlen(compext) + 30);
+- sprintf(firstRotated, "%s/%s.%d%s%s", dirName, baseName,
+- logStart, fileext,
+- (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext);
-
-+ firstRotated = alloca(strlen(dirName) + strlen(baseName) +
-+ strlen(fileext) + strlen(compext) + 30);
++
+ #ifdef WITH_SELINUX
+ if ((selinux_enabled=(is_selinux_enabled()>0))) {
+ security_context_t oldContext=NULL;
+@@ -558,6 +594,98 @@
+ }
+ }
+ #endif
+
+ if(log->flags & LOG_FLAG_DATEEXT) {
+ /* glob for compressed files with our pattern
+ if( !stat((globResult.gl_pathv)[i],&fst_buf) ) {
+ if (i < ((int)globResult.gl_pathc - rotateCount - 1)) {
+ if ( mail_out != -1 ) {
-+ if (!hasErrors && log->logAddress)
-+ hasErrors = mail_old_log(log, logNum, NULL,
-+ (globResult.gl_pathv)[mail_out],
-+ errorFile, compext);
-+ if (!hasErrors)
-+ hasErrors = remove_old_log(log,
-+ (globResult.gl_pathv)[mail_out],
-+ errorFile);
++ if (!hasErrors && log->logAddress) {
++ char * mailFilename;
++
++ if(log->flags & LOG_FLAG_MAILFIRST)
++ mailFilename = NULL;
++ else
++ mailFilename = (globResult.gl_pathv)[mail_out];
++ if(mailFilename) {
++ /* if the log is compressed (and we're not mailing a
++ file whose compression has been delayed), we need
++ to uncompress it */
++ if ((log->flags & LOG_FLAG_COMPRESS) &&
++ !((log->flags & LOG_FLAG_DELAYCOMPRESS) &&
++ (log->flags & LOG_FLAG_MAILFIRST))) {
++ if (mailLog(mailFilename, mailCommand,
++ log->uncompress_prog, log->logAddress,
++ log->files[logNum]))
++ hasErrors = 1;
++ } else {
++ if (mailLog(mailFilename, mailCommand, NULL,
++ log->logAddress, mailFilename))
++ hasErrors = 1;
++ }
++ }
++ if (!hasErrors) {
++ message(MESS_DEBUG, "removing old log %s\n",
++ (globResult.gl_pathv)[mail_out]);
++ if(!debug && unlink((globResult.gl_pathv)[mail_out])) {
++ message(MESS_ERROR, "Failed to remove old log %s: %s\n",
++ (globResult.gl_pathv)[mail_out], strerror(errno));
++ hasErrors = 1;
++ }
++ }
++ }
+ }
+ mail_out = i;
+ }
+ free(glob_pattern);
+ } else {
+
- sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
- logStart + rotateCount, fileext, compext);
- strcpy(newName, oldName);
-
- strcpy(disposeName, oldName);
-
-- firstRotated = alloca(strlen(dirName) + strlen(baseName) +
-- strlen(fileext) + strlen(compext) + 30);
- sprintf(firstRotated, "%s/%s.%d%s%s", dirName, baseName,
- logStart, fileext, compext);
-
-@@ -584,11 +679,27 @@
++ sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
++ logStart + rotateCount, fileext, compext);
++ strcpy(newName, oldName);
++
++ strcpy(disposeName, oldName);
++
++ sprintf(firstRotated, "%s/%s.%d%s%s", dirName, baseName,
++ logStart, fileext,
++ (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext);
++
+ for (i = rotateCount + logStart - 1; (i >= 0) && !hasErrors; i--) {
+ tmp = newName;
+ newName = oldName;
+@@ -579,11 +707,27 @@
}
}
}
/* if the last rotation doesn't exist, that's okay */
if (!debug && access(disposeName, F_OK)) {
-@@ -597,9 +708,6 @@
+@@ -592,9 +736,6 @@
disposeName = NULL;
}
if (!hasErrors) {
if (log->pre && !(log->flags & LOG_FLAG_SHAREDSCRIPTS)) {
message(MESS_DEBUG, "running prerotate script\n");
-@@ -716,6 +824,8 @@
+@@ -740,6 +881,8 @@
}
}
#endif
message. See also \fBnomissingok\fR.
--- logrotate.c
+++ logrotate.c
-@@ -589,7 +589,10 @@
+@@ -615,7 +615,10 @@
* the date in their name */
for (i = 0; i < globResult.gl_pathc; i++) {
if( !stat((globResult.gl_pathv)[i],&fst_buf) ) {
+ && (((nowSecs - fst_buf.st_mtime)/60/60/24)
+ > log->rotateAge))) {
if ( mail_out != -1 ) {
- if (!hasErrors && log->logAddress)
- hasErrors = mail_old_log(log, logNum, NULL,
-@@ -623,6 +626,25 @@
+ if (!hasErrors && log->logAddress) {
+ char * mailFilename;
+@@ -675,6 +678,49 @@
globfree(&globResult);
free(glob_pattern);
} else {
+ if(!stat(oldName,&fst_buf)
+ && (((nowSecs - fst_buf.st_mtime)/60/60/24)
+ > log->rotateAge)) {
-+ if (!hasErrors && log->logAddress)
-+ hasErrors = mail_old_log(log, logNum, NULL,
-+ (globResult.gl_pathv)[i],
-+ errorFile, compext);
-+ if (!hasErrors)
-+ hasErrors = remove_old_log(log,
-+ (globResult.gl_pathv)[i],
-+ errorFile);
++ if (!hasErrors && log->logAddress) {
++ char * mailFilename;
++
++ if(log->flags & LOG_FLAG_MAILFIRST)
++ mailFilename = NULL;
++ else
++ mailFilename = (globResult.gl_pathv)[i];
++ /* if the log is compressed (and we're not mailing a
++ file whose compression has been delayed), we need
++ to uncompress it */
++ if ((log->flags & LOG_FLAG_COMPRESS) &&
++ !((log->flags & LOG_FLAG_DELAYCOMPRESS) &&
++ (log->flags & LOG_FLAG_MAILFIRST))) {
++ if (mailLog(mailFilename, mailCommand,
++ log->uncompress_prog, log->logAddress,
++ log->files[logNum]))
++ hasErrors = 1;
++ } else {
++ if (mailLog(mailFilename, mailCommand, NULL,
++ log->logAddress, mailFilename))
++ hasErrors = 1;
++ }
++ }
++ if (!hasErrors) {
++ message(MESS_DEBUG, "removing old log %s\n",
++ (globResult.gl_pathv)[i]);
++ if(!debug && unlink((globResult.gl_pathv)[i])) {
++ message(MESS_ERROR, "Failed to remove old log %s: %s\n",
++ (globResult.gl_pathv)[i], strerror(errno));
++ hasErrors = 1;
++ }
++ }
+ }
+ }
+ }
sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
logStart + rotateCount, fileext, compext);
-@@ -1110,8 +1132,10 @@
+@@ -1168,8 +1214,10 @@
}
int main(int argc, const char ** argv) {