View | Details | Raw Unified | Return to bug 114523 | Differences between
and this patch

Collapse All | Expand All

(-)logrotate/Makefile (-3 / +3 lines)
Lines 6-13 Link Here
6
#
6
#
7
7
8
PORTNAME=		logrotate
8
PORTNAME=		logrotate
9
PORTVERSION=		3.7
9
PORTVERSION=		3.7.1
10
PORTREVISION=		5
10
PORTREVISION=		3
11
CATEGORIES=		sysutils
11
CATEGORIES=		sysutils
12
MASTER_SITES=		${MASTER_SITE_DEBIAN_POOL}
12
MASTER_SITES=		${MASTER_SITE_DEBIAN_POOL}
13
MASTER_SITE_SUBDIR=	l/logrotate
13
MASTER_SITE_SUBDIR=	l/logrotate
Lines 15-21 Link Here
15
15
16
PATCH_SITES=		${MASTER_SITES}
16
PATCH_SITES=		${MASTER_SITES}
17
PATCH_SITE_SUBDIR=	${MASTER_SITE_SUBDIR}
17
PATCH_SITE_SUBDIR=	${MASTER_SITE_SUBDIR}
18
PATCHFILES=		${PORTNAME}_${PORTVERSION}-5.diff.gz
18
PATCHFILES=		${PORTNAME}_${PORTVERSION}-3.diff.gz
19
19
20
MAINTAINER=		js@iksz.hu
20
MAINTAINER=		js@iksz.hu
21
COMMENT=		Daemon to rotate, compress, remove and mail system log files
21
COMMENT=		Daemon to rotate, compress, remove and mail system log files
(-)logrotate/Makefile.orig (+39 lines)
Line 0 Link Here
1
# New ports collection makefile for:	logrotate
2
# Date Created:				29 Dec 1999
3
# Whom:					Yuan-Chen Cheng <ycheng@sinica.edu.tw>
4
#
5
# $FreeBSD: ports/sysutils/logrotate/Makefile,v 1.22 2007/02/17 20:56:56 gabor Exp $
6
#
7
8
PORTNAME=		logrotate
9
PORTVERSION=		3.7
10
PORTREVISION=		5
11
CATEGORIES=		sysutils
12
MASTER_SITES=		${MASTER_SITE_DEBIAN_POOL}
13
MASTER_SITE_SUBDIR=	l/logrotate
14
DISTNAME=		${PORTNAME}_${PORTVERSION}.orig
15
16
PATCH_SITES=		${MASTER_SITES}
17
PATCH_SITE_SUBDIR=	${MASTER_SITE_SUBDIR}
18
PATCHFILES=		${PORTNAME}_${PORTVERSION}-5.diff.gz
19
20
MAINTAINER=		js@iksz.hu
21
COMMENT=		Daemon to rotate, compress, remove and mail system log files
22
23
LIB_DEPENDS=		popt.0:${PORTSDIR}/devel/popt
24
25
USE_GMAKE=	yes
26
MAKE_ENV=	"BASEDIR=${PREFIX}"
27
PATCH_WRKSRC=		${WRKDIR}
28
WRKSRC=			${WRKDIR}/${PORTNAME}-${PORTVERSION}
29
30
MAN8=		logrotate.8
31
MANCOMPRESSED=	no
32
33
post-install:
34
	@${MKDIR} ${EXAMPLESDIR}
35
	@${SED} -e 's|__PREFIX__|${PREFIX}|' \
36
		< ${FILESDIR}/logrotate.conf.sample > ${PREFIX}/etc/logrotate.conf.sample
37
	@${INSTALL_DATA} ${FILESDIR}/syslog.sample ${EXAMPLESDIR}
38
39
.include <bsd.port.mk>
(-)logrotate/distinfo (-6 / +6 lines)
Lines 1-6 Link Here
1
MD5 (logrotate_3.7.orig.tar.gz) = bf0de3a495294300f32e71f136119c41
1
MD5 (logrotate_3.7.1.orig.tar.gz) = 552639142e163745f6bcd4f1f3816d8a
2
SHA256 (logrotate_3.7.orig.tar.gz) = a0fba4f6214fb30cb1f61a51fffca9a7e2ec01aad8dbcf5d3ec157149b460e1b
2
SHA256 (logrotate_3.7.1.orig.tar.gz) = 7e79b03d65105541a5fdcc05087bee29ebc9e33149ac33d6563d0b20eddf79e0
3
SIZE (logrotate_3.7.orig.tar.gz) = 35737
3
SIZE (logrotate_3.7.1.orig.tar.gz) = 36176
4
MD5 (logrotate_3.7-5.diff.gz) = 291d015a7fddd86ee2da4cb7bbb12b19
4
MD5 (logrotate_3.7.1-3.diff.gz) = 7b0dd9835339bbf85f106d4adb25cf0c
5
SHA256 (logrotate_3.7-5.diff.gz) = dce1378ddafe98478eb0fa2d6064fae7ddbd4eab9e8cac794b333d586759bbf5
5
SHA256 (logrotate_3.7.1-3.diff.gz) = 68b6ebd0cb8f78a8a0a1dcaa8a1a4486288967e9acc7f4c02bb8ee9ecde9cb6c
6
SIZE (logrotate_3.7-5.diff.gz) = 15081
6
SIZE (logrotate_3.7.1-3.diff.gz) = 23547
(-)logrotate/distinfo.orig (+12 lines)
Line 0 Link Here
1
MD5 (logrotate_3.7.orig.tar.gz) = bf0de3a495294300f32e71f136119c41
2
SHA256 (logrotate_3.7.orig.tar.gz) = a0fba4f6214fb30cb1f61a51fffca9a7e2ec01aad8dbcf5d3ec157149b460e1b
3
SIZE (logrotate_3.7.orig.tar.gz) = 35737
4
MD5 (logrotate_3.7-5.diff.gz) = 291d015a7fddd86ee2da4cb7bbb12b19
5
SHA256 (logrotate_3.7-5.diff.gz) = dce1378ddafe98478eb0fa2d6064fae7ddbd4eab9e8cac794b333d586759bbf5
6
SIZE (logrotate_3.7-5.diff.gz) = 15081
7
MD5 (logrotate_3.7.orig.tar.gz) = bf0de3a495294300f32e71f136119c41
8
SHA256 (logrotate_3.7.orig.tar.gz) = a0fba4f6214fb30cb1f61a51fffca9a7e2ec01aad8dbcf5d3ec157149b460e1b
9
SIZE (logrotate_3.7.orig.tar.gz) = 35737
10
MD5 (logrotate_3.7-5.diff.gz) = 291d015a7fddd86ee2da4cb7bbb12b19
11
SHA256 (logrotate_3.7-5.diff.gz) = dce1378ddafe98478eb0fa2d6064fae7ddbd4eab9e8cac794b333d586759bbf5
12
SIZE (logrotate_3.7-5.diff.gz) = 15081
(-)logrotate/distinfo.orig.orig (+6 lines)
Line 0 Link Here
1
MD5 (logrotate_3.7.orig.tar.gz) = bf0de3a495294300f32e71f136119c41
2
SHA256 (logrotate_3.7.orig.tar.gz) = a0fba4f6214fb30cb1f61a51fffca9a7e2ec01aad8dbcf5d3ec157149b460e1b
3
SIZE (logrotate_3.7.orig.tar.gz) = 35737
4
MD5 (logrotate_3.7-5.diff.gz) = 291d015a7fddd86ee2da4cb7bbb12b19
5
SHA256 (logrotate_3.7-5.diff.gz) = dce1378ddafe98478eb0fa2d6064fae7ddbd4eab9e8cac794b333d586759bbf5
6
SIZE (logrotate_3.7-5.diff.gz) = 15081
(-)logrotate/files/patch-Makefile (-1 / +1 lines)
Lines 1-5 Link Here
1
--- logrotate-3.7-orig/Makefile	Wed Oct 20 19:07:27 2004
1
--- logrotate-3.7-orig/Makefile	Wed Oct 20 19:07:27 2004
2
+++ logrotate-3.7/Makefile	Wed Oct 20 19:07:42 2004
2
+++ logrotate-3.7.1/Makefile	Wed Oct 20 19:07:42 2004
3
@@ -1,5 +1,4 @@
3
@@ -1,5 +1,4 @@
4
 VERSION = $(shell awk '/Version:/ { print $$2 }' logrotate.spec)
4
 VERSION = $(shell awk '/Version:/ { print $$2 }' logrotate.spec)
5
-CVSROOT = $(shell cat CVS/Root)
5
-CVSROOT = $(shell cat CVS/Root)
(-)logrotate/files/patch-aa (-13 / +4 lines)
Lines 1-25 Link Here
1
diff -ruN logrotate-3.7-orig/config.c logrotate-3.7/config.c
1
diff -ruN logrotate-3.7-orig/config.c logrotate-3.7/config.c
2
--- logrotate-3.7-orig/config.c	Mon Sep 22 21:11:12 2003
2
--- logrotate-3.7.1-orig/config.c	Mon Sep 22 21:11:12 2003
3
+++ logrotate-3.7/config.c	Mon May 24 08:09:39 2004
3
+++ logrotate-3.7.1/config.c	Mon May 24 08:09:39 2004
4
@@ -1,4 +1,3 @@
4
@@ -1,4 +1,3 @@
5
-#include <alloca.h>
5
-#include <alloca.h>
6
 #include <ctype.h>
6
 #include <ctype.h>
7
 #include <dirent.h>
7
 #include <dirent.h>
8
 #include <errno.h>
8
 #include <errno.h>
9
diff -ruN logrotate-3.7-orig/logrotate.c logrotate-3.7/logrotate.c
9
diff -ruN logrotate-3.7-orig/logrotate.c logrotate-3.7/logrotate.c
10
--- logrotate-3.7-orig/logrotate.c	Thu Feb  5 19:42:13 2004
10
--- logrotate-3.7.1-orig/logrotate.c	Thu Feb  5 19:42:13 2004
11
+++ logrotate-3.7/logrotate.c	Tue Jun 15 17:35:48 2004
11
+++ logrotate-3.7.1/logrotate.c	Tue Jun 15 17:35:48 2004
12
@@ -1,4 +1,3 @@
12
@@ -1,4 +1,3 @@
13
-#include <alloca.h>
13
-#include <alloca.h>
14
 #include <ctype.h>
14
 #include <ctype.h>
15
 #include <dirent.h>
15
 #include <dirent.h>
16
 #include <errno.h>
16
 #include <errno.h>
17
@@ -110,7 +109,7 @@
18
     close(fd);
19
 
20
     if (!fork()) {
21
-	execlp(filespec, logfn, NULL);
22
+	execlp(filespec, filespec, logfn, NULL);
23
 	exit(1);
24
     }
25
 
(-)logrotate/files/patch-config.h (-2 / +2 lines)
Lines 1-6 Link Here
1
diff -ruN logrotate-3.7-orig/config.h logrotate-3.7/config.h
1
diff -ruN logrotate-3.7-orig/config.h logrotate-3.7/config.h
2
--- logrotate-3.7-orig/config.h	Mon Sep 22 21:11:12 2003
2
--- logrotate-3.7-orig/config.h	Mon Sep 22 21:11:12 2003
3
+++ logrotate-3.7/config.h	Mon May 24 08:05:29 2004
3
+++ logrotate-3.7.1/config.h	Mon May 24 08:05:29 2004
4
@@ -16,6 +16,13 @@
4
@@ -16,6 +16,13 @@
5
     #define STATEFILE "/var/log/logrotate.status"
5
     #define STATEFILE "/var/log/logrotate.status"
6
 #endif
6
 #endif
Lines 9-15 Link Here
9
+    #define DEFAULT_MAIL_COMMAND "/usr/bin/mailx -s"
9
+    #define DEFAULT_MAIL_COMMAND "/usr/bin/mailx -s"
10
+    #define COMPRESS_COMMAND "/usr/bin/gzip"
10
+    #define COMPRESS_COMMAND "/usr/bin/gzip"
11
+    #define UNCOMPRESS_COMMAND "/usr/bin/gunzip"
11
+    #define UNCOMPRESS_COMMAND "/usr/bin/gunzip"
12
+    #define STATEFILE "/var/lib/logrotate.status"
12
+    #define STATEFILE "/var/log/logrotate.status"
13
+#endif
13
+#endif
14
+
14
+
15
 /*
15
 /*
(-)logrotate/files/patch-dateext (+414 lines)
Line 0 Link Here
1
--- logrotate-3.7.1/logrotate.h.dateext	2003-08-07 13:13:14.000000000 +0200
2
+++ logrotate-3.7.1/logrotate.h	2005-05-03 14:17:28.732914132 +0200
3
@@ -15,6 +15,7 @@
4
 #define LOG_FLAG_MAILFIRST	(1 << 6)
5
 #define LOG_FLAG_SHAREDSCRIPTS	(1 << 7)
6
 #define LOG_FLAG_COPY		(1 << 8)
7
+#define LOG_FLAG_DATEEXT	(1 << 9)
8
 
9
 #define NO_FORCE_ROTATE 0
10
 #define FORCE_ROTATE    1
11
--- logrotate-3.7.1/logrotate.c.dateext	2005-05-03 14:17:28.730914415 +0200
12
+++ logrotate-3.7.1/logrotate.c	2005-05-03 14:31:29.916899912 +0200
13
@@ -11,6 +11,7 @@
14
 #include <sys/wait.h>
15
 #include <time.h>
16
 #include <unistd.h>
17
+#include <glob.h>
18
 
19
 #ifdef WITH_SELINUX
20
 #include <selinux/selinux.h>
21
@@ -23,6 +24,10 @@
22
 #include "log.h"
23
 #include "logrotate.h"
24
 
25
+#if !defined(GLOB_ABORTED) && defined(GLOB_ABEND)
26
+#define GLOB_ABORTED GLOB_ABEND
27
+#endif
28
+
29
 typedef struct {
30
     char * fn;
31
     struct tm lastRotated;	/* only tm.mon, tm_mday, tm_year are good! */
32
@@ -43,6 +48,14 @@
33
 char * mailCommand = DEFAULT_MAIL_COMMAND;
34
 time_t nowSecs = 0;
35
 
36
+static int globerr(const char * pathname, int theerr) {
37
+    message(MESS_ERROR, "error accessing %s: %s\n", pathname,
38
+	strerror(theerr));
39
+
40
+    /* We want the glob operation to continue, so return 0 */
41
+    return 1;
42
+}
43
+
44
 static logState * findState(const char * fn, struct stateSet * sip) {
45
     int i;
46
     logState * states = sip->states;
47
@@ -93,6 +106,17 @@
48
     return rc;
49
 }
50
 
51
+static int removeLogFile(char * name) {
52
+    message(MESS_DEBUG, "removing old log %s\n", name);
53
+
54
+    if (!debug && unlink(name)) {
55
+       message(MESS_ERROR, "Failed to remove old log %s: %s\n",
56
+           name, strerror(errno));
57
+       return 1;
58
+    }
59
+    return 0;
60
+}
61
+
62
 static int compressLogFile(char * name, logInfo * log, struct stat *sb) {
63
     char * compressedName;
64
     const char ** fullCommand;
65
@@ -237,6 +261,25 @@
66
     return rc;
67
 }
68
 
69
+static int mailLogWrapper (char * mailFilename, char * mailCommand, int logNum, logInfo * log) {
70
+    /* if the log is compressed (and we're not mailing a
71
+     * file whose compression has been delayed), we need
72
+     * to uncompress it */
73
+    if ((log->flags & LOG_FLAG_COMPRESS) &&
74
+       !((log->flags & LOG_FLAG_DELAYCOMPRESS) &&
75
+           (log->flags & LOG_FLAG_MAILFIRST))) {
76
+       if (mailLog(mailFilename, mailCommand,
77
+                   log->uncompress_prog, log->logAddress,
78
+                   log->files[logNum]))
79
+           return 1;
80
+    } else {
81
+       if (mailLog(mailFilename, mailCommand, NULL,
82
+                   log->logAddress, mailFilename))
83
+           return 1;
84
+    }
85
+    return 0;
86
+}
87
+
88
 static int copyTruncate(char * currLog, char * saveLog, struct stat * sb, int flags) {
89
     char buf[BUFSIZ];
90
     int fdcurr = -1, fdsave = -1;
91
@@ -456,6 +499,9 @@
92
     char * baseName;
93
     char * dirName;
94
     char * firstRotated;
95
+    char * glob_pattern;
96
+    glob_t globResult;
97
+    int rc;
98
     size_t alloc_size;
99
     int rotateCount = log->rotateCount ? log->rotateCount : 1;
100
     int logStart = (log->logStart == -1) ? 1 : log->logStart;
101
@@ -486,7 +532,7 @@
102
 
103
     alloc_size = strlen(dirName) + strlen(baseName) + 
104
                  strlen(log->files[logNum]) + strlen(fileext) +
105
-                 strlen(compext) + 10;
106
+                 strlen(compext) + 18;
107
     
108
     oldName = alloca(alloc_size);
109
     newName = alloca(alloc_size);
110
@@ -508,25 +554,106 @@
111
     /* First compress the previous log when necessary */
112
     if (log->flags & LOG_FLAG_COMPRESS &&
113
         log->flags & LOG_FLAG_DELAYCOMPRESS) {
114
-        struct stat sbprev;
115
-	
116
-        sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
117
-        if (stat(oldName, &sbprev)) {
118
-            message(MESS_DEBUG, "previous log %s does not exist\n",
119
-		    oldName);
120
-        } else {
121
-	    hasErrors = compressLogFile(oldName, log, &sbprev);
122
+	if (log->flags & LOG_FLAG_DATEEXT) {
123
+	               /* glob for uncompressed files with our pattern */
124
+	    glob_pattern = malloc(strlen(dirName) + strlen(baseName)
125
+				  + strlen(fileext) + 44 );
126
+	    sprintf(glob_pattern,
127
+		    "%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s",
128
+		    dirName, baseName, fileext);
129
+	    rc = glob(glob_pattern, 0, globerr, &globResult);
130
+	    if (!rc && globResult.gl_pathc > 0) {
131
+		for (i = 0; i < globResult.gl_pathc && !hasErrors; i++) {
132
+	    	    struct stat sbprev;
133
+		    
134
+		    sprintf(oldName,"%s",(globResult.gl_pathv)[i]);
135
+		    if (stat(oldName, &sbprev)) {
136
+			message(MESS_DEBUG, "previous log %s does not exist\n",
137
+			oldName);
138
+		    } else {
139
+			hasErrors = compressLogFile(oldName, log, &sbprev);
140
+		    }
141
+		}
142
+	    } else {
143
+		message (MESS_DEBUG, "glob finding logs to compress failed\n");
144
+		/* fallback to old behaviour */
145
+		sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
146
+	    }
147
+	    globfree(&globResult);
148
+	    free(glob_pattern);
149
+	} else {
150
+	    struct stat sbprev;
151
+
152
+	    sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
153
+	    if (stat(oldName, &sbprev)) {
154
+		message(MESS_DEBUG, "previous log %s does not exist\n",
155
+			oldName);
156
+	    } else {
157
+		hasErrors = compressLogFile(oldName, log, &sbprev);
158
+	    }
159
 	}
160
     }
161
     
162
+    firstRotated = alloca(strlen(dirName) + strlen(baseName) +
163
+			  strlen(fileext) + strlen(compext) + 30);
164
+
165
+    if(log->flags & LOG_FLAG_DATEEXT) {
166
+	/* glob for compressed files with our pattern
167
+	 * and compress ext */
168
+	glob_pattern = malloc(strlen(dirName)+strlen(baseName)
169
+			      +strlen(fileext)+strlen(compext)+44);
170
+	sprintf(glob_pattern,
171
+		"%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s%s",
172
+		dirName, baseName, fileext, compext);
173
+	rc = glob(glob_pattern, 0, globerr, &globResult);
174
+	if (!rc) {
175
+	    /* search for files to drop, if we find one remember it,
176
+	     * if we find another one mail and remove the first and
177
+	     * remember the second and so on */
178
+	    struct stat fst_buf;
179
+	    int mail_out = -1;
180
+	    /* remove the first (n - rotateCount) matches
181
+	     * no real rotation needed, since the files have
182
+	     * the date in their name */
183
+	    for (i = 0; i < globResult.gl_pathc; i++) {
184
+		if( !stat((globResult.gl_pathv)[i],&fst_buf) ) {
185
+		    if (i <= ((int)globResult.gl_pathc - rotateCount)) {
186
+			if ( mail_out != -1 ) {
187
+			    if (!hasErrors && log->logAddress) {
188
+				char * mailFilename = (globResult.gl_pathv)[mail_out];
189
+				hasErrors = mailLogWrapper(mailFilename, mailCommand, logNum, log);
190
+				if (!hasErrors)
191
+				    hasErrors = removeLogFile(mailFilename);
192
+			    }
193
+			}
194
+			mail_out = i;
195
+		    }
196
+		}
197
+	    }
198
+	    if ( mail_out != -1 ) {
199
+		/* oldName is oldest Backup found (for unlink later) */
200
+		sprintf(oldName, "%s", (globResult.gl_pathv)[mail_out]);
201
+		strcpy(disposeName, oldName);
202
+	    } else
203
+		disposeName = NULL;
204
+	} else {
205
+	    message (MESS_DEBUG, "glob finding old rotated logs failed\n");
206
+	    disposeName = NULL;
207
+	}
208
+	/* firstRotated is most recently created/compressed rotated log */
209
+	sprintf(firstRotated, "%s/%s-%04d%02d%02d%s%s",
210
+		dirName, baseName, now.tm_year+1900,
211
+		now.tm_mon+1, now.tm_mday, fileext, compext);
212
+	globfree(&globResult);
213
+	free(glob_pattern);
214
+    } else {
215
+
216
     sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
217
             logStart + rotateCount, fileext, compext);
218
     strcpy(newName, oldName);
219
     
220
     strcpy(disposeName, oldName);
221
     
222
-    firstRotated = alloca(strlen(dirName) + strlen(baseName) +
223
-                          strlen(fileext) + strlen(compext) + 30);
224
     sprintf(firstRotated, "%s/%s.%d%s%s", dirName, baseName,
225
             logStart, fileext, 
226
 	    (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext);
227
@@ -582,12 +709,27 @@
228
                 hasErrors = 1;
229
 	    }
230
 	}
231
-    }
232
-    
233
+    } 
234
+    } /* !LOG_FLAG_DATEEXT */
235
+ 
236
     finalName = oldName;
237
     
238
-    /* note: the gzip extension is *not* used here! */
239
-    sprintf(finalName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
240
+    if(log->flags & LOG_FLAG_DATEEXT) {
241
+	char * destFile = alloca(strlen(dirName) + strlen(baseName) +
242
+				 strlen(fileext) + strlen(compext) + 30);
243
+	struct stat fst_buf;
244
+	sprintf(finalName, "%s/%s-%04d%02d%02d%s",
245
+		dirName, baseName, now.tm_year+1900,
246
+		now.tm_mon+1, now.tm_mday, fileext);
247
+	sprintf(destFile, "%s%s", finalName, compext);
248
+	if(!stat(destFile,&fst_buf)) {
249
+	    message (MESS_DEBUG, "destination %s already exists, skipping rotation\n", firstRotated);
250
+	    hasErrors = 1;
251
+	}
252
+    } else {
253
+	/* note: the gzip extension is *not* used here! */
254
+	sprintf(finalName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
255
+    }
256
     
257
     /* if the last rotation doesn't exist, that's okay */
258
     if (!debug && access(disposeName, F_OK)) {
259
@@ -596,9 +738,6 @@
260
         disposeName = NULL;
261
     } 
262
     
263
-    free(dirName);
264
-    free(baseName);
265
-    
266
     if (!hasErrors) {
267
         if (log->pre && !(log->flags & LOG_FLAG_SHAREDSCRIPTS)) {
268
             message(MESS_DEBUG, "running prerotate script\n");
269
@@ -744,6 +883,8 @@
270
 		}
271
 	}
272
 #endif
273
+    free(dirName);
274
+    free(baseName);
275
     return hasErrors;
276
 }
277
 
278
--- logrotate-3.7.1/config.c.dateext	2003-08-07 13:13:14.000000000 +0200
279
+++ logrotate-3.7.1/config.c	2005-05-03 14:17:28.734913850 +0200
280
@@ -511,6 +511,14 @@
281
 		newlog->flags &= ~LOG_FLAG_IFEMPTY;
282
 
283
 		*endtag = oldchar, start = endtag;
284
+	    } else if (!strcmp(start, "dateext")) {
285
+		newlog->flags |= LOG_FLAG_DATEEXT;
286
+
287
+		*endtag = oldchar, start = endtag;
288
+	    } else if (!strcmp(start, "nodateext")) {
289
+		newlog->flags &= ~LOG_FLAG_DATEEXT;
290
+
291
+		*endtag = oldchar, start = endtag;
292
 	    } else if (!strcmp(start, "noolddir")) {
293
 		newlog->oldDir = NULL;
294
 
295
--- logrotate-3.7.1/logrotate.8.dateext	2005-05-03 14:17:28.722915545 +0200
296
+++ logrotate-3.7.1/logrotate.8	2005-05-03 14:17:28.735913708 +0200
297
@@ -205,6 +205,11 @@
298
 Log files are rotated every day.
299
 
300
 .TP
301
+\fBdateext\fR
302
+Archive old versions of log files adding a daily extension like YYYYMMDD
303
+instead of simply adding a number.
304
+
305
+.TP
306
 \fBdelaycompress\fR
307
 Postpone compression of the previous log file to the next rotation cycle.
308
 This has only effect when used in combination with \fBcompress\fR.
309
310
logrotate-3.7.1-maxage.patch:
311
 config.c    |   15 +++++++++++++++
312
 logrotate.8 |    6 ++++++
313
 logrotate.c |   25 +++++++++++++++++++++++--
314
 logrotate.h |    1 +
315
 4 files changed, 45 insertions(+), 2 deletions(-)
316
317
--- NEW FILE logrotate-3.7.1-maxage.patch ---
318
--- logrotate-3.7.1/logrotate.c.maxage	2005-05-03 14:46:08.154599467 +0200
319
+++ logrotate-3.7.1/logrotate.c	2005-05-03 14:50:43.707983574 +0200
320
@@ -617,7 +617,10 @@
321
 	     * the date in their name */
322
 	    for (i = 0; i < globResult.gl_pathc; i++) {
323
 		if( !stat((globResult.gl_pathv)[i],&fst_buf) ) {
324
-		    if (i <= ((int)globResult.gl_pathc - rotateCount)) {
325
+		    if ((i <= ((int)globResult.gl_pathc - rotateCount)) 
326
+			|| ((log->rotateAge > 0)
327
+			    && (((nowSecs - fst_buf.st_mtime)/60/60/24)
328
+				> log->rotateAge))) {
329
 			if ( mail_out != -1 ) {
330
 			    if (!hasErrors && log->logAddress) {
331
 				char * mailFilename = (globResult.gl_pathv)[mail_out];
332
@@ -647,6 +650,22 @@
333
 	globfree(&globResult);
334
 	free(glob_pattern);
335
     } else {
336
+	if ( log->rotateAge ) {
337
+	    struct stat fst_buf;
338
+	    for (i=1; i <= rotateCount; i++) {
339
+		sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
340
+			rotateCount + 1, fileext, compext);
341
+		if(!stat(oldName,&fst_buf)
342
+		    && (((nowSecs - fst_buf.st_mtime)/60/60/24)
343
+			> log->rotateAge)) {
344
+		    char * mailFilename = (globResult.gl_pathv)[i];
345
+		    if (!hasErrors && log->logAddress)
346
+			hasErrors = mailLogWrapper(mailFilename, mailCommand, logNum, log);
347
+		    if (!hasErrors)
348
+			hasErrors = removeLogFile(mailFilename);
349
+		}
350
+	    }
351
+	}
352
 
353
     sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
354
             logStart + rotateCount, fileext, compext);
355
@@ -1171,7 +1190,9 @@
356
 
357
 int main(int argc, const char ** argv) {
358
     logInfo defConfig = { NULL, NULL, 0, NULL, ROT_SIZE, 
359
-			  /* threshHold */ 1024 * 1024, 0,
360
+			  /* threshHold */ 1024 * 1024,
361
+			  /* rotateCount */ 0,
362
+			  /* rotateAge */ 0,
363
 			  /* log start */ -1,
364
 			  /* pre, post */ NULL, NULL,
365
 			  /* first, last */ NULL, NULL,
366
--- logrotate-3.7.1/logrotate.h.maxage	2005-05-03 14:51:33.207865757 +0200
367
+++ logrotate-3.7.1/logrotate.h	2005-05-03 14:51:58.732195346 +0200
368
@@ -35,6 +35,7 @@
369
     enum { ROT_DAYS, ROT_WEEKLY, ROT_MONTHLY, ROT_SIZE, ROT_FORCE } criterium;
370
     unsigned int threshhold;
371
     int rotateCount;
372
+    int rotateAge;
373
     int logStart;
374
     char * pre, * post, * first, * last;
375
     char * logAddress;
376
--- logrotate-3.7.1/config.c.maxage	2005-05-03 14:39:35.690020183 +0200
377
+++ logrotate-3.7.1/config.c	2005-05-03 14:40:33.429711948 +0200
378
@@ -678,6 +678,21 @@
379
 		    }
380
 		    *endtag = oldchar, start = endtag;
381
 		}
382
+	    } else if (!strcmp(start, "maxage")) {
383
+		*endtag = oldchar, start = endtag;
384
+
385
+		if (!isolateValue(configFile, lineNum, "maxage count", &start,
386
+				  &endtag)) {
387
+		    oldchar = *endtag, *endtag = '\0';
388
+
389
+		    newlog->rotateAge = strtoul(start, &chptr, 0);
390
+		    if (*chptr || newlog->rotateAge < 0) {
391
+			message(MESS_ERROR, "%s:%d bad maximum age '%s'\n",
392
+				configFile, lineNum, start);
393
+			return 1;
394
+		    }
395
+		    *endtag = oldchar, start = endtag;
396
+		}
397
 	    } else if (!strcmp(start, "errors")) {
398
 		message(MESS_DEBUG, "%s: %d: the errors directive is deprecated and no longer used.\n",
399
 			configFile, lineNum);
400
--- logrotate-3.7.1/logrotate.8.maxage	2005-05-03 14:41:55.736877916 +0200
401
+++ logrotate-3.7.1/logrotate.8	2005-05-03 14:45:33.464585908 +0200
402
@@ -256,6 +256,12 @@
403
 instead of the just-rotated file (this is the default).
404
 
405
 .TP
406
+\fBmaxage\fR \fIcount\fR
407
+Remove rotated logs older than <count> days. The age is only checked
408
+if the logfile is to be rotated. The files are mailed to the
409
+configured address if \fBmaillast\fR and \fBmail\fR are configured.
410
+
411
+.TP
412
 \fBmissingok\fR
413
 If the log file is missing, go on to the next one without issuing an error
414
 message. See also \fBnomissingok\fR.

Return to bug 114523