Commit cf6bd7c0 authored by Tobias Frost's avatar Tobias Frost

Import Upstream version 3.8.1

parent e86a2956
3.8.0 -> 3.8.1
- fixed 1 memory leak in prerotateSingleLog
- another fixes for Solaris
- fixed HP-UX compilation and default config
- do not redirect logrotate errors to /dev/null in cron script
- fixed "size" directive parsing
- handle situation when acl_get_fd is supported, but acl_set_fd is not
- added "maxsize" directive (see man page)
3.7.9 -> 3.8.0
- added "dateyesterday" option (see man page)
- fixed crash when config file had exactly 4096*N bytes
......
......@@ -41,16 +41,14 @@ endif
# Solaris using gcc
ifeq ($(OS_NAME),SunOS)
CFLAGS = -I/opt/baw/include -D_GNU_SOURCE -D$(OS_NAME) -DVERSION=\"$(VERSION)\" $(RPM_OPT_FLAGS) $(LFS)
CFLAGS = -D_GNU_SOURCE -D$(OS_NAME) -DVERSION=\"$(VERSION)\" $(RPM_OPT_FLAGS) $(LFS)
CC ?= gcc
CPP = $(CC) -E -M
INSTALL = /usr/ucb/install
ifeq ($(CC),cc)
CPP = cc -xM
endif
ifeq ($(BASEDIR),)
BASEDIR = /usr/local
endif
BASEDIR ?= /usr/local
endif
# Red Hat Linux
......@@ -83,7 +81,7 @@ ifneq ($(STATEFILE),)
endif
BINDIR = $(BASEDIR)/sbin
MANDIR = $(BASEDIR)/man
MANDIR ?= $(BASEDIR)/man
#--------------------------------------------------------------------------
......@@ -95,6 +93,9 @@ CFLAGS += -g
LDFLAGS = -g
endif
LDFLAGS += $(EXTRA_LDFLAGS) $(EXTRA_LIBS)
CFLAGS += $(EXTRA_CPPFLAGS) $(EXTRA_CFLAGS)
ifeq (.depend,$(wildcard .depend))
TARGET=$(PROG)
else
......
#include <sys/queue.h>
#ifdef _ALLOCA_H
#include <alloca.h>
#else
#include <limits.h>
#endif
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
......@@ -41,6 +38,10 @@
#endif
#endif
#ifdef __hpux
#include "asprintf.c"
#endif
#if !defined(asprintf)
#include <stdarg.h>
......@@ -74,6 +75,29 @@ int asprintf(char **string_ptr, const char *format, ...)
#endif
#if !defined(strndup)
char *strndup(const char *s, size_t n)
{
size_t nAvail;
char *p;
if(!s)
return NULL;
/* min() */
nAvail = strlen(s) + 1;
if ( (n + 1) < nAvail)
nAvail = n + 1;
p = malloc(nAvail);
if (!p)
return NULL;
memcpy(p, s, nAvail);
p[nAvail - 1] = 0;
return p;
}
#endif
enum {
STATE_DEFAULT = 2,
STATE_SKIP_LINE = 4,
......@@ -270,6 +294,7 @@ static void copyLogInfo(struct logInfo *to, struct logInfo *from)
to->criterium = from->criterium;
to->threshhold = from->threshhold;
to->minsize = from->minsize;
to->maxsize = from->maxsize;
to->rotateCount = from->rotateCount;
to->rotateAge = from->rotateAge;
to->logStart = from->logStart;
......@@ -484,6 +509,7 @@ int readAllConfigPaths(const char **paths)
.criterium = ROT_SIZE,
.threshhold = 1024 * 1024,
.minsize = 0,
.maxsize = 0,
.rotateCount = 0,
.rotateAge = 0,
.logStart = -1,
......@@ -865,13 +891,13 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
newlog->flags |= LOG_FLAG_CREATE;
} else if (!strcmp(key, "nocreate")) {
newlog->flags &= ~LOG_FLAG_CREATE;
} else if (!strcmp(key, "size") || !strcmp(key, "minsize")) {
} else if (!strcmp(key, "size") || !strcmp(key, "minsize") ||
!strcmp(key, "maxsize")) {
unsigned long long size = 0;
char *opt = key;
if ((key = isolateValue(configFile, lineNum, opt, &start,
&buf, length)) != NULL) {
free(opt);
int l = strlen(key) - 1;
if (key[l] == 'k') {
key[l] = '\0';
......@@ -883,6 +909,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
key[l] = '\0';
multiplier = 1024 * 1024 * 1024;
} else if (!isdigit(key[l])) {
free(opt);
message(MESS_ERROR, "%s:%d unknown unit '%c'\n",
configFile, lineNum, key[l]);
if (newlog != defConfig) {
......@@ -899,6 +926,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
if (*chptr) {
message(MESS_ERROR, "%s:%d bad size '%s'\n",
configFile, lineNum, key);
free(opt);
if (newlog != defConfig) {
state = STATE_ERROR;
continue;
......@@ -906,11 +934,15 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
goto error;
}
}
if (!strncmp(key, "size", 4)) {
if (!strncmp(opt, "size", 4)) {
newlog->criterium = ROT_SIZE;
newlog->threshhold = size;
} else
} else if (!strncmp(opt, "maxsize", 7)) {
newlog->maxsize = size;
} else {
newlog->minsize = size;
}
free(opt);
}
else {
free(opt);
......@@ -1112,7 +1144,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
goto error;
}
}
else continue;
#if 0
if (stat(newlog->oldDir, &sb)) {
message(MESS_ERROR, "%s:%d error verifying olddir "
......@@ -1157,7 +1189,6 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
goto error;
}
}
else continue;
if (access(newlog->compress_prog, X_OK)) {
message(MESS_ERROR,
......@@ -1188,7 +1219,6 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
goto error;
}
}
else continue;
if (access(newlog->uncompress_prog, X_OK)) {
message(MESS_ERROR,
......@@ -1224,7 +1254,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
} else {
goto error;
}
} else continue;
}
if (poptParseArgvString(options,
&newlog->compress_options_count,
......@@ -1257,7 +1287,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
} else {
goto error;
}
} else continue;
}
message(MESS_DEBUG, "compress_ext is now %s\n",
newlog->compress_ext);
......
......@@ -7,7 +7,7 @@
#ifdef __hpux
#define DEFAULT_MAIL_COMMAND "/usr/bin/mailx"
#define COMPRESS_COMMAND "/usr/contrib/bin/gzip"
#define UNCOMPRESS_COMMAND " /usr/contrib/bin/gunzip"
#define UNCOMPRESS_COMMAND "/usr/contrib/bin/gunzip"
#define STATEFILE "/var/run/logrotate.status"
#endif
......
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
......
......@@ -285,7 +285,17 @@ if the logfile is to be rotated. The files are mailed to the
configured address if \fBmaillast\fR and \fBmail\fR are configured.
.TP
\fBminsize\fR \fIsize\fR
\fBmaxsize\fR \fIsize\fR
Log files are rotated when they grow bigger than \fIsize\fR bytes even
before the additionally specified time interval (\fBdaily\fR, \fBweekly\fR,
\fBmonthly\fR, or \fByearly\fR). The related \fBsize\fR option is similar
except that it is mutually exclusive with the time interval options, and it
causes log files to be rotated without regard for the last rotation time.
When \fBmaxsize\fR is used, both the size and timestamp of a log file are
considered.
.TP
\fBminsize\fR \fIsize\fR
Log files are rotated when they grow bigger than \fIsize\fR bytes, but not
before the additionally specified time interval (\fBdaily\fR, \fBweekly\fR,
\fBmonthly\fR, or \fByearly\fR). The related \fBsize\fR option is similar
......
#include <sys/queue.h>
#ifdef _ALLOCA_H
#include <alloca.h>
#else
#include <limits.h>
#endif
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
......@@ -51,6 +48,10 @@ static acl_t prev_acl = NULL;
#define STATEFILE_BUFFER_SIZE 4096
#endif
#ifdef __hpux
extern int asprintf(char **str, const char *fmt, ...);
#endif
struct logState {
char *fn;
struct tm lastRotated; /* only tm.mon, tm_mday, tm_year are good! */
......@@ -413,13 +414,15 @@ static int compressLogFile(char *name, struct logInfo *log, struct stat *sb)
}
if (prev_acl) {
if (acl_set_fd(outFile, prev_acl) == -1) {
message(MESS_ERROR, "setting ACL for %s: %s\n",
compressedName, strerror(errno));
acl_free(prev_acl);
prev_acl = NULL;
close(inFile);
close(outFile);
return 1;
if (errno != ENOTSUP) {
message(MESS_ERROR, "setting ACL for %s: %s\n",
compressedName, strerror(errno));
acl_free(prev_acl);
prev_acl = NULL;
close(inFile);
close(outFile);
return 1;
}
}
acl_free(prev_acl);
prev_acl = NULL;
......@@ -627,14 +630,16 @@ static int copyTruncate(char *currLog, char *saveLog, struct stat *sb,
}
#ifdef WITH_ACL
if (prev_acl) {
if (acl_set_fd(fdsave, prev_acl) == -1) {
message(MESS_ERROR, "setting ACL for %s: %s\n",
saveLog, strerror(errno));
acl_free(prev_acl);
prev_acl = NULL;
close(fdsave);
close(fdcurr);
return 1;
if ((fdsave, prev_acl) == -1) {
if (errno != ENOTSUP) {
message(MESS_ERROR, "setting ACL for %s: %s\n",
saveLog, strerror(errno));
acl_free(prev_acl);
prev_acl = NULL;
close(fdsave);
close(fdcurr);
return 1;
}
}
acl_free(prev_acl);
prev_acl = NULL;
......@@ -787,6 +792,9 @@ int findNeedRotating(struct logInfo *log, int logNum)
state->doRotate = 0;
}
if (log->maxsize && sb.st_size > log->maxsize)
state->doRotate = 1;
/* The notifempty flag overrides the normal criteria */
if (!(log->flags & LOG_FLAG_IFEMPTY) && !sb.st_size)
state->doRotate = 0;
......@@ -1153,6 +1161,8 @@ int prerotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
hasErrors = 1;
}
}
if (hasErrors || i - 1 < 0)
free(oldName);
}
free(newName);
......@@ -1332,9 +1342,11 @@ int rotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
#ifdef WITH_ACL
if (prev_acl) {
if (acl_set_fd(fd, prev_acl) == -1) {
message(MESS_ERROR, "setting ACL for %s: %s\n",
log->files[logNum], strerror(errno));
hasErrors = 1;
if (errno != ENOTSUP) {
message(MESS_ERROR, "setting ACL for %s: %s\n",
log->files[logNum], strerror(errno));
hasErrors = 1;
}
}
acl_free(prev_acl);
prev_acl = NULL;
......@@ -1460,6 +1472,9 @@ int rotateLogSet(struct logInfo *log, int force)
if (log->minsize)
message(MESS_DEBUG, "only log files >= %llu bytes are rotated, ", log->minsize);
if (log->maxsize)
message(MESS_DEBUG, "log files >= %llu are rotated earlier, ", log->minsize);
if (log->logAddress) {
message(MESS_DEBUG, "old logs mailed to %s\n", log->logAddress);
} else {
......
......@@ -36,6 +36,7 @@ struct logInfo {
enum { ROT_DAYS, ROT_WEEKLY, ROT_MONTHLY, ROT_YEARLY, ROT_SIZE,
ROT_FORCE } criterium;
unsigned long long threshhold;
unsigned long long maxsize;
unsigned long long minsize;
int rotateCount;
int rotateAge;
......
Summary: Rotates, compresses, removes and mails system log files
Name: logrotate
Version: 3.8.0
Version: 3.8.1
Release: 1
License: GPL+
Group: System Environment/Base
......@@ -52,6 +52,9 @@ rm -rf $RPM_BUILD_ROOT
%attr(0644, root, root) %verify(not size md5 mtime) %config(noreplace) %{_localstatedir}/lib/logrotate.status
%changelog
* Wed Aug 31 2011 Jan Kaluza <jkaluza@redhat.com> 3.8.1-1
- new upstream version
* Tue Jun 21 2011 Jan Kaluza <jkaluza@redhat.com> 3.8.0-1
- new upstream version
......
......@@ -142,6 +142,7 @@ preptest() {
# we don't want any stuff left from previous runs
cleanup
# ------------------------------- Test 1 -------------------------------------
# Without a log file, no rotations should occur
preptest test.log 1 2
$RLR test-config.1
......@@ -176,6 +177,7 @@ EOF
cleanup 1
# ------------------------------- Test 2 -------------------------------------
preptest test.log 2 3
$RLR test-config.2 --force
......@@ -203,6 +205,7 @@ EOF
cleanup 3
# ------------------------------- Test 3 -------------------------------------
preptest test.log 3 1
preptest test2.log 3 1
$RLR test-config.3 --force
......@@ -217,6 +220,7 @@ EOF
cleanup 4
# ------------------------------- Test 4 -------------------------------------
preptest test.log 4 1
preptest test2.log 4 1
$RLR test-config.4 --force
......@@ -231,6 +235,7 @@ EOF
cleanup 5
# ------------------------------- Test 5 -------------------------------------
preptest test.log 5 1
preptest anothertest.log 5 1
$RLR test-config.5 --force
......@@ -245,6 +250,7 @@ EOF
cleanup 6
# ------------------------------- Test 6 -------------------------------------
preptest test.log 6 1
preptest anothertest.log 6 1
$RLR test-config.6 --force
......@@ -259,6 +265,7 @@ EOF
cleanup 7
# ------------------------------- Test 7 -------------------------------------
preptest test.log 7 1
preptest anothertest.log 7 1
......@@ -274,6 +281,7 @@ EOF
cleanup 8
# ------------------------------- Test 8 -------------------------------------
preptest test.log 8 1 1
$RLR test-config.8 --force
......@@ -287,6 +295,7 @@ checkmail test.log zero
cleanup 9
# ------------------------------- Test 9 -------------------------------------
preptest test.log 9 1 1
$RLR test-config.9 --force
......@@ -299,6 +308,7 @@ checkmail test.log zero
cleanup 10
# ------------------------------- Test 10 ------------------------------------
preptest test.log 10 1
$RLR test-config.10 --force
......@@ -320,6 +330,7 @@ checkmail test.log.1 newfile
cleanup 11
# ------------------------------- Test 11 ------------------------------------
preptest test.log 11 2 1
$RLR test-config.11 --force
......@@ -333,6 +344,7 @@ checkmail test.log first
# check rotation into a directory given as a relative pathname
cleanup 12
# ------------------------------- Test 12 ------------------------------------
preptest test.log 12 1 0
rm -rf testdir
mkdir testdir
......@@ -348,6 +360,7 @@ rm -rf testdir
# check rotation into a directory given as an absolute pathname
cleanup 13
# ------------------------------- Test 13 ------------------------------------
preptest test.log 13 1 0
rm -rf testdir
mkdir testdir
......@@ -363,6 +376,7 @@ rm -rf testdir
# sanity rotation check using dateext and dateformat
cleanup 14
# ------------------------------- Test 14 ------------------------------------
preptest test.log 14 1 0
$RLR test-config.14 --force
......@@ -379,9 +393,8 @@ rm -rf testdir
# shred test
cleanup 15
# ------------------------------- Test 15 ------------------------------------
preptest test.log 15 1 0
rm -rf testdir
mkdir testdir
$RLR test-config.15 --force
# this rotation should use shred
......@@ -392,6 +405,26 @@ test.log 0
test.log.1 0
EOF
rm -rf testdir
cleanup 16
cleanup
# ------------------------------- Test 16 ------------------------------------
preptest test.log 16 1 0
# log with 1 byte should not be rotated
echo "a" > test.log
$RLR test-config.16
if [ -f test.log.1 ]; then
echo "file $file does exist!"
exit 2
fi
# log with 4 bytes should be rotated
echo "zero" > test.log
$RLR test-config.16
checkoutput <<EOF
test.log 0
test.log.1 0 zero
EOF
# cleanup
create
&DIR&/test.log {
weekly
maxsize 4
rotate 1
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment