Skip to content
Snippets Groups Projects
Commit 03e041b4 authored by Rahul Thakur's avatar Rahul Thakur
Browse files

logrotate: update version

* update logrotate version to 3.22.0
* add patch to implement minutes
* add patch to calculate age in minutes instead of days
parent fc1229c2
No related branches found
No related tags found
1 merge request!90logrotate: update version
......@@ -8,12 +8,12 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=logrotate
PKG_VERSION:=3.17.0
PKG_RELEASE:=2
PKG_VERSION:=3.22.0
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://github.com/logrotate/logrotate/releases/download/$(PKG_VERSION)
PKG_HASH:=58cc2178ff57faa3c0490181cce041345aeca6cff18dba1c5cd1398bf1c19294
PKG_SOURCE_URL:=https://github.com/logrotate/logrotate/releases/download/$(PKG_SOURCE)
PKG_HASH:=42b4080ee99c9fb6a7d12d8e787637d057a635194e25971997eebbe8d5e57618
PKG_MAINTAINER:=Christian Beier <cb@shoutrlabs.com>
PKG_LICENSE:=GPL-2.0-or-later
......
diff --git a/README.md b/README.md
index f44d5c0..c615981 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# logrotate
-The logrotate utility is designed to simplify the administration of log files on a system which generates a lot of log files. Logrotate allows for the automatic rotation compression, removal and mailing of log files. Logrotate can be set to handle a log file hourly, daily, weekly, monthly or when the log file gets to a certain size.
+The logrotate utility is designed to simplify the administration of log files on a system which generates a lot of log files. Logrotate allows for the automatic rotation compression, removal and mailing of log files. Logrotate can be set to handle a log file hourly, daily, weekly, monthly, when time in minutes has elapsed or when the log file gets to a certain size.
## Download
diff --git a/config.c b/config.c
index fb39494..d19ebcc 100644
--- a/config.c
+++ b/config.c
@@ -609,6 +609,7 @@ static int copyLogInfo(struct logInfo *to, const struct logInfo *from)
to->criterium = from->criterium;
to->weekday = from->weekday;
to->threshold = from->threshold;
+ to->minutes = from->minutes;
to->minsize = from->minsize;
to->maxsize = from->maxsize;
to->rotateCount = from->rotateCount;
@@ -723,6 +724,7 @@ static const char *crit_to_string(enum criterium crit)
case ROT_MONTHLY: return "monthly";
case ROT_YEARLY: return "yearly";
case ROT_SIZE: return "size";
+ case ROT_MINUTES: return "minutes";
default: return "XXX";
}
}
@@ -877,6 +879,7 @@ int readAllConfigPaths(const char **paths)
.oldDir = NULL,
.criterium = ROT_SIZE,
.threshold = 1024 * 1024,
+ .minutes = 0,
.minsize = 0,
.maxsize = 0,
.rotateCount = 0,
@@ -1443,6 +1446,26 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
}
} else if (!strcmp(key, "hourly")) {
set_criterium(&newlog->criterium, ROT_HOURLY, &criterium_set);
+ } else if (!strcmp(key, "minutes")) {
+ char *opt = key;
+
+ key = isolateValue(configFile, lineNum, opt, &start, &buf, length);
+ if (key && key[0]) {
+ unsigned int minutes = (unsigned int)strtoul(key, &chptr, 0);
+ if (*chptr != '\0' || minutes <= 0) {
+ message(MESS_ERROR, "%s:%d bad minutes '%s'\n",
+ configFile, lineNum, key);
+ free(opt);
+ RAISE_ERROR();
+ }
+ set_criterium(&newlog->criterium, ROT_MINUTES, &criterium_set);
+ newlog->minutes = minutes;
+ free(opt);
+ }
+ else {
+ free(opt);
+ continue;
+ }
} else if (!strcmp(key, "daily")) {
set_criterium(&newlog->criterium, ROT_DAYS, &criterium_set);
newlog->threshold = 1;
diff --git a/logrotate.8.in b/logrotate.8.in
index 4ff198e..e6c712d 100644
--- a/logrotate.8.in
+++ b/logrotate.8.in
@@ -292,6 +292,11 @@ Log files are rotated the first time \fBlogrotate\fR is run in a month
\fByearly\fR
Log files are rotated if the current year is not the same as the last rotation.
+.TP
+\fBminutes \fIminutes\fR
+Log files are rotated the first time \fBlogrotate\fR is run after \fIminutes\fR
+have expired.
+
.TP
\fBsize \fIsize\fR
Log files are rotated only if they grow bigger than \fIsize\fR bytes. If
diff --git a/logrotate.c b/logrotate.c
index 1292b46..a5cdd90 100644
--- a/logrotate.c
+++ b/logrotate.c
@@ -1479,6 +1479,7 @@ static int findNeedRotating(const struct logInfo *log, unsigned logNum, int forc
} else if (state->lastRotated.tm_year != now.tm_year ||
state->lastRotated.tm_mon != now.tm_mon ||
state->lastRotated.tm_mday != now.tm_mday ||
+ state->lastRotated.tm_min != now.tm_min ||
state->lastRotated.tm_hour != now.tm_hour) {
long days;
switch (log->criterium) {
@@ -1511,6 +1512,18 @@ static int findNeedRotating(const struct logInfo *log, unsigned logNum, int forc
state->lastRotated.tm_hour, state->lastRotated.tm_min);
}
break;
+ case ROT_MINUTES:
+ if (((intmax_t)difftime(nowSecs, mktime(&state->lastRotated)) / 60) > log->minutes) {
+ state->doRotate = 1;
+ }
+ if (!state->doRotate) {
+ message(MESS_DEBUG, " log does not need rotating "
+ "(log has been rotated at %d-%02d-%02d %02d:%02d, "
+ "which is less than %u minutes ago)\n", 1900 + state->lastRotated.tm_year,
+ 1 + state->lastRotated.tm_mon, state->lastRotated.tm_mday,
+ state->lastRotated.tm_hour, state->lastRotated.tm_min, log->minutes);
+ }
+ break;
case ROT_DAYS:
state->doRotate = ((now.tm_mday != state->lastRotated.tm_mday) ||
(now.tm_mon != state->lastRotated.tm_mon) ||
@@ -1870,6 +1883,11 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
final_dformat = "-%Y%m%d%H";
strncpy(dext_pattern, "-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]",
sizeof(dext_pattern));
+ } else if (log->criterium == ROT_MINUTES) {
+ /* minutes adds another four digits */
+ final_dformat = "-%Y%m%d%H%M";
+ strncpy(dext_pattern, "-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]",
+ sizeof(dext_pattern));
} else {
/* The default dateformat and glob pattern */
final_dformat = "-%Y%m%d";
@@ -2370,6 +2388,9 @@ static int rotateLogSet(const struct logInfo *log, int force)
case ROT_HOURLY:
message(MESS_DEBUG, "hourly ");
break;
+ case ROT_MINUTES:
+ message(MESS_DEBUG, "after %u minutes ", log->minutes);
+ break;
case ROT_DAYS:
message(MESS_DEBUG, "after %jd days ", (intmax_t)log->threshold);
break;
diff --git a/logrotate.h b/logrotate.h
index e87a282..df2e940 100644
--- a/logrotate.h
+++ b/logrotate.h
@@ -48,7 +48,8 @@ enum criterium {
ROT_WEEKLY,
ROT_MONTHLY,
ROT_YEARLY,
- ROT_SIZE
+ ROT_SIZE,
+ ROT_MINUTES
};
struct logInfo {
@@ -58,6 +59,7 @@ struct logInfo {
char *oldDir;
enum criterium criterium;
unsigned weekday; /* used by ROT_WEEKLY only */
+ unsigned int minutes; /* used by ROT_MINUTES only */
off_t threshold;
off_t maxsize;
off_t minsize;
diff --git a/logrotate.c b/logrotate.c
index a5cdd90..35ffea7 100644
--- a/logrotate.c
+++ b/logrotate.c
@@ -2102,7 +2102,7 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
continue;
}
- if (((intmax_t)difftime(nowSecs, fst_buf.st_mtime) / DAY_SECONDS) > log->rotateAge) {
+ if (((intmax_t)difftime(nowSecs, fst_buf.st_mtime) / 60) > log->rotateAge) {
if (!hasErrors && log->logAddress)
hasErrors = mailLogWrapper(oldName, mailCommand,
logNum, log);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment