1
Enhance logrotate with "maxage".
2
From upstream RedHat patch.
4
Index: logrotate-3.7.1/logrotate.c
5
===================================================================
6
--- logrotate-3.7.1.orig/logrotate.c 2006-04-08 20:38:58.277761983 +0100
7
+++ logrotate-3.7.1/logrotate.c 2006-04-08 20:38:58.314755223 +0100
9
* the date in their name */
10
for (i = 0; i < globResult.gl_pathc; i++) {
11
if( !stat((globResult.gl_pathv)[i],&fst_buf) ) {
12
- if (i <= ((int)globResult.gl_pathc - rotateCount)) {
13
+ if ((i <= ((int)globResult.gl_pathc - rotateCount))
14
+ || ((log->rotateAge > 0)
15
+ && (((nowSecs - fst_buf.st_mtime)/60/60/24)
16
+ > log->rotateAge))) {
17
if ( mail_out != -1 ) {
18
if (!hasErrors && log->logAddress) {
19
char * mailFilename = (globResult.gl_pathv)[mail_out];
21
globfree(&globResult);
24
+ if ( log->rotateAge ) {
25
+ struct stat fst_buf;
26
+ for (i=1; i <= rotateCount; i++) {
27
+ sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
28
+ rotateCount + 1, fileext, compext);
29
+ if(!stat(oldName,&fst_buf)
30
+ && (((nowSecs - fst_buf.st_mtime)/60/60/24)
31
+ > log->rotateAge)) {
32
+ char * mailFilename = (globResult.gl_pathv)[i];
33
+ if (!hasErrors && log->logAddress)
34
+ hasErrors = mailLogWrapper(mailFilename, mailCommand, logNum, log);
36
+ hasErrors = removeLogFile(mailFilename);
41
sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
42
logStart + rotateCount, fileext, compext);
45
int main(int argc, const char ** argv) {
46
logInfo defConfig = { NULL, NULL, 0, NULL, ROT_SIZE,
47
- /* threshHold */ 1024 * 1024, 0,
48
+ /* threshHold */ 1024 * 1024,
49
+ /* rotateCount */ 0,
52
/* pre, post */ NULL, NULL,
53
/* first, last */ NULL, NULL,
54
Index: logrotate-3.7.1/logrotate.h
55
===================================================================
56
--- logrotate-3.7.1.orig/logrotate.h 2006-04-08 20:38:58.274762531 +0100
57
+++ logrotate-3.7.1/logrotate.h 2006-04-08 20:38:58.315755040 +0100
59
enum { ROT_DAYS, ROT_WEEKLY, ROT_MONTHLY, ROT_SIZE, ROT_FORCE } criterium;
60
unsigned int threshhold;
64
char * pre, * post, * first, * last;
66
Index: logrotate-3.7.1/config.c
67
===================================================================
68
--- logrotate-3.7.1.orig/config.c 2006-04-08 20:38:58.279761617 +0100
69
+++ logrotate-3.7.1/config.c 2006-04-08 20:38:58.317754675 +0100
72
*endtag = oldchar, start = endtag;
74
+ } else if (!strcmp(start, "maxage")) {
75
+ *endtag = oldchar, start = endtag;
77
+ if (!isolateValue(configFile, lineNum, "maxage count", &start,
79
+ oldchar = *endtag, *endtag = '\0';
81
+ newlog->rotateAge = strtoul(start, &chptr, 0);
82
+ if (*chptr || newlog->rotateAge < 0) {
83
+ message(MESS_ERROR, "%s:%d bad maximum age '%s'\n",
84
+ configFile, lineNum, start);
87
+ *endtag = oldchar, start = endtag;
89
} else if (!strcmp(start, "errors")) {
90
message(MESS_DEBUG, "%s: %d: the errors directive is deprecated and no longer used.\n",
92
Index: logrotate-3.7.1/logrotate.8
93
===================================================================
94
--- logrotate-3.7.1.orig/logrotate.8 2006-04-08 20:38:58.280761435 +0100
95
+++ logrotate-3.7.1/logrotate.8 2006-04-08 20:38:58.318754492 +0100
97
instead of the just-rotated file (this is the default).
100
+\fBmaxage\fR \fIcount\fR
101
+Remove rotated logs older than <count> days. The age is only checked
102
+if the logfile is to be rotated. The files are mailed to the
103
+configured address if \fBmaillast\fR and \fBmail\fR are configured.
107
If the log file is missing, go on to the next one without issuing an error
108
message. See also \fBnomissingok\fR.