Commit bc491699 authored by Tobias Frost's avatar Tobias Frost

Import Upstream version 3.7

parent 958d01f3
3.6.8 -> 3.7:
- always use compressext for the extension for compressed
files; before compresscmd and compressext had to agree
- moved all compression to one code block
- compression, scripts don't use system() anymore
- compress and maillast didn't work together properly
- delaycompress and mailfirst didn't work properly
- don't use system() for mailing (or uncompressing) logs anymore
- use "-s" for speciying the subjected of mailed logs
3.5.4 -> 3.6:
- See .spec file for changes
3.5.3 -> 3.5.4:
- %defattr(-,root,root) in specfile
......
VERSION = $(shell awk '/Version:/ { print $$2 }' logrotate.spec)
CVSROOT = $(shell cat CVS/Root)
CVSTAG = r$(subst .,-,$(VERSION))
LFS = $(shell echo `getconf LFS_CFLAGS`)
CFLAGS = -Wall -D_GNU_SOURCE -DVERSION=\"$(VERSION)\" $(RPM_OPT_FLAGS) $(LFS)
OS_NAME = $(shell uname -s)
LFS = $(shell echo `getconf LFS_CFLAGS 2>/dev/null`)
CFLAGS = -Wall -D_GNU_SOURCE -D$(OS_NAME) -DVERSION=\"$(VERSION)\" $(RPM_OPT_FLAGS) $(LFS)
PROG = logrotate
BINDIR = /usr/sbin
MANDIR = /usr/man
MAN = logrotate.8
LOADLIBES = -lpopt
ifeq ($(WITH_SELINUX),yes)
CFLAGS += -DWITH_SELINUX
LOADLIBES += -lselinux
endif
# HP-UX using GCC
ifeq ($(OS_NAME),HP-UX)
ifeq ($(RPM_OPT_FLAGS),)
RPM_OPT_FLAGS = -O2
endif
CC = gcc
INSTALL = cpset
ifeq ($(POPT_DIR),)
POPT_DIR = /usr/local
endif
ifeq ($(HPLX_DIR),)
HPLX_DIR = /usr/local/hplx
endif
LOADLIBES += -lhplx -L$(HPLX_DIR)/lib
ifeq ($(BASEDIR),)
BASEDIR = /usr/local
endif
endif
# Solaris using gcc
ifeq ($(OS_NAME),SunOS)
ifeq ($(RPM_OPT_FLAGS),)
RPM_OPT_FLAGS = -O2
endif
CC = gcc
INSTALL = install
ifeq ($(BASEDIR),)
BASEDIR = /usr/local
endif
endif
# Red Hat Linux
ifeq ($(OS_NAME),Linux)
INSTALL = install
BASEDIR = /usr
endif
ifneq ($(POPT_DIR),)
CFLAGS += -I$(POPT_DIR)
LOADLIBES += -L$(POPT_DIR)
endif
ifneq ($(STATEFILE),)
CFLAGS += -DSTATEFILE=\"$(STATEFILE)\"
endif
BINDIR = $(BASEDIR)/sbin
MANDIR = $(BASEDIR)/man
#--------------------------------------------------------------------------
OBJS = logrotate.o log.o config.o basenames.o
......@@ -31,13 +85,13 @@ all: $(TARGET)
$(PROG): $(OBJS)
clean:
rm -f $(OBJS) $(PROG) core*
rm -f $(OBJS) $(PROG) core* .depend
depend:
$(CPP) $(CFLAGS) -M $(SOURCES) > .depend
.PHONY : test
test:
test: $(TARGET)
(cd test; ./test)
install:
......@@ -45,19 +99,24 @@ install:
[ -d $(PREFIX)/$(MANDIR) ] || mkdir -p $(PREFIX)/$(MANDIR)
[ -d $(PREFIX)/$(MANDIR)/man8 ] || mkdir -p $(PREFIX)/$(MANDIR)/man8
install -s -m 755 $(PROG) $(PREFIX)/$(BINDIR)
install -m 644 $(MAN) $(PREFIX)/$(MANDIR)/man`echo $(MAN) | sed "s/.*\.//"`/$(MAN)
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; \
else \
$(INSTALL) -m 755 $(PROG) $(PREFIX)/$(BINDIR); \
$(INSTALL) -m 644 $(MAN) $(PREFIX)/$(MANDIR)/man`echo $(MAN) | sed "s/.*\.//"`/$(MAN); \
fi
co:
co RCS/*,v
(cd examples; co RCS/*,v)
cvstag:
cvs tag -F $(CVSTAG) .
cvs tag -cF $(CVSTAG) .
archive: cvstag
@rm -rf /tmp/logrotate-$(VERSION) /tmp/logrotate
@cd /tmp; cvs export -r$(CVSTAG) logrotate; mv logrotate logrotate-$(VERSION)
@cd /tmp; cvs -d $(CVSROOT) export -r$(CVSTAG) logrotate; mv logrotate logrotate-$(VERSION)
@cd /tmp/logrotate-$(VERSION)
@cd /tmp; tar czSpf logrotate-$(VERSION).tar.gz logrotate-$(VERSION)
@rm -rf /tmp/logrotate-$(VERSION)
......
How to build and install logrotate on HP-UX 11.00 (these instructions should
also work on HP-UX 10.20):
1. Obtain and install the following GNU packages for HP-UX:
binutils 2.9.1
gcc 2.95.2
make 3.78.1
I used the packages at the Software Porting and Archive Centre for HP-UX
at http://hpux.cs.utah.edu/.
Obtain and install the following GNU/Linux to HP-UX Porting package:
libhplx library
See http://devresource.hp.com/LPK/index.html for downloads.
This library is needed to provide the ??? function.
2. Obtain, build, and install popt 1.4 (there doesn't seem to be a build at
the Porting Centre.)
See ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.0.x/popt-1.6.4.tar.gz
Install it into the directory of your choice (i.e.
"./configure --prefix=/opt/popt").
3. Build logrotate, telling it where to find popt and hplx installation. The
POPT_DIR defaults to /usr/local and HPLX_DIR defaults to /usr/local/hplx:
gmake POPT_DIR=/usr/local HPLX_DIR=/usr/local/hplx
4. Install logrotate into your desired directory (BASEDIR defaults to
/usr/local):
gmake install BASEDIR=/usr/local
5. Copy the configuration files into your desired location.
cp examples/logrotate-default /etc/logrotate.conf
mkdir /etc/logrotate.d
6. Set up a cron job to run logrotate daily. See examples/logrotate.cron.
7. I also recommend setting CLEAN_ADM=0 in /etc/rc.config.d/clean, and
setting up an init script to use logrotate for this instead. This way,
logrotate manages all logfile pruning.
Questions, comments, abuse to:
Paul D. Gear <citecpdg@citec.qld.gov.au>, <paulgear@bigfoot.com>
Danial M. Howard <howadani@isu.edu>, <dmhoward@byu.edu>
Steps to build and install logrotate on Solaris 2.6
1. Obtain and install the following GNU packages from http://Sunfreeware.com:
gcc 2.95.2
make 3.80
popt-1.6.3
2. Build and install logrotate:
gmake
gmake install
OBS.: If you want to use the test script on Solaris 2.6, you'll need to have
bash installed, adjust the path after the sha-bang (#!) properly and
substitute the sintax $(...) for backticks `...` in all
"test-config.?.in" files.
--
Fidelis Assis <fidelis@embratel.net.br>
......@@ -23,9 +23,8 @@ static void stripTrailingSlashes(char *path) {
char * ourDirName(char * origname) {
char * slash;
char * name;
int i = strlen(origname);
name = strcpy(malloc(i + 1), origname);
name = strdup(origname);
stripTrailingSlashes(name);
......
This diff is collapsed.
/*
* OS-specific definitions
*/
#ifdef __hpux
#define DEFAULT_MAIL_COMMAND "/usr/bin/mailx -s"
#define COMPRESS_COMMAND "/usr/contrib/bin/gzip"
#define UNCOMPRESS_COMMAND " /usr/contrib/bin/gunzip"
#define STATEFILE "/var/run/logrotate.status"
#endif
#ifdef SunOS
#define DEFAULT_MAIL_COMMAND "/usr/bin/mailx -s"
#define COMPRESS_COMMAND "/usr/local/bin/gzip"
#define UNCOMPRESS_COMMAND "/usr/local/bin/gunzip"
#define STATEFILE "/var/log/logrotate.status"
#endif
/*
* Default settings for Linux - leave these last.
*/
#ifndef DEFAULT_MAIL_COMMAND
#define DEFAULT_MAIL_COMMAND "/bin/mail -s"
#endif
#ifndef COMPRESS_COMMAND
#define COMPRESS_COMMAND "/bin/gzip"
#endif
#ifndef COMPRESS_EXT
#define COMPRESS_EXT ".gz"
#endif
#ifndef UNCOMPRESS_COMMAND
#define UNCOMPRESS_COMMAND "/bin/gunzip"
#endif
#ifndef STATEFILE
#define STATEFILE "/var/lib/logrotate.status"
#endif
......@@ -14,7 +14,7 @@ create
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own lastlog or wtmp -- we'll rotate them here
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
......
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
.TH LOGROTATE 8 "Thu Aug 02 2001"
.TH LOGROTATE 8 "Wed Nov 5 2002" "Red Hat Linux" "System Administrator's Manual"
.UC 4
.SH NAME
logrotate \- rotates, compresses, and mails system logs
......@@ -42,11 +42,19 @@ this is necessary. Sometimes this is useful after adding new entries to
\fBlogrotate\fR, or if old log files have been removed by hand, as the
new files will be created, and logging will continue correctly.
.TP
\fB-m, -\-mail <command>\fR
Tells \fBlogrotate\fR which command to use when mailing logs. This
command should accept two arguments: 1) the subject of the message, and
2) the recipient. The command must then read a message on standard input
and mail it to the recipient. The default mail command is \fB/bin/mail
-s\fR.
.TP
\fB-s, -\-state <statefile>\fR
Tells \fBlogrotate\fR to use an alternate state file. This is useful
if logrotate is being run as a different user for various sets of
log files. The default state file is \fB/var/lib/logrotate.status\fR.
log files. The default state file is \fI/var/lib/logrotate/status\fR.
.TP
\fB-\-usage\fR
......@@ -83,9 +91,10 @@ compress
endscript
}
/var/log/news/* {
/var/log/news/news.crit {
monthly
rotate 2
olddir /var/log/news/old
missingok
postrotate
kill -HUP `cat /var/run/inn.pid`
......@@ -107,7 +116,7 @@ version of the log has been compressed), the command
\fI/sbin/killall -HUP syslogd\fR will be executed.
The next section defines the parameters for both
\fI/var/log/httpd/access.log\fRand \fI/var/log/httpd/error.log\fR.
\fI/var/log/httpd/access.log\fR and \fI/var/log/httpd/error.log\fR.
They are rotated whenever is grows over 100k is size, and the old logs
files are mailed (uncompressed) to www@my.org after going through 5
rotations, rather then being removed. The \fBsharedscripts\fR means that
......@@ -117,11 +126,15 @@ 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 definest the parameters for all of the files in
The last 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 then
one file, the log files are not compressed.
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).
Here is more information on the directives which may be included in
a \fBlogrotate\fR configuration file:
......@@ -151,6 +164,14 @@ command.
Command line options may be passed to the compression program, if one is
in use. The default, for \fBgzip\fR, is "-9" (maximum compression).
.TP
\fBcopy\fR
Make a copy of the log file, but don't change the original at all.
This option can be used, for instance, to make a snapshot of the current
log file, or when some other utility needs to truncate or pare the file.
When this option is used, the \fBcreate\fR option will have no effect,
as the old log file stays in place.
.TP
\fBcopytruncate\fR
Truncate the original log file in place after creating a copy,
......@@ -198,14 +219,15 @@ option (ifempty is the default).
.TP
\fBinclude \fIfile_or_directory\fR
Reads the file given as an argument as if it was included inline where
the \fBinclude\fR directive appears. If a directory is given, most of the
files in that directory are read before processing of the including file
continues. The only files which are ignored are files which are not regular
files (such as directories and named pipes) and files whose names end
with one of the taboo extensions, as specified by the \fBtabooext\fR
directive. The \fBinclude\fR directive may not appear inside of a log
file definition.
Reads the file given as an argument as if it was included inline
where the \fBinclude\fR directive appears. If a directory is given,
most of the files in that directory are read in alphabetic order
before processing of the including file continues. The only files
which are ignored are files which are not regular files (such as
directories and named pipes) and files whose names end with one of
the taboo extensions, as specified by the \fBtabooext\fR directive.
The \fBinclude\fR directive may not appear inside of a log file
definition.
.TP
\fBmail \fIaddress\fR
......@@ -238,6 +260,11 @@ Log files are rotated the first time \fBlogrotate\fR is run in a month
Old versions of log files are not compressed with \fBgzip\fR. See also
\fBcompress\fR.
.TP
\fBnocopy\fR
Do not copy the original log file and leave it in place.
(this overrides the \fBcopy\fR option).
.TP
\fBnocopytruncate\fR
Do not truncate the original log file in place after creating a copy
......@@ -277,14 +304,16 @@ Do not rotate the log if it is empty (this overrides the \fBifempty\fR option).
.TP
\fBolddir \fIdirectory\fR
Logs are moved into \fIdirectory\fR for rotation. The \fIdirectory\fR must
be on the same physical device as the log file being rotated. When this
option is used all old versions of the log end up in \fIdirectory\fR. This
option may be overriden by the \fBnoolddir\fR option.
Logs are moved into \fIdirectory\fR for rotation. The \fIdirectory\fR
must be on the same physical device as the log file being rotated,
and is assumed to be relative to the directory holding the log file
unless an absolute path name is specified. When this option is used all
old versions of the log end up in \fIdirectory\fR. This option may be
overriden by the \fBnoolddir\fR option.
.TP
\fBpostrotate\fR/\fBendscript\fR
The lines between \fIpostrotate\fR and \fIendscript\fR (both of which
The lines between \fBpostrotate\fR and \fBendscript\fR (both of which
must appear on lines by themselves) are executed after the log file is
rotated. These directives may only appear inside of a log file definition.
See \fBprerotate\fR as well.
......@@ -293,8 +322,25 @@ See \fBprerotate\fR as well.
\fBprerotate\fR/\fBendscript\fR
The lines between \fBprerotate\fR and \fBendscript\fR (both of which
must appear on lines by themselves) are executed before the log file is
rotated. These directives may only appear inside of a log file definition.
See \fBpostrotate\fR as well.
rotated and only if the log will actually be rotated. These directives
may only appear inside of a log file definition. See \fBpostrotate\fR
as well.
.TP
\fBfirstaction\fR/\fBendscript\fR
The lines between \fBfirstaction\fR and \fBendscript\fR (both of which
must appear on lines by themselves) are executed once before all log
files that match the wildcarded pattern are rotated, before prerotate script
is run and only if at least one log will actually be rotated. These directives
may only appear inside of a log file definition. See \fBlastaction\fR as well.
.TP
\fBlastaction\fR/\fBendscript\fR
The lines between \fBlastaction\fR and \fBendscript\fR (both of which
must appear on lines by themselves) are executed once after all log
files that match the wildcarded pattern are rotated, after postrotate script
is run and only if at least one log is rotated. These directives may only
appear inside of a log file definition. See \fBlastaction\fR as well.
.TP
\fBrotate \fIcount\fR
......@@ -316,10 +362,17 @@ log which is rotated, meaning that a single script may be run multiple
times for log file entries which match multiple files (such as the
/var/log/news/* example). If \fBsharedscript\fR is specified, the scripts
are only run once, no matter how many logs match the wildcarded pattern.
A side effect of this option is that the scripts are always executed, even
if no logs are rotated (if it is not specified, the scripts are run only
if logs are actually rotated) (this overrides the \fbnosharedscripts\fR
option).
However, if none of the logs in the pattern require rotating, the scripts
will not be run at all. This option overrides the \fbnosharedscripts\fR
option.
.TP
\fBstart \fIcount\fR
This is the number to use as the base for rotation. For example, if
you specify 0, the logs will be created with a .0 extension as they are
rotated from the original log files. If you specify 9, log files will
be created with a .9, skipping 0-8. Files will still be rotated the
number of times specified with the \fBcount\fR directive.
.TP
\fBtabooext\fR [+] \fIlist\fR
......@@ -340,7 +393,7 @@ night.
.SH FILES
.PD 0
.TP 27
\fI/var/lib/logrotate.status\fR
\fI/var/lib/logrotate/status\fR
Default state file.
.TP 27
\fI/etc/logrotate.conf\fR
......
This diff is collapsed.
......@@ -4,6 +4,8 @@
#include <sys/types.h>
#include <glob.h>
#include "config.h"
#define LOG_FLAG_COMPRESS (1 << 0)
#define LOG_FLAG_CREATE (1 << 1)
#define LOG_FLAG_IFEMPTY (1 << 2)
......@@ -12,17 +14,17 @@
#define LOG_FLAG_MISSINGOK (1 << 5)
#define LOG_FLAG_MAILFIRST (1 << 6)
#define LOG_FLAG_SHAREDSCRIPTS (1 << 7)
#define DEFAULT_MAIL_COMMAND "/bin/mail -s"
#define COMPRESS_COMMAND "/bin/gzip"
#define COMPRESS_OPTIONS "-9"
#define COMPRESS_EXT ".gz"
#define UNCOMPRESS_COMMAND "/bin/gunzip"
#define LOG_FLAG_COPY (1 << 8)
#define NO_FORCE_ROTATE 0
#define FORCE_ROTATE 1
#define STATEFILE "/var/lib/logrotate.status"
struct rotatePatternElement {
enum { RP_NONE = 0, RP_FILENAME, RP_STRING, RP_COUNT, RP_MONTH, RP_DAY,
RP_YEAR } type;
char * arg;
struct rotatePatternElement * next;
};
typedef struct {
char * pattern;
......@@ -32,17 +34,21 @@ typedef struct {
enum { ROT_DAYS, ROT_WEEKLY, ROT_MONTHLY, ROT_SIZE, ROT_FORCE } criterium;
unsigned int threshhold;
int rotateCount;
char * pre, * post;
int logStart;
char * pre, * post, * first, * last;
char * logAddress;
char * extension;
char * compress_prog;
char * uncompress_prog;
char * compress_options;
char * compress_ext;
struct rotatePatternElement * rotatePattern;
int flags;
mode_t createMode; /* if any/all of these are -1, we use the */
uid_t createUid; /* attributes from the log file just rotated */
gid_t createGid;
/* these are at the end so they end up nil */
const char ** compress_options_list;
int compress_options_count;
} logInfo;
int readConfigPath(const char * path, logInfo * defConfig,
......
%if %{?WITH_SELINUX:0}%{!?WITH_SELINUX:1}
%define WITH_SELINUX 1
%endif
Summary: Rotates, compresses, removes and mails system log files.
Name: logrotate
Version: 3.5.9
Release: 1
Version: 3.7
Release: 4
License: GPL
Group: System Environment/Base
Source: logrotate-%{PACKAGE_VERSION}.tar.gz
......@@ -22,15 +26,21 @@ log files on your system.
%setup
%build
make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
make RPM_OPT_FLAGS="$RPM_OPT_FLAGS" \
%if %{WITH_SELINUX}
WITH_SELINUX=yes
%endif
%install
rm -rf $RPM_BUILD_ROOT
make PREFIX=$RPM_BUILD_ROOT MANDIR=%{_mandir} install
mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d
mkdir -p $RPM_BUILD_ROOT/etc/cron.daily
mkdir -p $RPM_BUILD_ROOT/var/lib
install -m 644 examples/logrotate-default $RPM_BUILD_ROOT/etc/logrotate.conf
install -m 755 examples/logrotate.cron $RPM_BUILD_ROOT/etc/cron.daily/logrotate
touch $RPM_BUILD_ROOT/var/lib/logrotate.status
%clean
rm -rf $RPM_BUILD_ROOT
......@@ -41,10 +51,75 @@ rm -rf $RPM_BUILD_ROOT
%attr(0755, root, root) /usr/sbin/logrotate
%attr(0644, root, root) %{_mandir}/man8/logrotate.8*
%attr(0755, root, root) /etc/cron.daily/logrotate
%attr(0644, root, root) %config /etc/logrotate.conf
%attr(0644, root, root) %config(noreplace) /etc/logrotate.conf
%attr(0755, root, root) %dir /etc/logrotate.d
%attr(0644, root, root) %verify(not size md5 mtime) %config(noreplace) /var/lib/logrotate.status
%changelog
* Mon Jan 26 2004 Dan Walsh <dwalsh@redhat.com> 3.6.10-4
- fix is_selinux_enabled call
* Fri Sep 5 2003 Dan Walsh <dwalsh@redhat.com> 3.6.10-3
- Turn off selinux
* Fri Sep 5 2003 Dan Walsh <dwalsh@redhat.com> 3.6.10-2.sel
- Turn on selinux
* Wed Aug 06 2003 Erik Troan <ewt@redhat.com>
- always use compressext for the extension for compressed
files; before compresscmd and compressext had to agree
- moved all compression to one code block
- compression, scripts don't use system() anymore
- compress and maillast didn't work together properly
- delaycompress and mailfirst didn't work properly
- don't use system() for mailing (or uncompressing) logs anymore
- use "-s" for speciying the subjected of mailed logs
* Thu Jul 24 2003 Elliot Lee <sopwith@redhat.com> 3.6.10-1
- Fix #100546, change selinux port.
* Wed Jul 18 2003 Dan Walsh <dwalsh@redhat.com> 3.6.9-2
- Port to SELinux 2.5
* Wed Jul 09 2003 Elliot Lee <sopwith@redhat.com> 3.6.9-1
- Fix #90229, #90274, #89458, #91408
* Mon Jan 20 2003 Elliot Lee <sopwith@redhat.com> 3.6.8-1
- Old patch from pm@debian.org
* Tue Jan 14 2003 Elliot Lee <sopwith@redhat.com> 3.6.7-1
- Fixes from bugzilla
* Fri Nov 15 2002 Elliot Lee <sopwith@redhat.com> 3.6.6-1
- Commit patch from Fidelis Assis <fidelis@embratel.net.br>
* Thu Jun 20 2002 Elliot Lee <sopwith@redhat.com> 3.6.5-1
- Commit fix for #65299
* Mon Apr 15 2002 Elliot Lee <sopwith@redhat.com> 3.6.4-1
- Commit fix for #62560
* Wed Mar 13 2002 Elliot Lee <sopwith@redhat.com> 3.6.3-1
- Apply various bugfix patches from the openwall people
* Tue Jan 29 2002 Elliot Lee <sopwith@redhat.com> 3.6.2-1
- Fix bug #55809 (include logrotate.status in %files)
- Fix bug #58328 (incorrect error detection when reading state file)
- Allow 'G' size specifier from bug #57242
* Mon Dec 10 2001 Preston Brown <pbrown@redhat.com>
- noreplace config file
* Wed Nov 28 2001 Preston Brown <pbrown@redhat.com> 3.6-1
- patch from Alexander Kourakos <awk@awks.org> to stop the shared
postrotate/prerotate scripts from running if none of the log(s) need
rotating. All log files are now checked for rotation in one batch,
rather than sequentially.
- more fixes from Paul Martin <pm@debian.org>
* Thu Nov 8 2001 Preston Brown <pbrown@redhat.com> 3.5.10-1
- fix from paul martin <pm@debian.org> for zero-length state files
* Tue Sep 4 2001 Preston Brown <pbrown@redhat.com>
- fix segfault when logfile is in current directory.
......
#!/bin/bash
echo "To: $1" >> mail-out
echo "---" >> mail-out
echo "$*" > mail-out
cat >> mail-out
echo "---" >> mail-out
......@@ -6,9 +6,11 @@ S=-"s state"
RLR="$LOGROTATE $M $S"
cleanup() {
rm -f test*.log* state test-config.[1-9] scriptout mail-out
rm -f test*.log* anothertest*.log* state test-config. scriptout mail-out
rm -f $(ls | egrep '^test-config.[0-9]+$')
[ -n "$1" ] && echo "Running test $1"
return 0
}
genconfig() {
......@@ -20,6 +22,7 @@ genconfig() {
createlog() {
num=$1
file=$2
cl_compressed=$3
case $num in
0)
......@@ -40,17 +43,31 @@ createlog() {
5)
what=fifth
;;
6)
what=sixth
;;
7)
what=seventh
;;
8)
what=eight
;;
9)
what=ninth
;;
*)
exit 1
;;
esac
echo $what > $file
[ -n "$cl_compressed" ] && gzip -9 $file
}
createlogs() {
base=$1
numlogs=$2
cls_compressed=$3
rm -f ${base}*
......@@ -59,37 +76,46 @@ createlogs() {
if [ $num = 0 ]; then
createlog 0 $base
else
createlog $num ${base}.$num
createlog $num ${base}.$num $cls_compressed
fi
num=`expr $num + 1`
done
}
checkmail() {
(echo -s $PWD/$1 user@myhost.org; echo $2) | diff -u - mail-out
}
checkoutput() {
while read line; do
set $line
file=$1
shift
co_compressed=$2
shift 2
fileother=`echo $line | awk '{print $1}'`
expected=`echo $line | cut -s -d\ -f2-`
expected=`echo $line | cut -s -d\ -f3-`
if [ $file != $fileother ]; then
echo "unexpected file $file'" >&2
return 1
exit 2
fi
if [ ! -f $file ]; then
echo "file $file does not exist"
fi
contents=`cat $file`
if [ -n "$co_compressed" -a "$co_compressed" != 0 ]; then
contents=`gunzip -c $file`
else
contents=`cat $file`
fi
if [ "$contents" != "$expected" ]; then
echo "file $file does not contain expected results" >&2
echo "file $file does not contain expected results (compressed $co_compressed, args $*)" >&2
echo contains: \'$contents\'
echo expected: \'$expected\'
return 1
exit 2
fi
done
}
......@@ -98,12 +124,13 @@ preptest() {
base=$1
confignum=$2
numlogs=$3
pt_compressed=$4
rm -f $base*
rm -f state
genconfig $confignum
createlogs $base $numlogs
createlogs $base $numlogs $pt_compressed
}
# we don't want any stuff left from previous runs
......@@ -113,9 +140,9 @@ cleanup
preptest test.log 1 2
$RLR test-config.1
checkoutput test.log* <<EOF
test.log zero
test.log.1 first
checkoutput <<EOF
test.log 0 zero
test.log.1 0 first
EOF
# Put in place a state file that will force a rotation
......@@ -126,19 +153,19 @@ EOF
# Now force the rotation
$RLR test-config.1
checkoutput test.log* <<EOF
test.log
test.log.1 zero
test.log.2 first
checkoutput <<EOF
test.log 0