Commit d99ab330 authored by Tobias Frost's avatar Tobias Frost

Import Upstream version 3.8.2

parent cf6bd7c0
3.8.1 -> 3.8.2
- show error and ignore config if '{' is not present after log files
declaration
- support whitespaces in compressoptions directive
- support for tilde expansion in config files
- 'su' directive does not affect script execution - scripts
are executed as a root if 'su' directive is present
- fixed mail sending for 'mailfirst', 'dateext' and 'delaycompress'
combination
- do not use gzip/gunzip from /usr/local on Solaris
- add O_NOFOLLOW when opening files as safeguard against symlink tricks.
Symlinks rotation is now officially unsupported. It didn't work
as expected in the past anyway.
- do not run external programs with uid != euid
- fixed potential bad-free when ACL is used
- Do not include alloca.h on NetBSD, since alloca() is declared in
stdlib.h there
- 13 new tests added
3.8.0 -> 3.8.1
- fixed 1 memory leak in prerotateSingleLog
- another fixes for Solaris
......
......@@ -119,23 +119,23 @@ test: $(TARGET)
(cd test; ./test)
install:
[ -d $(PREFIX)/$(BINDIR) ] || mkdir -p $(PREFIX)/$(BINDIR)
[ -d $(PREFIX)/$(MANDIR) ] || mkdir -p $(PREFIX)/$(MANDIR)
[ -d $(PREFIX)/$(MANDIR)/man8 ] || mkdir -p $(PREFIX)/$(MANDIR)/man8
[ -d $(PREFIX)/$(MANDIR)/man5 ] || mkdir -p $(PREFIX)/$(MANDIR)/man5
[ -d $(PREFIX)$(BINDIR) ] || mkdir -p $(PREFIX)$(BINDIR)
[ -d $(PREFIX)$(MANDIR) ] || mkdir -p $(PREFIX)$(MANDIR)
[ -d $(PREFIX)$(MANDIR)/man8 ] || mkdir -p $(PREFIX)$(MANDIR)/man8
[ -d $(PREFIX)$(MANDIR)/man5 ] || mkdir -p $(PREFIX)$(MANDIR)/man5
if [ "$(OS_NAME)" = HP-UX ]; then \
$(INSTALL) $(PROG) $(PREFIX)/$(BINDIR) 0755 bin bin; \
$(INSTALL) $(MAN) $(PREFIX)/$(MANDIR)/man`echo $(MAN) | sed "s/.*\.//"` 0644 bin bin; \
$(INSTALL) $(MAN5) $(PREFIX)/$(MANDIR)/man`echo $(MAN5) | sed "s/.*\.//"` 0644 bin bin; \
$(INSTALL) $(PROG) $(PREFIX)$(BINDIR) 0755 bin bin; \
$(INSTALL) $(MAN) $(PREFIX)$(MANDIR)/man`echo $(MAN) | sed "s/.*\.//"` 0644 bin bin; \
$(INSTALL) $(MAN5) $(PREFIX)$(MANDIR)/man`echo $(MAN5) | sed "s/.*\.//"` 0644 bin bin; \
else if [ "$(OS_NAME)" = FreeBSD ]; then \
$(BSD_INSTALL_PROGRAM) $(PROG) $(BINDIR); \
$(BSD_INSTALL_MAN) $(MAN) $(MANDIR)/man`echo $(MAN) | sed "s/.*\.//"`/$(MAN); \
$(BSD_INSTALL_MAN) $(MAN5) $(MANDIR)/man`echo $(MAN5) | sed "s/.*\.//"`/$(MAN5); \
else \
$(INSTALL) -m 755 $(PROG) $(PREFIX)/$(BINDIR); \
$(INSTALL) -m 644 $(MAN) $(PREFIX)/$(MANDIR)/man`echo $(MAN) | sed "s/.*\.//"`/$(MAN); \
$(INSTALL) -m 644 $(MAN5) $(PREFIX)/$(MANDIR)/man`echo $(MAN5) | sed "s/.*\.//"`/$(MAN5); \
$(INSTALL) -m 755 $(PROG) $(PREFIX)$(BINDIR); \
$(INSTALL) -m 644 $(MAN) $(PREFIX)$(MANDIR)/man`echo $(MAN) | sed "s/.*\.//"`/$(MAN); \
$(INSTALL) -m 644 $(MAN5) $(PREFIX)$(MANDIR)/man`echo $(MAN5) | sed "s/.*\.//"`/$(MAN5); \
fi; fi
co:
......
#include <sys/queue.h>
/* Alloca is defined in stdlib.h in NetBSD */
#ifndef __NetBSD__
#include <alloca.h>
#endif
#include <limits.h>
#include <ctype.h>
#include <dirent.h>
......@@ -190,7 +193,7 @@ static char *readPath(const char *configFile, int lineNum, char *key,
chptr = start;
while( (len = mbrtowc(&pwc, chptr, strlen(chptr), NULL)) != 0 ) {
while( (len = mbrtowc(&pwc, chptr, strlen(chptr), NULL)) != 0 && strlen(chptr) != 0) {
if( len == (size_t)(-1) || len == (size_t)(-2) || !iswprint(pwc) || iswblank(pwc) ) {
message(MESS_ERROR, "%s:%d bad %s path %s\n",
configFile, lineNum, key, start);
......@@ -317,6 +320,7 @@ static void copyLogInfo(struct logInfo *to, struct logInfo *from)
if (from->compress_ext)
to->compress_ext = strdup(from->compress_ext);
to->flags = from->flags;
to->shred_cycles = from->shred_cycles;
to->createMode = from->createMode;
to->createUid = from->createUid;
to->createGid = from->createGid;
......@@ -599,6 +603,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
struct logInfo *log;
static unsigned recursion_depth = 0U;
char *globerr_msg = NULL;
int in_config = 0;
struct flock fd_lock = {
.l_start = 0,
.l_len = 0,
......@@ -1244,10 +1249,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
newlog->compress_options_count = 0;
}
if (!
(options =
readPath(configFile, lineNum, "compressoptions",
&start, &buf, length))) {
if (!(options = isolateLine(&start, &buf, length))) {
if (newlog != defConfig) {
state = STATE_ERROR;
continue;
......@@ -1299,7 +1301,12 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
}
free(key);
key = NULL;
} else if (*start == '/' || *start == '"' || *start == '\'') {
} else if (*start == '/' || *start == '"' || *start == '\''
#ifdef GLOB_TILDE
|| *start == '~'
#endif
) {
in_config = 0;
if (newlog != defConfig) {
message(MESS_ERROR, "%s:%d unexpected log filename\n",
configFile, lineNum);
......@@ -1322,10 +1329,23 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
goto error;
endtag = start;
while (endtag - buf < length && *endtag != '{' && *endtag != '\0') {
while (endtag - buf < length && *endtag != '{' && *endtag != '}' && *endtag != '\0') {
endtag++;}
if (endtag - buf > length)
continue;
if (*endtag == '}') {
message(MESS_ERROR, "%s:%d unexpected } (missing previous '{')\n", configFile,
lineNum);
goto error;
}
if (*endtag == '{') {
in_config = 1;
}
else {
message(MESS_ERROR, "%s:%d missing '{' after log files definition\n", configFile,
lineNum);
goto error;
}
char *key = strndup(start, endtag - start);
start = endtag;
......@@ -1350,8 +1370,11 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
globerr_msg = NULL;
}
rc = glob(argv[argNum], GLOB_NOCHECK, globerr,
&globResult);
rc = glob(argv[argNum], GLOB_NOCHECK
#ifdef GLOB_TILDE
| GLOB_TILDE
#endif
, globerr, &globResult);
if (rc == GLOB_ABORTED) {
if (newlog->flags & LOG_FLAG_MISSINGOK) {
continue;
......@@ -1417,6 +1440,12 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
lineNum);
goto error;
}
if (!in_config) {
message(MESS_ERROR, "%s:%d unexpected } (missing previous '{')\n", configFile,
lineNum);
goto error;
}
in_config = 0;
if (globerr_msg) {
if (!(newlog->flags & LOG_FLAG_MISSINGOK))
message(MESS_ERROR, "%s", globerr_msg);
......@@ -1570,7 +1599,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
}
}
if (scriptStart) {
message(MESS_ERROR,
"%s:prerotate or postrotate without endscript\n",
......
......@@ -13,16 +13,14 @@
#ifdef SunOS
#define DEFAULT_MAIL_COMMAND "/usr/bin/mailx"
#define COMPRESS_COMMAND "/usr/local/bin/gzip"
#define UNCOMPRESS_COMMAND "/usr/local/bin/gunzip"
#define STATEFILE "/var/log/logrotate.status"
#endif
#ifdef __NetBSD__
#define DEFAULT_MAIL_COMMAND "/usr/bin/mail -s"
#define COMPRESS_COMMAND "/usr/bin/gzip"
#define UNCOMPRESS_COMMAND "/usr/bin/gunzip"
#define STATEFILE "/var/log/logrotate.status"
#define DEFAULT_MAIL_COMMAND "/usr/bin/mail -s"
#define COMPRESS_COMMAND "/usr/bin/gzip"
#define UNCOMPRESS_COMMAND "/usr/bin/gunzip"
#define STATEFILE "/var/log/logrotate.status"
#endif
/*
......
......@@ -110,6 +110,9 @@ compress
endscript
nocompress
}
~/log/*.log {}
.fi
.PP
......@@ -135,11 +138,15 @@ quotes around the first filename at the beginning of this section allows
logrotate to rotate logs with spaces in the name. Normal shell quoting rules
apply, with ', ", and \\ characters supported.
The last section defines the parameters for all of the files in
The next section defines the parameters for all of the files in
\fI/var/log/news\fR. Each file is rotated on a monthly basis. This is
considered a single rotation directive and if errors occur for more than
one file, the log files are not compressed.
The last section uses tilde expansion to rotate log files in the home
directory of the current user. This is only available, if your glob
library supports tilde expansion. GNU glob does support this.
Please use wildcards with caution. If you specify *, \fBlogrotate\fR will
rotate all files, including previously rotated ones. A way around this
is to use the \fBolddir\fR directive or a more exact wildcard (such as *.log).
......@@ -434,8 +441,8 @@ are removed rather than rotated.
Log files are rotated only if they grow bigger then \fIsize\fR bytes. If
\fIsize\fR is followed by \fIk\fR, the size is assumed to be in kilobytes.
If the \fIM\fR is used, the size is in megabytes, and if \fIG\fR is used, the
size is in gigabytes. So \fBsize 100\fR, \fIsize 100k\fR, \fIsize 100M\fR and
\fIsize 100G\f are all valid.
size is in gigabytes. So \fIsize 100\fR, \fIsize 100k\fR, \fIsize 100M\fR and
\fIsize 100G\fR are all valid.
.TP
\fBsharedscripts\fR
......@@ -459,7 +466,7 @@ off by default. See also \fBnoshred\fR.
.TP
\fBshredcycles\fR \fIcount\fR
Asks GNU \fBshred\fR(1) to overwite log files \fBcount\fR times before
Asks GNU \fBshred\fR(1) to overwrite log files \fBcount\fR times before
deletion. Without this option, \fBshred\fR's default will be used.
.TP
......
This diff is collapsed.
Summary: Rotates, compresses, removes and mails system log files
Name: logrotate
Version: 3.8.1
Version: 3.8.2
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
* Thu Jul 19 2012 Jan Kaluza <jkaluza@redhat.com> 3.8.2-1
- new upstream version
* Wed Aug 31 2011 Jan Kaluza <jkaluza@redhat.com> 3.8.1-1
- new upstream version
......
#!/bin/bash
echo "gzip $*" > compress-args
gzip $*
\ No newline at end of file
......@@ -6,7 +6,7 @@ S=-"s state"
RLR="$LOGROTATE $M $S"
cleanup() {
rm -f test*.log* anothertest*.log* state test-config. scriptout mail-out
rm -f test*.log* anothertest*.log* state test-config. scriptout mail-out compress-args
rm -f $(ls | egrep '^test-config.[0-9]+$')
[ -n "$1" ] && echo "Running test $1"
......@@ -427,4 +427,242 @@ test.log 0
test.log.1 0 zero
EOF
# cleanup
cleanup 17
# ------------------------------- Test 17 ------------------------------------
preptest test.log 17 1 0
# log with 1 byte should not be rotated
$RLR test-config.17 2>error.log
grep "unexpected } (missing previous '{')" error.log >/dev/null
if [ $? != 0 ]; then
echo "No error printed, but there should be one."
exit 3
fi
rm error.log
checkoutput <<EOF
test.log 0 zero
EOF
cleanup 18
# ------------------------------- Test 18 ------------------------------------
preptest test.log 18 1
$RLR test-config.18 --force
checkoutput <<EOF
test.log 0
test.log.1.gz 1 zero
EOF
(echo "gzip -f -9") | diff -u - compress-args
cleanup 19
# ------------------------------- Test 19 ------------------------------------
preptest test.log 19 1
$RLR test-config.19 --force 2>error.log
if [ $? == 0 ]; then
echo "Logrotate exited with 0 exit code, but it should not"
fi
grep "error running non-shared postrotate script for" error.log >/dev/null
if [ $? != 0 ]; then
echo "No error printed, but there should be one."
exit 3
fi
cleanup 20
# ------------------------------- Test 20 ------------------------------------
preptest test.log 20 1
$RLR test-config.20 --force 2>error.log
if [ $? == 0 ]; then
echo "Logrotate exited with 0 exit code, but it should not"
fi
grep "error running shared postrotate script for" error.log >/dev/null
if [ $? != 0 ]; then
echo "No error printed, but there should be one."
exit 3
fi
cleanup 21
# ------------------------------- Test 21 ------------------------------------
# different base name, so it should not find the file
preptest differenttest.log 21 1
$RLR test-config.21 --force 2>error.log
if [ $? != 0 ]; then
echo "Logrotate exited with non-zero exit code, but it should not"
fi
cat error.log
# grep "error running shared postrotate script for" error.log >/dev/null
# if [ $? != 0 ]; then
# echo "No error printed, but there should be one."
# exit 3
# fi
cleanup 22
# ------------------------------- Test 22 ------------------------------------
# different base name, so it should not find the file
preptest differenttest.log 22 1
$RLR test-config.22 --force 2>error.log
if [ $? == 0 ]; then
echo "Logrotate exited with zero exit code, but it should not"
fi
grep "error: stat of" error.log >/dev/null
if [ $? != 0 ]; then
echo "No error printed, but there should be one."
exit 3
fi
cleanup 23
# ------------------------------- Test 23 ------------------------------------
# symlinks - symlinks rotation is not allowed for security reasons.
preptest test.log.original 23 1
ln -s test.log.original test.log
$RLR test-config.23 --force 2>error.log
checkoutput <<EOF
test.log 0 zero
test.log.original 0 zero
EOF
rm -f test.log 2>/dev/null || true
cleanup 24
# ------------------------------- Test 24 ------------------------------------
# symlinks 2 - now copytruncate is used, but symlinks rotation is not allowed for
# security reasons.
# since logrotate-3.8.2, we don't support symlinks rotation officially.
preptest test.log.original 24 1
ln -s test.log.original test.log
$RLR test-config.24 --force 2>error.log
checkoutput <<EOF
test.log 0 zero
test.log.original 0 zero
EOF
rm -f test.log 2>/dev/null || true
cleanup 25
# ------------------------------- Test 25 ------------------------------------
# If there is no '{' character after log files definition, error should be printed
# and config file should be skipped
preptest test.log 25 1 0
# log with 1 byte should not be rotated
$RLR test-config.25 2>error.log
grep "missing '{' after log files definition" error.log >/dev/null
if [ $? != 0 ]; then
echo "No error printed, but there should be one."
exit 3
fi
rm error.log
checkoutput <<EOF
test.log 0 zero
EOF
cleanup 26
# ------------------------------- Test 26 ------------------------------------
# If there is error in config file, log should not be rotated and original log
# should be untouched
preptest test.log 26 1 0
# log with 1 byte should not be rotated
$RLR test-config.26 2>error.log
grep "unknown option" error.log >/dev/null
if [ $? != 0 ]; then
echo "No error printed, but there should be one."
exit 3
fi
rm error.log
checkoutput <<EOF
test.log 0
test.log.1 0 zero
EOF
cleanup 27
# ------------------------------- Test 27 ------------------------------------
# logrotate fails to find the correct file to mail, when using "mailfirst" in
# combination with "delaycompress" and "dateext" option.
preptest test.log 27 1 0
DATESTRING=$(/bin/date +%Y%m%d)
$RLR test-config.27 --force
checkoutput <<EOF
test.log 0
test.log-$DATESTRING 0 zero
EOF
checkmail test.log-$DATESTRING zero
cleanup 28
# ------------------------------- Test 28 ------------------------------------
# { on new line
preptest test.log 28 1 0
# log with 1 byte should not be rotated
$RLR test-config.28
checkoutput <<EOF
test.log 0
test.log.1 0 zero
EOF
cleanup 29
# ------------------------------- Test 29 ------------------------------------
# { } on the same line
preptest test.log 29 1 0
# log with 1 byte should not be rotated
$RLR test-config.29 --force
checkoutput <<EOF
test.log 0
test.log.1 0 zero
EOF
cleanup 30
# ------------------------------- Test 30 ------------------------------------
# the file with the same date already exists, so it should not be overwritten
# and log should not be rotated
preptest test.log 30 1 0
DATESTRING=$(/bin/date +%Y%m%d)
echo "one" > test.log-$DATESTRING
$RLR test-config.30 --force
checkoutput <<EOF
test.log 0 zero
test.log-$DATESTRING 0 one
EOF
cleanup
create
# missing { is OK, we're testing parsing here
&DIR&/test.log
weekly
maxsize 4
rotate 1
}
create
# tests more compressoptions
&DIR&/test.log {
compress
compresscmd ./compress
compressoptions -f -9
weekly
rotate 1
}
create
&DIR&/test*.log {
daily
rotate 1
postrotate
exit 1
endscript
}
create
&DIR&/test*.log {
daily
rotate 1
sharedscripts
postrotate
exit 1
endscript
}
create
&DIR&/test*.log {
daily
rotate 1
missingok
}
create
&DIR&/test*.log {
daily
rotate 1
}
create
&DIR&/test*.log {
daily
rotate 1
}
create
&DIR&/test*.log {
daily
copytruncate
rotate 1
}
create
# missing { is OK, we're testing parsing here
&DIR&/test.log
weekly
maxsize 4
rotate 1
create
&DIR&/test.log {
waeekly
maxsize 4
rotate 1
}
\ No newline at end of file
create
&DIR&/test.log {
daily
rotate 999
compress
dateext
ifempty
delaycompress
mailfirst
mail user@myhost.org
}
create
#testing { on new line
&DIR&/test.log
{
weekly
maxsize 4
rotate 1
}
create
rotate 1
daily
#testing { } on the same line
&DIR&/test.log { }
create
&DIR&/test.log {
daily
rotate 999
dateext
}
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