summaryrefslogtreecommitdiffstats
path: root/patches/logrotate-3.7.1/ptx-timeext.patch
blob: 8931e3ab634c13eac754cbd0e4da2e67fe13271d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
Index: logrotate.h
===================================================================
--- a/logrotate.h.orig
+++ b/logrotate.h
@@ -16,6 +16,7 @@
 #define LOG_FLAG_SHAREDSCRIPTS	(1 << 7)
 #define LOG_FLAG_COPY		(1 << 8)
 #define LOG_FLAG_DATEEXT	(1 << 9)
+#define LOG_FLAG_TIMEEXT	(1 << 10)
 
 #define NO_FORCE_ROTATE 0
 #define FORCE_ROTATE    1
Index: config.c
===================================================================
--- a/config.c.orig
+++ b/config.c
@@ -521,6 +521,14 @@ static int readConfigFile(const char * c
 		newlog->flags &= ~LOG_FLAG_DATEEXT;
 
 		*endtag = oldchar, start = endtag;
+	    } else if (!strcmp(start, "timeext")) {
+		newlog->flags |= (LOG_FLAG_TIMEEXT);
+
+		*endtag = oldchar, start = endtag;
+	    } else if (!strcmp(start, "notimeext")) {
+		newlog->flags &= ~LOG_FLAG_TIMEEXT;
+
+		*endtag = oldchar, start = endtag;
 	    } else if (!strcmp(start, "noolddir")) {
 		newlog->oldDir = NULL;
 
Index: logrotate.8
===================================================================
--- a/logrotate.8.orig
+++ b/logrotate.8
@@ -216,6 +216,14 @@ Archive old versions of log files adding
 instead of simply adding a number.
 
 .TP
+\fBtimeext\fR
+Archive old versions of log files adding a timestamp extension like
+YYYYMMDDThhmmssZ instead of simply adding a number.
+The timestamp conforms to International Standard ISO 8601.
+20060307T114252Z -> 2006/03/07 11:42:52 Zulu (UTC)
+
+
+.TP
 \fBdelaycompress\fR
 Postpone compression of the previous log file to the next rotation cycle.
 This only has effect when used in combination with \fBcompress\fR.
Index: logrotate.c
===================================================================
--- a/logrotate.c.orig
+++ b/logrotate.c
@@ -542,7 +542,7 @@ int rotateSingleLog(logInfo * log, int l
 
     alloc_size = strlen(dirName) + strlen(baseName) + 
                  strlen(log->files[logNum]) + strlen(fileext) +
-                 strlen(compext) + 18;
+                 strlen(compext) + 18 + 8;
     
     oldName = alloca(alloc_size);
     newName = alloca(alloc_size);
@@ -564,13 +564,17 @@ int rotateSingleLog(logInfo * log, int l
     /* First compress the previous log when necessary */
     if (log->flags & LOG_FLAG_COMPRESS &&
         log->flags & LOG_FLAG_DELAYCOMPRESS) {
-	if (log->flags & LOG_FLAG_DATEEXT) {
+	if (log->flags & LOG_FLAG_DATEEXT ||
+	    log->flags & LOG_FLAG_TIMEEXT) {
 	               /* glob for uncompressed files with our pattern */
 	    glob_pattern = malloc(strlen(dirName) + strlen(baseName)
-				  + strlen(fileext) + 44 );
+				  + strlen(fileext) + 44 + 32);
 	    sprintf(glob_pattern,
-		    "%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s",
-		    dirName, baseName, fileext);
+		    "%s/%s%s%s",
+		    dirName, baseName, log->flags & LOG_FLAG_TIMEEXT ?
+		    "-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]Z" :
+		    "-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]",
+		    fileext);
 	    rc = glob(glob_pattern, 0, globerr, &globResult);
 	    if (!rc && globResult.gl_pathc > 0) {
 		for (i = 0; i < globResult.gl_pathc && !hasErrors; i++) {
@@ -605,16 +609,20 @@ int rotateSingleLog(logInfo * log, int l
     }
     
     firstRotated = alloca(strlen(dirName) + strlen(baseName) +
-			  strlen(fileext) + strlen(compext) + 30);
+			  strlen(fileext) + strlen(compext) + 30 + 8);
 
-    if(log->flags & LOG_FLAG_DATEEXT) {
+    if(log->flags & LOG_FLAG_DATEEXT ||
+       log->flags & LOG_FLAG_TIMEEXT) {
 	/* glob for compressed files with our pattern
 	 * and compress ext */
 	glob_pattern = malloc(strlen(dirName)+strlen(baseName)
-			      +strlen(fileext)+strlen(compext)+44);
+			      +strlen(fileext)+strlen(compext)+44+32);
 	sprintf(glob_pattern,
-		"%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s%s",
-		dirName, baseName, fileext, compext);
+		"%s/%s%s%s%s",
+		dirName, baseName, log->flags & LOG_FLAG_TIMEEXT ?
+		"-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]Z" :
+		"-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]",
+		fileext, compext);
 	rc = glob(glob_pattern, 0, globerr, &globResult);
 	if (!rc) {
 	    /* search for files to drop, if we find one remember it,
@@ -654,9 +662,17 @@ int rotateSingleLog(logInfo * log, int l
 	    disposeName = NULL;
 	}
 	/* firstRotated is most recently created/compressed rotated log */
+	if(log->flags & LOG_FLAG_TIMEEXT)
+	    sprintf(firstRotated, "%s/%s-%04d%02d%02dT%02d%02d%02dZ%s%s",
+		    dirName, baseName, now.tm_year+1900,
+		    now.tm_mon+1, now.tm_mday,
+		    now.tm_hour, now.tm_min, now.tm_sec,
+		    fileext, compext);
+	else
 	sprintf(firstRotated, "%s/%s-%04d%02d%02d%s%s",
 		dirName, baseName, now.tm_year+1900,
 		now.tm_mon+1, now.tm_mday, fileext, compext);
+
 	globfree(&globResult);
 	free(glob_pattern);
     } else {
@@ -743,13 +759,22 @@ int rotateSingleLog(logInfo * log, int l
  
     finalName = oldName;
     
-    if(log->flags & LOG_FLAG_DATEEXT) {
+    if(log->flags & LOG_FLAG_DATEEXT ||
+       log->flags & LOG_FLAG_TIMEEXT) {
 	char * destFile = alloca(strlen(dirName) + strlen(baseName) +
-				 strlen(fileext) + strlen(compext) + 30);
+				 strlen(fileext) + strlen(compext) + 30 + 8);
 	struct stat fst_buf;
+	if(log->flags & LOG_FLAG_TIMEEXT)
+		sprintf(finalName, "%s/%s-%04d%02d%02dT%02d%02d%02dZ%s",
+			dirName, baseName, now.tm_year+1900,
+			now.tm_mon+1, now.tm_mday,
+			now.tm_hour, now.tm_min, now.tm_sec,
+			fileext);
+	else
 	sprintf(finalName, "%s/%s-%04d%02d%02d%s",
 		dirName, baseName, now.tm_year+1900,
 		now.tm_mon+1, now.tm_mday, fileext);
+
 	sprintf(destFile, "%s%s", finalName, compext);
 	if(!stat(destFile,&fst_buf)) {
 	    message (MESS_DEBUG, "destination %s already exists, skipping rotation\n", firstRotated);