147 lines
3.4 KiB
Plaintext
147 lines
3.4 KiB
Plaintext
--- config.c
|
|
+++ config.c
|
|
@@ -301,6 +301,7 @@
|
|
/* first, last */ NULL, NULL,
|
|
/* logAddress */ NULL,
|
|
/* extension */ NULL,
|
|
+ /* addextension */ NULL,
|
|
/* compress_prog */ NULL,
|
|
/* uncompress_prog */ NULL,
|
|
/* compress_ext */ NULL,
|
|
@@ -876,6 +877,22 @@
|
|
message(MESS_DEBUG, "extension is now %s\n",
|
|
newlog->extension);
|
|
|
|
+ } else if (!strcmp(start, "addextension")) {
|
|
+ *endtag = oldchar, start = endtag;
|
|
+
|
|
+ if (!isolateValue
|
|
+ (configFile, lineNum, "addextension name", &start,
|
|
+ &endtag)) {
|
|
+ oldchar = *endtag, *endtag = '\0';
|
|
+
|
|
+ newlog->addextension = strdup(start);
|
|
+
|
|
+ *endtag = oldchar, start = endtag;
|
|
+ }
|
|
+
|
|
+ message(MESS_DEBUG, "addextension is now %s\n",
|
|
+ newlog->addextension);
|
|
+
|
|
} else if (!strcmp(start, "compresscmd")) {
|
|
*endtag = oldchar, start = endtag;
|
|
if (!
|
|
--- logrotate.8
|
|
+++ logrotate.8
|
|
@@ -142,6 +142,15 @@
|
|
a \fBlogrotate\fR configuration file:
|
|
|
|
.TP
|
|
+\fBaddextension \fIext\fR
|
|
+Log files are given the final extension \fIext\fR after rotation. If
|
|
+the original file already ends with \fIext\fR, the extension is not
|
|
+duplicated, but merely moved to the end, i.e. both \fBfilename\fR and
|
|
+\fBfilename\fIext\fR would get rotated to filename.1\fIext\fR. If
|
|
+compression is used, the compression extension (normally \fB.gz\fR)
|
|
+appears after \fIext\fR.
|
|
+
|
|
+.TP
|
|
\fBcompress\fR
|
|
Old versions of log files are compressed with \fBgzip\fR by default. See also
|
|
\fBnocompress\fR.
|
|
--- logrotate.c
|
|
+++ logrotate.c
|
|
@@ -99,6 +99,7 @@
|
|
freeLogItem(last);
|
|
freeLogItem(logAddress);
|
|
freeLogItem(extension);
|
|
+ freeLogItem(addextension);
|
|
freeLogItem(compress_prog);
|
|
freeLogItem(uncompress_prog);
|
|
freeLogItem(compress_ext);
|
|
@@ -591,6 +592,25 @@
|
|
|
|
rotNames->baseName = strdup(ourBaseName(log->files[logNum]));
|
|
|
|
+ if (log->addextension) {
|
|
+ size_t baseLen = strlen(rotNames->baseName);
|
|
+ size_t extLen = strlen(log->addextension);
|
|
+ if (baseLen >= extLen &&
|
|
+ strncmp(&(rotNames->baseName[baseLen - extLen]),
|
|
+ log->addextension, extLen) == 0) {
|
|
+ char *tempstr;
|
|
+
|
|
+ fileext = log->addextension;
|
|
+ tempstr = calloc(baseLen - extLen + 1, sizeof(char));
|
|
+ strncat(tempstr, rotNames->baseName, baseLen - extLen);
|
|
+ free(rotNames->baseName);
|
|
+ rotNames->baseName = tempstr;
|
|
+ } else {
|
|
+ fileext = log->addextension;
|
|
+ }
|
|
+ }
|
|
+
|
|
+
|
|
alloc_size = strlen(rotNames->dirName) + strlen(rotNames->baseName) +
|
|
strlen(log->files[logNum]) + strlen(fileext) +
|
|
strlen(compext) + 18;
|
|
--- logrotate.h
|
|
+++ logrotate.h
|
|
@@ -40,6 +40,7 @@
|
|
char *pre, *post, *first, *last;
|
|
char *logAddress;
|
|
char *extension;
|
|
+ char *addextension;
|
|
char *compress_prog;
|
|
char *uncompress_prog;
|
|
char *compress_ext;
|
|
--- test/test
|
|
+++ test/test
|
|
@@ -354,4 +354,26 @@
|
|
|
|
rm -rf testdir
|
|
|
|
+# check rotation with extension appended to the filename
|
|
+cleanup 14
|
|
+
|
|
+preptest test.log 14 1 0
|
|
+$RLR test-config.14 --force
|
|
+
|
|
+checkoutput <<EOF
|
|
+test.log 0
|
|
+test.log.1.newext 0 zero
|
|
+EOF
|
|
+
|
|
+# check rotation with extension moved after the number
|
|
+cleanup 15
|
|
+
|
|
+preptest test.log 15 1 0
|
|
+$RLR test-config.15 --force
|
|
+
|
|
+checkoutput <<EOF
|
|
+test.log 0
|
|
+test.1.log 0 zero
|
|
+EOF
|
|
+
|
|
cleanup
|
|
--- test/test-config.14.in
|
|
+++ test/test-config.14.in
|
|
@@ -0,0 +1,7 @@
|
|
+create
|
|
+
|
|
+&DIR&/test.log {
|
|
+ monthly
|
|
+ rotate 1
|
|
+ addextension .newext
|
|
+}
|
|
--- test/test-config.15.in
|
|
+++ test/test-config.15.in
|
|
@@ -0,0 +1,7 @@
|
|
+create
|
|
+
|
|
+&DIR&/test.log {
|
|
+ monthly
|
|
+ rotate 1
|
|
+ addextension .log
|
|
+}
|