xref: /titanic_51/usr/src/cmd/logadm/tester (revision 7ee93e3bbce920c0d0742deb6632b0939e30b783)
1#!/usr/bin/perl -w
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28#
29#
30# tester - run logadm tests
31#
32# requires a <bindir> argument to say where the various logadm
33# binaries live (conftest, globtest, kwtest, luttest, optstest, and
34# logadm itself).
35#
36# to run all the tests:
37# 	tester [-f] <bindir>
38#
39# to run just a few tests, given their names:
40# 	tester [-f] <bindir> globtest1 luttest1
41#
42# to setup a test and stop so you can run it by hand:
43# 	tester [-f] -s globtest1 <bindir>
44#
45# 	tester will tell you what tmp directory it created for
46# 	the test.  to run it, cd there and run:
47# 		sh runtest
48# 	to check the results, run:
49# 		sh checktest
50#
51# -f means "fast" -- without it, watchmalloc(3MALLOC) is setup for
52# each test and they run a zillion times slower and produce core
53# dumps when malloc/free problems are detected.
54#
55$watchmalloc=1;		# default is to use watchmalloc
56${ENV} = "/bin";
57umask 002;
58
59# list of tests we run by default
60@tests = (
61	"conftest1",
62	"conftest2",
63	"globtest1",
64	"globtest2",
65	"kwtest1",
66	"kwtest2",
67	"luttest1",
68	"optstest1",
69	"optstest2",
70	"logadmV1",
71	"logadmV2",
72	"logadmr",
73	"logadmw",
74	"logadm1",
75	"logadm1c",
76	"logadm2",
77	"logadm3",
78	"logadm4",
79	"logadm5",
80	"logadm6",
81	"logadm7",
82	"logadm8",
83	"logadm9",
84	"logadm9d",
85	"logadm10",
86	"logadm11",
87	"logadm12",
88	"logadm13",
89	"logadm14",
90	"logadm15",
91	"logadm16",
92	"logadm17",
93	"logadm18",
94	"logadm19",
95);
96
97use Getopt::Std;
98use File::Find;
99
100$usage_summary = '[-s test-name] [-d dir] bindir [test-name...]';
101$usage_getopts = 'fd:s:';
102%usage = (
103	d=>'use dir for tests rather than creating one in /tmp',
104	s=>'setup only, do not run test');
105
106# spew usage message, plus any given message, and exit
107sub usage {
108	my $msg = shift;
109
110	if ($msg) {
111		chomp $msg;
112		warn "$0: $msg\n" if $msg;
113	}
114	warn "Usage: $0 $usage_summary\n";
115	foreach (sort keys %usage) {
116		warn "       -$_ $usage{$_}\n";
117	}
118	exit 1;
119}
120
121#
122# basic argument processing
123#
124$myname = $0;
125$myname =~ s/.*\///;	# just show last component in error mesages
126getopts($usage_getopts) or usage;
127$bindir = shift or usage;
128usage("$bindir does not exist") unless -d $bindir;
129usage("cannot list more than one test with -s option") if $opt_s && @ARGV;
130@tests = @ARGV if @ARGV;
131print "Fast mode\n" if $opt_f;
132$watchmalloc = 0 if $opt_f;
133
134$mydir=`pwd`;
135chomp $mydir;
136
137$dir = $opt_d;
138$dir = "/tmp/logadmtest$$" unless $dir = $opt_d;
139
140if (!-d $dir) {
141	mkdir $dir, 0777 or die "$myname: mkdir $dir: $!\n";
142	$needrmdir = 1;
143}
144
145chdir $dir or die "$myname: $dir: $!\n";
146
147# common commands in runtest by tests
148if ($watchmalloc) {
149	$envsetup =
150		"HOME=$dir export HOME; " .
151		"LD_PRELOAD=watchmalloc.so.1 export LD_PRELOAD; " .
152		"MALLOC_DEBUG=RW export MALLOC_DEBUG";
153} else {
154	$envsetup = "HOME=$dir export HOME; ";
155}
156
157$| = 1;		# a.k.a. setbuf(stdout, NULL)
158
159if ($opt_s) {
160	#
161	# just setup the test, explain how to use it, and exit
162	#
163	$testname = $opt_s;
164	eval "&$opt_s";
165	die "$myname: ERROR: $@" if $@;
166	print "$myname: $testname setup complete, to run, cd to:\n";
167	print "    $dir\n";
168	print "and run the command:\n";
169	print "    sh runtest\n";
170	print "to check the results, run the command:\n";
171	print "    sh checktest\n";
172	exit 0;
173} else {
174	#
175	# run all the tests
176	#
177	foreach (@tests) {
178		$testname = $_;
179		print "Running $testname...";
180		eval "&$_";
181		if ($@) {
182			print " SETUP FAILURE\n";
183			print STDERR "$myname: ERROR: $@";
184			exit 1;
185		}
186		eval "runner('runtest')";
187		if ($@) {
188			print " RUNTEST FAILURE\n";
189			print STDERR "$myname: ERROR: $@";
190			print STDERR "results captured in directory $dir\n";
191			print STDERR "  or use: $myname -s $testname $bindir\n";
192			print STDERR "  to do a fresh setup of this test.\n";
193			exit 1;
194		}
195		eval "runner('checktest')";
196		if ($@) {
197			print " CHECKTEST FAILURE\n";
198			print STDERR "$myname: ERROR: $@";
199			print STDERR "results captured in directory $dir\n";
200			print STDERR "  or use: $myname -s $testname $bindir\n";
201			print STDERR "  to do a fresh setup of this test.\n";
202			exit 1;
203		}
204		print "pass\n";
205		# sanity...
206		die "unexpected dir $dir" unless $dir =~ m,/.+/,;
207		system("/bin/rm -rf $dir/*");
208	}
209}
210
211# if we were the ones who created $dir, remove it
212if ($needrmdir) {
213	chdir $mydir;
214	rmdir $dir || die "$myname: rmdir $dir: $!\n";
215}
216
217exit 0;
218
219#
220# run a shell script and check for failure
221#
222# the shell scripts generated by this program always "exec" the binary
223# under test so checking here are for exit code, signals, and core dump
224# is actually checking the program under test and not /bin/sh
225#
226sub runner {
227	my $cmd = shift;
228	my $fullcmd = "/bin/sh $cmd";
229	my $rc = 0xffff & system("$fullcmd");
230
231	if ($rc == 0) {
232		return;		# cmd completed normally
233	} elsif ($rc == 0xff00) {
234		die "command \"$cmd\" failed: $!\n";
235	} elsif (($rc & 0xff) == 0) {
236		$rc >>= 8;
237		die "command \"$cmd\" exit $rc\n";
238	} else {
239		my $coremsg;
240		$coremsg = " (core dumped)" if ($rc & 0x80);
241		$rc &= ~0x80;
242		die "command \"$cmd\" signal $rc$coremsg\n" ;
243	}
244}
245
246#
247# set_file(filename [, contents]) -- create a file, optionally with contents
248#
249sub set_file {
250	my $file = shift;
251	my $contents = shift;
252
253	open SF, ">$file" or die "create \"$file\": $!\n";
254	print SF $contents if defined($contents);
255	close SF;
256}
257
258#############
259#############
260#############    THE TESTS START AFTER HERE...
261#############
262#############
263
264# common setup step -- create a testfile.conf
265sub set_testconffile {
266	my $fname = shift;
267	$fname = 'testfile.conf' unless defined($fname);
268
269	set_file($fname, <<'EOF');
270#
271# logadm.conf
272#
273# Default settings for system log file management.
274# The -w option to logadm(1M) is the preferred way to write to this file,
275# but if you do edit it by hand, use "logadm -V" to check it for errors.
276#
277# The format of lines in this file is:
278#       <logname> <options>
279# For each logname listed here, the default options to logadm
280# are given.  Options given on the logadm command line override
281# the defaults contained in this file.
282#
283# logadm typically runs early every morning via an entry in
284# root's crontab (see crontab(1)).
285#
286/var/adm/messages -C 4 -P 'Thu Nov  1 16:56:42 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
287/var/cron/log -s 512k -t /var/cron/olog
288/var/lp/logs/lpsched -C 2 -N -t '$file.$N'
289#
290# The entry below is used by turnacct(1M)
291#
292/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
293apache -C 24 -a '/usr/apache/bin/apachectl graceful' -p 1m -t '/var/apache/old-logs/$basename.%Y-%m' '/var/apache/logs/*{access,error}_log'
294/var/log/syslog -C 8 -P 'Thu Nov  1 09:16:38 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
295/var/apache/logs/access_log -P 'Thu Nov  1 08:27:56 2001'
296/var/apache/logs/error_log -P 'Thu Nov  1 08:27:56 2001'
297/var/apache/logs/suexec_log -P 'Thu Nov  1 08:27:56 2001'
298/var/apache/logs/mod_jserv.log -P 'Thu Nov  1 08:27:56 2001'
299/var/apache/logs/jserv.log -P 'Thu Nov  1 08:27:56 2001'
300EOF
301}
302
303
304###########################################################################
305#
306#	conftest1 -- minimal basic test of the conf.c code
307#
308###########################################################################
309sub conftest1 {
310	set_testconffile;
311
312	set_file('checktest', <<'EOF');
313[ -s std.err ] && exit 1
314/bin/sed '/^conffile <testfile.conf>:$/d' <std.out >sed.out
315exec /bin/diff sed.out testfile.conf
316EOF
317
318	set_file('runtest', <<"EOF");
319# test "conftest1"
320$envsetup
321exec $bindir/conftest testfile.conf >std.out 2>std.err
322EOF
323}
324
325###########################################################################
326#
327#	conftest2 -- error path through conf.c
328#
329###########################################################################
330sub conftest2 {
331	set_file('testfile.conf', 'line fragment');
332
333	set_file('std.err.expect', <<'EOF');
334conftest: Warning: config file doesn't end with newline, last line ignored.
335EOF
336
337	set_file('checktest', <<'EOF');
338exec /bin/diff std.err std.err.expect
339EOF
340
341	set_file('runtest', <<"EOF");
342# test "conftest2"
343$envsetup
344$bindir/conftest testfile.conf >std.out 2>std.err || exit 0
345exit 1
346EOF
347}
348
349###########################################################################
350#
351#	globtest1 -- minimal basic test of the glob.c code
352#
353###########################################################################
354sub globtest1 {
355	set_file('fileBname12');
356	sleep 2;	# ensure above name is odler than below name
357	set_file('fileAname12');
358	set_file('fileAname1');
359	set_file('fileAname3');
360	set_file('fileAname5');
361	set_file('fileAname7');
362	set_file('fileAname9');
363	set_file('fileAname11');
364	set_file('fileBname0');
365	set_file('fileBname2');
366	set_file('fileBname4');
367	set_file('fileBname6');
368	set_file('fileBname8');
369	set_file('fileBname10');
370	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
371	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
372	mkdir 'dir3', 0777 or die "mkdir dir3: $!\n";
373	mkdir 'dir1/dirA', 0777 or die "mkdir dir1/dirA: $!\n";
374	mkdir 'dir1/dirB', 0777 or die "mkdir dir1/dirB: $!\n";
375	mkdir 'dir1/dirC', 0777 or die "mkdir dir1/dirC: $!\n";
376	mkdir 'dir2/dirA', 0777 or die "mkdir dir2/dirA: $!\n";
377	mkdir 'dir2/dirB', 0777 or die "mkdir dir2/dirB: $!\n";
378	mkdir 'dir2/dirC', 0777 or die "mkdir dir2/dirC: $!\n";
379	set_file('dir1/fileAname1');
380	set_file('dir1/fileAname2');
381	set_file('dir1/fileAname3');
382	set_file('dir1/fileAname4');
383	set_file('dir1/fileAname5');
384	set_file('dir1/fileBname1');
385	set_file('dir1/fileBname2');
386	set_file('dir1/fileBname3');
387	set_file('dir1/fileBname4');
388	set_file('dir1/fileBname5');
389	# supply some varying sizes to produce different total size values
390	set_file('dir1/dirA/fileAname4', '4444');
391	sleep 2;	# ensure above file is oldest in dirA
392	set_file('dir1/dirA/fileAname1', '1');
393	set_file('dir1/dirA/fileAname2', '22');
394	set_file('dir1/dirA/fileAname3', '333');
395	set_file('dir1/dirA/fileAname5', '55555');
396	set_file('dir1/dirA/fileBname1', '1');
397	set_file('dir1/dirA/fileBname2', '22');
398	set_file('dir1/dirA/fileBname3', '333');
399	set_file('dir1/dirA/fileBname4', '4444');
400	set_file('dir1/dirA/fileBname5', '55555');
401	set_file('dir1/dirB/fileAname1', '1');
402	set_file('dir1/dirB/fileAname2', '22');
403	set_file('dir1/dirB/fileAname3', '333');
404	set_file('dir1/dirB/fileAname4', '4444');
405	set_file('dir1/dirB/fileAname5', '55555');
406	set_file('dir1/dirB/fileBname1', '1');
407	set_file('dir1/dirB/fileBname2', '22');
408	set_file('dir1/dirB/fileBname3', '333');
409	set_file('dir1/dirB/fileBname4', '4444');
410	set_file('dir1/dirB/fileBname5', '55555');
411	set_file('dir1/dirC/fileAname10', '12345678901');
412	set_file('dir1/dirC/fileAname20', '123456789022');
413	set_file('dir1/dirC/fileAname30', '1234567890333');
414	set_file('dir1/dirC/fileAname40', '12345678904444');
415	set_file('dir1/dirC/fileAname50', '123456789055555');
416	set_file('dir1/dirC/fileBname10', '12345678901');
417	set_file('dir1/dirC/fileBname20', '123456789022');
418	set_file('dir1/dirC/fileBname30', '1234567890333');
419	set_file('dir1/dirC/fileBname40', '12345678904444');
420	set_file('dir1/dirC/fileBname50', '123456789055555');
421
422	set_file('std.out.expect', <<'EOF');
423<file{A,B,C}name*>:
424    <./fileAname12>
425    <./fileAname1>
426    <./fileAname3>
427    <./fileAname5>
428    <./fileAname7>
429    <./fileAname9>
430    <./fileAname11>
431    <./fileBname12>
432    <./fileBname0>
433    <./fileBname2>
434    <./fileBname4>
435    <./fileBname6>
436    <./fileBname8>
437    <./fileBname10>
438total size: 0
439    oldest <./fileBname12>
440    oldest <./fileBname8>
441    oldest <./fileBname6>
442    oldest <./fileBname4>
443    oldest <./fileBname2>
444    oldest <./fileBname10>
445    oldest <./fileBname0>
446    oldest <./fileAname9>
447    oldest <./fileAname7>
448    oldest <./fileAname5>
449    oldest <./fileAname3>
450    oldest <./fileAname12>
451    oldest <./fileAname11>
452    oldest <./fileAname1>
453<file{A,B,C}name>:
454    <fileAname>
455    <fileBname>
456    <fileCname>
457total size: 0
458    oldest <fileCname>
459    oldest <fileBname>
460    oldest <fileAname>
461<dir1/dirA/file*>:
462    <./dir1/dirA/fileAname4>
463    <./dir1/dirA/fileAname1>
464    <./dir1/dirA/fileAname2>
465    <./dir1/dirA/fileAname3>
466    <./dir1/dirA/fileAname5>
467    <./dir1/dirA/fileBname1>
468    <./dir1/dirA/fileBname2>
469    <./dir1/dirA/fileBname3>
470    <./dir1/dirA/fileBname4>
471    <./dir1/dirA/fileBname5>
472total size: 30
473    oldest <./dir1/dirA/fileAname4>
474    oldest <./dir1/dirA/fileBname5>
475    oldest <./dir1/dirA/fileBname4>
476    oldest <./dir1/dirA/fileBname3>
477    oldest <./dir1/dirA/fileBname2>
478    oldest <./dir1/dirA/fileBname1>
479    oldest <./dir1/dirA/fileAname5>
480    oldest <./dir1/dirA/fileAname3>
481    oldest <./dir1/dirA/fileAname2>
482    oldest <./dir1/dirA/fileAname1>
483<dir[13]/[e-z]*>:
484    <./dir1/fileAname1>
485    <./dir1/fileAname2>
486    <./dir1/fileAname3>
487    <./dir1/fileAname4>
488    <./dir1/fileAname5>
489    <./dir1/fileBname1>
490    <./dir1/fileBname2>
491    <./dir1/fileBname3>
492    <./dir1/fileBname4>
493    <./dir1/fileBname5>
494total size: 0
495    oldest <./dir1/fileBname5>
496    oldest <./dir1/fileBname4>
497    oldest <./dir1/fileBname3>
498    oldest <./dir1/fileBname2>
499    oldest <./dir1/fileBname1>
500    oldest <./dir1/fileAname5>
501    oldest <./dir1/fileAname4>
502    oldest <./dir1/fileAname3>
503    oldest <./dir1/fileAname2>
504    oldest <./dir1/fileAname1>
505<dir?/dir[AC]/fileBname[2-9]>:
506    <./dir1/dirA/fileBname2>
507    <./dir1/dirA/fileBname3>
508    <./dir1/dirA/fileBname4>
509    <./dir1/dirA/fileBname5>
510total size: 14
511    oldest <./dir1/dirA/fileBname5>
512    oldest <./dir1/dirA/fileBname4>
513    oldest <./dir1/dirA/fileBname3>
514    oldest <./dir1/dirA/fileBname2>
515<file[A-Z]n.*e([0-9]+)$0>:
516    <./fileBname12>
517    <./fileAname12>
518    <./fileAname1>
519    <./fileAname3>
520    <./fileAname5>
521    <./fileAname7>
522    <./fileAname9>
523    <./fileAname11>
524    <./fileBname0>
525    <./fileBname2>
526    <./fileBname4>
527    <./fileBname6>
528    <./fileBname8>
529    <./fileBname10>
530total size: 0
531    oldest <./fileBname12>
532    oldest <./fileAname12>
533    oldest <./fileAname11>
534    oldest <./fileBname10>
535    oldest <./fileAname9>
536    oldest <./fileBname8>
537    oldest <./fileAname7>
538    oldest <./fileBname6>
539    oldest <./fileAname5>
540    oldest <./fileBname4>
541    oldest <./fileAname3>
542    oldest <./fileBname2>
543    oldest <./fileAname1>
544    oldest <./fileBname0>
545EOF
546
547	set_file('checktest', <<'EOF');
548[ -s std.err ] && exit 1
549exec /bin/diff std.out std.out.expect
550EOF
551
552	$testglobs='\'file{A,B,C}name*\' \'file{A,B,C}name\' \'dir1/dirA/file*\' \'dir[13]/[e-z]*\' \'dir?/dir[AC]/fileBname[2-9]\' -r \'file[A-Z]n.*e([0-9]+)$0\'';
553
554	set_file('runtest', <<"EOF");
555# test "globtest1"
556$envsetup
557exec $bindir/globtest $testglobs >std.out 2>std.err
558EOF
559}
560
561###########################################################################
562#
563#	globtest2 -- error path through glob.c
564#
565###########################################################################
566sub globtest2 {
567	set_file('std.err.expect', <<'EOF');
568globtest: Error: Missing }
569EOF
570
571	set_file('checktest', <<'EOF');
572exec /bin/diff std.err std.err.expect
573EOF
574
575	set_file('runtest', <<"EOF");
576# test "globtest2"
577$envsetup
578$bindir/globtest 'hello{there' >std.out 2>std.err || exit 0
579exit 1
580EOF
581}
582
583###########################################################################
584#
585#	kwtest1 -- minimal basic test of the kw.c code
586#
587###########################################################################
588sub kwtest1 {
589	$domainname = `/bin/domainname`; chomp $domainname;
590	$isa = `/bin/uname -p`; chomp $isa;
591	$platform = `/bin/uname -i`; chomp $platform;
592	$nodename = `/bin/uname -n`; chomp $nodename;
593	$machine = `/bin/uname -m`; chomp $machine;
594	$release = `/bin/uname -r`; chomp $release;
595$secondblob=<<'EOF';
596expand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
597expand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
598expand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
599expand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
600expand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
601expand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
602expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n -1 hasn 1 result </var/logs-[0-9]+/moose-ISAporklips[0-9]+\.([0-9]+)$0>
603expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
604expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
605EOF
606	$percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
607	$percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
608	$secondblob =~ s/%d/$percentd/mg;
609	$secondblob =~ s/%Y/$percentY/mg;
610	$secondblob =~ s/ISA/$isa/mg;
611	$utcenv = "TZ=UTC export TZ";
612	chomp $secondblob;
613	set_file('sed.out.expect', <<"EOF");
614            basename syslog
615             dirname /var/log
616              domain $domainname
617                file /var/log/syslog
618                home $dir
619                 isa $isa
620             logname $ENV{LOGNAME}
621             machine $machine
622               nfile
623            nodename $nodename
624            platform $platform
625             release $release
626                user $ENV{USER}
627$secondblob
628EOF
629
630	set_file('checktest', <<'EOF');
631[ -s std.err ] && exit 1
632/bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
633	-e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
634	-e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
635	<std.out >sed.out
636exec /bin/diff sed.out sed.out.expect
637EOF
638
639	$kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
640	set_file('runtest', <<"EOF");
641# test "kwtest1"
642$envsetup
643$utcenv
644exec $bindir/$kwtest >std.out 2>std.err
645EOF
646}
647
648###########################################################################
649#
650#	kwtest2 -- NULL environment variables test of the kw.c code
651#
652###########################################################################
653sub kwtest2 {
654	$domainname = `/bin/domainname`; chomp $domainname;
655	$isa = `/bin/uname -p`; chomp $isa;
656	$platform = `/bin/uname -i`; chomp $platform;
657	$nodename = `/bin/uname -n`; chomp $nodename;
658	$machine = `/bin/uname -m`; chomp $machine;
659	$release = `/bin/uname -r`; chomp $release;
660$secondblob=<<'EOF';
661expand<$file.$n> n -1 hasn 1 result </var/log/syslog\.([0-9]+)$0>
662expand<$file.$n> n 0 hasn 1 result </var/log/syslog.0>
663expand<$file.$n> n 1 hasn 1 result </var/log/syslog.1>
664expand<moose%d.$n> n -1 hasn 1 result <moose[0-9]+\.([0-9]+)$0>
665expand<moose%d.$n> n 0 hasn 1 result <moose%d.0>
666expand<moose%d.$n> n 1 hasn 1 result <moose%d.1>
667expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n -1 hasn 1 result </var/logs-[0-9]+/moose-ISAporklips[0-9]+\.([0-9]+)$0>
668expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
669expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
670EOF
671	$percentd = `/bin/env TZ=UTC /bin/date +%d`; chomp $percentd;
672	$percentY = `/bin/env TZ=UTC /bin/date +%Y`; chomp $percentY;
673	$secondblob =~ s/%d/$percentd/mg;
674	$secondblob =~ s/%Y/$percentY/mg;
675	$secondblob =~ s/ISA/$isa/mg;
676	chomp $secondblob;
677	set_file('sed.out.expect', <<"EOF");
678            basename syslog
679             dirname /var/log
680              domain $domainname
681                file /var/log/syslog
682                home
683                 isa $isa
684             logname
685             machine $machine
686               nfile
687            nodename $nodename
688            platform $platform
689             release $release
690                user
691$secondblob
692EOF
693
694	set_file('checktest', <<'EOF');
695[ -s std.err ] && exit 1
696/bin/sed -e '/^ *secs [0-9][0-9]*$/d'\
697	-e "s/%d/`/bin/env TZ=UTC /bin/date +%d`/g"\
698	-e "s/%Y/`/bin/env TZ=UTC /bin/date +%Y`/g"\
699	<std.out >sed.out
700exec /bin/diff sed.out sed.out.expect
701EOF
702
703	$kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
704	set_file('runtest', <<"EOF");
705# test "kwtest2"
706$envsetup
707LOGNAME=
708export LOGNAME
709HOME=
710export HOME
711USER=
712export USER
713exec $bindir/$kwtest >std.out 2>std.err
714EOF
715}
716
717###########################################################################
718#
719#	luttest1 -- minimal basic test of the lut.c code
720#
721###########################################################################
722sub luttest1 {
723	set_file('std.out.expect', <<'EOF');
724lut contains:
725<fix> <NULL> (<NULL>)
726<one> <two> (<two>)
727<seven> <eight> (<eight>)
728<six> <NULL> (<NULL>)
729<three> <four> (<four>)
730dup lut contains:
731<fix> <NULL> (<NULL>)
732<one> <two> (<two>)
733<seven> <eight> (<eight>)
734<six> <NULL> (<NULL>)
735<three> <four> (<four>)
736EOF
737
738	set_file('checktest', <<'EOF');
739[ -s std.err ] && exit 1
740exec /bin/diff std.out std.out.expect
741EOF
742
743	set_file('runtest', <<"EOF");
744# test "luttest1"
745$envsetup
746exec $bindir/luttest one=two three=four fix six seven=eight >std.out 2>std.err
747EOF
748}
749
750###########################################################################
751#
752#	optstest1 -- minimal basic test of the opts.c code
753#
754###########################################################################
755sub optstest1 {
756	$options="-a -b moose -c 1h -d 'Fri Nov  2 13:19:55 2001' -e 1k -f 2 one two three";
757	set_file('std.out.expect', <<"EOF");
758options: $options
759EOF
760
761	set_file('checktest', <<'EOF');
762[ -s std.err ] && exit 1
763exec /bin/diff std.out std.out.expect
764EOF
765
766	set_file('runtest', <<"EOF");
767# test "optstest1"
768$envsetup
769exec $bindir/optstest $options >std.out 2>std.err
770EOF
771}
772
773###########################################################################
774#
775#	optstest2 -- error path through opts.c code
776#
777###########################################################################
778sub optstest2 {
779	$options="-a -b -c 1h -d 'Fri Nov  2 13:19:55 2001' -e 1k -f 2 one two three";
780	set_file('std.err.expect', <<'EOF');
781optstest: Error: Option 'b' requires an argument
782optstest: Error: opts parsing failed
783EOF
784
785	set_file('checktest', <<'EOF');
786[ -s std.out ] && exit 1
787exec /bin/diff std.err std.err.expect
788EOF
789
790	set_file('runtest', <<"EOF");
791# test "optstest2"
792$envsetup
793$bindir/optstest $options >std.out 2>std.err || exit 0
794exit 1
795EOF
796}
797
798###########################################################################
799#
800#	logadmV1 -- test of "logadm -V"
801#
802###########################################################################
803sub logadmV1 {
804	set_testconffile;
805
806	set_file('std.out.expect', <<'EOF');
807/var/adm/messages -C 4 -P 'Thu Nov  1 16:56:42 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
808/var/cron/log -s 512k -t /var/cron/olog
809/var/lp/logs/lpsched -C 2 -N -t '$file.$N'
810/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
811apache -C 24 -a '/usr/apache/bin/apachectl graceful' -p 1m -t '/var/apache/old-logs/$basename.%Y-%m' '/var/apache/logs/*{access,error}_log'
812/var/log/syslog -C 8 -P 'Thu Nov  1 09:16:38 2001' -a 'kill -HUP `cat /var/run/syslog.pid`'
813/var/apache/logs/access_log -P 'Thu Nov  1 08:27:56 2001'
814/var/apache/logs/error_log -P 'Thu Nov  1 08:27:56 2001'
815/var/apache/logs/suexec_log -P 'Thu Nov  1 08:27:56 2001'
816/var/apache/logs/mod_jserv.log -P 'Thu Nov  1 08:27:56 2001'
817/var/apache/logs/jserv.log -P 'Thu Nov  1 08:27:56 2001'
818EOF
819
820	set_file('checktest', <<'EOF');
821[ -s std.err ] && exit 1
822exec /bin/diff std.out std.out.expect
823EOF
824
825	set_file('runtest', <<"EOF");
826# test "logadmV1"
827$envsetup
828exec $bindir/logadm -f testfile.conf -V >std.out 2>std.err
829EOF
830}
831
832###########################################################################
833#
834#	logadmV2 -- test of "logadm -V <entry>"
835#
836###########################################################################
837sub logadmV2 {
838	set_testconffile;
839
840	set_file('std.out.expect', <<'EOF');
841/var/cron/log -s 512k -t /var/cron/olog
842/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
843EOF
844
845	set_file('checktest', <<'EOF');
846[ -s std.err ] && exit 1
847exec /bin/diff std.out std.out.expect
848EOF
849
850	set_file('runtest', <<"EOF");
851# test "logadmV2"
852$envsetup
853exec $bindir/logadm -f testfile.conf -V /var/cron/log /var/adm/pacct >std.out 2>std.err
854EOF
855}
856
857###########################################################################
858#
859#	logadmr -- test of "logadm -r <entry>"
860#
861###########################################################################
862sub logadmr {
863	set_testconffile;
864	set_testconffile('testfile.conf.orig');
865
866	set_file('diff.out.expect', <<'EOF');
86717a18
868> /var/cron/log -s 512k -t /var/cron/olog
86921a23
870> /var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
871EOF
872
873	set_file('checktest', <<'EOF');
874[ -s std.err ] && exit 1
875/bin/diff testfile.conf testfile.conf.orig > diff.out
876exec /bin/diff diff.out diff.out.expect
877EOF
878
879	set_file('runtest', <<"EOF");
880# test "logadmr"
881$envsetup
882exec $bindir/logadm -f testfile.conf -r /var/cron/log /var/adm/pacct >std.out 2>std.err
883EOF
884}
885
886###########################################################################
887#
888#	logadmw -- test of "logadm -w <entry>"
889#
890###########################################################################
891sub logadmw {
892	set_testconffile;
893	set_testconffile('testfile.conf.orig');
894
895	set_file('diff.out.expect', <<'EOF');
89631d30
897< moose -C 20 -a moose_after_cmd -g pig -m 664 -o cow -p never /moose/file
898EOF
899
900	set_file('checktest', <<'EOF');
901[ -s std.err ] && exit 1
902/bin/diff testfile.conf testfile.conf.orig > diff.out
903exec /bin/diff diff.out diff.out.expect
904EOF
905
906	set_file('runtest', <<"EOF");
907# test "logadmw"
908$envsetup
909exec $bindir/logadm -f testfile.conf -w moose -C 20 -a moose_after_cmd -g pig -m 664 -o cow -p never /moose/file >std.out 2>std.err
910EOF
911}
912
913###########################################################################
914#
915#	logadm1 -- minimal basic test of logadm rotation
916#
917###########################################################################
918sub logadm1 {
919	set_file('logfile', 'initially logfile');
920	set_file('logfile.0', 'initially logfile.0');
921	my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
922		$stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
923		lstat 'logfile' or die "lstat logfile: $!\n";
924
925	set_file('checktest', <<"EOF");
926[ -s std.err ] && exit 1
927[ -s std.out ] && exit 1
928[ -s logfile ] && exit 1
929[ -f logfile.0 ] || exit 1
930[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
931[ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] || exit 1
932[ -f logfile.1 ] || exit 1
933[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
934exit 0
935EOF
936
937	set_file('runtest', <<"EOF");
938# test "logadm1"
939$envsetup
940exec $bindir/logadm -f /dev/null -p now logfile >std.out 2>std.err
941EOF
942}
943
944###########################################################################
945#
946#	logadm1c -- same as logadm1 but with -c option
947#
948###########################################################################
949sub logadm1c {
950	set_file('logfile', 'initially logfile');
951	set_file('logfile.0', 'initially logfile.0');
952	my ($stdev, $stino, $stmode, $stnlink, $stuid, $stgid, $strdev,
953		$stsize, $statime, $stmtime, $stctime, $stblksize, $stblocks) =
954		lstat 'logfile' or die "lstat logfile: $!\n";
955
956	set_file('checktest', <<"EOF");
957[ -s std.err ] && exit 1
958[ -s std.out ] && exit 1
959[ -s logfile ] && exit 1
960[ -f logfile.0 ] || exit 1
961[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
962[ "`/bin/ls -i logfile.0 | /bin/awk '{ print \$1; }'`" = "$stino" ] && exit 1
963[ -f logfile.1 ] || exit 1
964[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
965exit 0
966EOF
967
968	set_file('runtest', <<"EOF");
969# test "logadm1c"
970$envsetup
971exec $bindir/logadm -f /dev/null -p now -c logfile >std.out 2>std.err
972EOF
973}
974
975###########################################################################
976#
977#	logadm2 -- minimal basic test of logadm expiration
978#
979###########################################################################
980sub logadm2 {
981	set_file('logfile', 'initially logfile');
982	set_file('logfile.0', 'initially logfile.0');
983	set_file('logfile.1', 'initially logfile.1');
984
985	set_file('checktest', <<'EOF');
986[ -s std.err ] && exit 1
987[ -s std.out ] && exit 1
988[ -s logfile ] && exit 1
989[ -f logfile.0 ] || exit 1
990[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
991[ -f logfile.1 ] || exit 1
992[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
993[ -f logfile.2 ] && exit 1
994exit 0
995EOF
996
997	set_file('runtest', <<"EOF");
998# test "logadm2"
999$envsetup
1000exec $bindir/logadm -f /dev/null -p now logfile -C2 >std.out 2>std.err
1001EOF
1002}
1003
1004###########################################################################
1005#
1006#	logadm3 -- minimal basic test of logadm pre/post-commands
1007#
1008###########################################################################
1009sub logadm3 {
1010	set_file('logfile', 'initially logfile');
1011	set_file('logfile.0', 'initially logfile.0');
1012	set_file('logfile.1', 'initially logfile.1');
1013
1014	set_file('checktest', <<'EOF');
1015[ -s std.err ] && exit 1
1016[ -s std.out ] && exit 1
1017[ -s logfile ] && exit 1
1018[ -f logfile.0 ] || exit 1
1019[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1020[ -f logfile.1 ] || exit 1
1021[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1022[ -f logfile.2 ] && exit 1
1023[ -f pre.out ] || exit 1
1024[ "xpre-command-stuff" = "x`/bin/cat pre.out`" ] || exit 1
1025[ -f post.out ] || exit 1
1026[ "xpost-command-stuff" = "x`/bin/cat post.out`" ] || exit 1
1027exit 0
1028EOF
1029
1030	set_file('runtest', <<"EOF");
1031# test "logadm3"
1032$envsetup
1033exec $bindir/logadm -f /dev/null -p now logfile -C2 -b 'echo pre-command-stuff > pre.out' -a 'echo post-command-stuff > post.out' >std.out 2>std.err
1034EOF
1035}
1036
1037###########################################################################
1038#
1039#	logadm4 -- test of -t template
1040#
1041###########################################################################
1042sub logadm4 {
1043	set_file('logfile', 'initially logfile');
1044
1045	set_file('checktest', <<'EOF');
1046[ -s std.err ] && exit 1
1047[ -s std.out ] && exit 1
1048[ -s logfile ] && exit 1
1049TZ=UTC export TZ
1050d=`/bin/date +%d`
1051[ -f logfile.$d ] || exit 1
1052[ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
1053exit 0
1054EOF
1055
1056	set_file('runtest', <<"EOF");
1057# test "logadm4"
1058$envsetup
1059exec $bindir/logadm -f /dev/null -p now logfile -t '\$file.\%d' >std.out 2>std.err
1060EOF
1061}
1062
1063###########################################################################
1064#
1065#	logadm5 -- test of -R cmd and -E cmd
1066#
1067###########################################################################
1068sub logadm5 {
1069	set_file('logfile', 'initially logfile');
1070	set_file('logfile.0', 'initially logfile.0');
1071
1072	set_file('cmd.out.expect', <<'EOF');
1073just rotated: initially logfile
1074just expired: initially logfile.0
1075EOF
1076
1077	set_file('checktest', <<'EOF');
1078[ -s std.err ] && exit 1
1079[ -s std.out ] && exit 1
1080[ -s logfile ] && exit 1
1081[ -f logfile.0 ] || exit 1
1082[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1083[ -f logfile.1 ] || exit 1
1084[ "xinitially logfile.0" = "x`/bin/cat logfile.1`" ] || exit 1
1085exec /bin/diff cmd.out cmd.out.expect
1086EOF
1087
1088	set_file('runtest', <<"EOF");
1089# test "logadm5"
1090$envsetup
1091exec $bindir/logadm -f /dev/null -p now logfile -C1 -R 'echo just rotated: `/bin/cat \$file` >>cmd.out' -E 'echo just expired: `/bin/cat \$file` >>cmd.out' >std.out 2>std.err
1092EOF
1093}
1094
1095###########################################################################
1096#
1097#	logadm6 -- test of -m, -o, -g
1098#
1099###########################################################################
1100sub logadm6 {
1101        set_file('logfile', 'initially logfile');
1102
1103        set_file('std.err.expect', <<'EOF');
1104logadm: Warning: command failed: /bin/chown _nonexistentuser_:_nonexistentgroup_ logfile
1105chown: unknown group id _nonexistentgroup_
1106EOF
1107
1108        set_file('checktest', <<'EOF');
1109[ -s std.err ] || exit 1
1110[ -s std.out ] && exit 1
1111[ -s logfile ] && exit 1
1112[ -f logfile.0 ] || exit 1
1113[ "xinitially logfile" = "x`/bin/cat logfile.0`" ] || exit 1
1114[ "`/bin/ls -l logfile | /bin/awk '{ print $1; }'`" = "-r----x--x" ] || exit 1
1115exec /bin/diff std.err std.err.expect
1116EOF
1117
1118        set_file('runtest', <<"EOF");
1119# test "logadm6"
1120$envsetup
1121exec $bindir/logadm -f /dev/null -p now logfile -m 411 -o _nonexistentuser_ -g _nonexistentgroup_ >std.out 2>std.err
1122EOF
1123}
1124
1125###########################################################################
1126#
1127#       logadm7 -- test running through a conffile
1128#
1129###########################################################################
1130sub logadm7 {
1131	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1132	set_file('dir1/syslog', 'initially dir1/syslog');
1133	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1134	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1135	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1136	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1137	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1138	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1139	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1140	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1141	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1142	set_file('dir2/messages', 'initially dir2/messages');
1143	set_file('dir2/messages.0', 'initially dir2/messages.0');
1144	set_file('dir2/messages.1', 'initially dir2/messages.1');
1145	set_file('dir2/messages.2', 'initially dir2/messages.2');
1146	set_file('dir2/messages.3', 'initially dir2/messages.3');
1147
1148	set_file('logadm.conf', <<'EOF');
1149#
1150# logadm.conf
1151#
1152#	this comment # has at least another #-sign in it #...
1153#
1154# Default settings for system log file management.
1155# The -w option to logadm(1M) is the preferred way to write to this file,
1156# but if you do edit it by hand, use "logadm -V" to check it for errors.
1157# but if you do edit it by hand, use "logadm -V" to check it for errors.
1158#
1159# The format of lines in this file is:
1160#       <logname> <options>
1161# For each logname listed here, the default options to logadm
1162# are given.  Options given on the logadm command line override
1163# the defaults contained in this file.
1164#
1165# logadm typically runs early every morning via an entry in
1166# root's crontab (see crontab(1)).
1167#
1168dir1/syslog -C 8 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
1169dir2/messages -C 4 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
1170#
1171# The entry below is used by turnacct(1M)
1172#
1173/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
1174EOF
1175
1176	system("/bin/cp logadm.conf logadm.conf.orig");
1177
1178	$pid=`cat /etc/syslog.pid`;
1179	chomp $pid;
1180	set_file('cmd.out.expect', <<"EOF");
1181kill -HUP $pid
1182second kill -HUP $pid
1183EOF
1184
1185	set_file('checktest', <<'EOF');
1186[ -s std.err ] && exit 1
1187[ -s std.out ] && exit 1
1188[ -s std.err2 ] && exit 1
1189[ -s std.out2 ] && exit 1
1190[ -s std.err3 ] && exit 1
1191[ -s std.out3 ] && exit 1
1192[ -s std.err4 ] && exit 1
1193[ -s std.out4 ] && exit 1
1194[ -f dir1/syslog ] || exit 1
1195[ "xsomething" = "x`/bin/cat dir1/syslog`" ] || exit 1
1196[ -f dir1/syslog.0 ] || exit 1
1197[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1198[ -f dir1/syslog.1 ] || exit 1
1199[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1200[ -f dir1/syslog.2 ] || exit 1
1201[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1202[ -f dir1/syslog.3 ] || exit 1
1203[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1204[ -f dir1/syslog.4 ] || exit 1
1205[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1206[ -f dir1/syslog.5 ] || exit 1
1207[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1208[ -f dir1/syslog.6 ] || exit 1
1209[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1210[ -f dir1/syslog.7 ] || exit 1
1211[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1212[ -f dir1/syslog.8 ] && exit 1
1213
1214[ -s dir2/messages ] && exit 1
1215[ -f dir2/messages.0 ] || exit 1
1216[ "xsomething" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1217[ -f dir2/messages.1 ] || exit 1
1218[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1219[ -f dir2/messages.2 ] || exit 1
1220[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1221[ -f dir2/messages.3 ] || exit 1
1222[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1223[ -f dir2/messages.4 ] && exit 1
1224/bin/sed "s/-P '[^']*' *//" < logadm.conf > sed.out
1225exec /bin/diff sed.out logadm.conf.orig
1226EOF
1227
1228        # first logadm call will rotate both syslog and messages
1229        # second one won't because size is zero
1230        # third one won't because of -P timestamps stored in conffile
1231        # fourth one will do messages because of -p now on command line
1232        set_file('runtest', <<"EOF");
1233# test "logadm7"
1234$envsetup
1235$bindir/logadm -f logadm.conf >std.out 2>std.err || exit 1
1236$bindir/logadm -f logadm.conf dir1/syslog dir2/messages >std.out2 2>std.err2 || exit 1
1237echo something > dir1/syslog
1238echo something > dir2/messages
1239$bindir/logadm -f logadm.conf >std.out3 2>std.err3 || exit 1
1240exec $bindir/logadm -f logadm.conf dir2/messages -p now -a 'echo second kill -HUP `cat /etc/syslog.pid` >> cmd.out' >std.out4 2>std.err4
1241EOF
1242}
1243
1244###########################################################################
1245#
1246#       logadm8 -- test of -z
1247#
1248###########################################################################
1249sub logadm8 {
1250	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1251	set_file('dir1/syslog', 'initially dir1/syslog');
1252	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1253	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1254	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1255	system("/bin/gzip dir1/syslog.2");
1256	die "gzip dir1/syslog.2 didn't work\n" unless -f 'dir1/syslog.2.gz';
1257	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1258	system("/bin/gzip dir1/syslog.3");
1259	die "gzip dir1/syslog.3 didn't work\n" unless -f 'dir1/syslog.3.gz';
1260	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1261	system("/bin/gzip dir1/syslog.4");
1262	die "gzip dir1/syslog.4 didn't work\n" unless -f 'dir1/syslog.4.gz';
1263	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1264	system("/bin/gzip dir1/syslog.5");
1265	die "gzip dir1/syslog.5 didn't work\n" unless -f 'dir1/syslog.5.gz';
1266	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1267	system("/bin/gzip dir1/syslog.6");
1268	die "gzip dir1/syslog.6 didn't work\n" unless -f 'dir1/syslog.6.gz';
1269	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1270	system("/bin/gzip dir1/syslog.7");
1271	die "gzip dir1/syslog.7 didn't work\n" unless -f 'dir1/syslog.7.gz';
1272
1273	set_file('checktest', <<'EOF');
1274[ -s std.err ] && exit 1
1275[ -s std.out ] && exit 1
1276[ -f dir1/syslog ] || exit 1
1277[ -s dir1/syslog ] && exit 1
1278[ -f dir1/syslog.0 ] || exit 1
1279[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1280[ -f dir1/syslog.1 ] || exit 1
1281[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1282[ -f dir1/syslog.2.gz ] || exit 1
1283[ "xinitially dir1/syslog.1" = "x`/bin/gzcat dir1/syslog.2.gz`" ] || exit 1
1284[ -f dir1/syslog.3.gz ] || exit 1
1285[ "xinitially dir1/syslog.2" = "x`/bin/gzcat dir1/syslog.3.gz`" ] || exit 1
1286[ -f dir1/syslog.4.gz ] || exit 1
1287[ "xinitially dir1/syslog.3" = "x`/bin/gzcat dir1/syslog.4.gz`" ] || exit 1
1288[ -f dir1/syslog.5.gz ] || exit 1
1289[ "xinitially dir1/syslog.4" = "x`/bin/gzcat dir1/syslog.5.gz`" ] || exit 1
1290[ -f dir1/syslog.6.gz ] || exit 1
1291[ "xinitially dir1/syslog.5" = "x`/bin/gzcat dir1/syslog.6.gz`" ] || exit 1
1292[ -f dir1/syslog.7.gz ] || exit 1
1293[ "xinitially dir1/syslog.6" = "x`/bin/gzcat dir1/syslog.7.gz`" ] || exit 1
1294[ -f dir1/syslog.8 ] && exit 1
1295[ -f dir1/syslog.8.gz ] && exit 1
1296exit 0
1297EOF
1298
1299        set_file('runtest', <<"EOF");
1300# test "logadm8"
1301$envsetup
1302exec $bindir/logadm -f /dev/null dir1/syslog -z 2 -C 8 >std.out 2>std.err
1303EOF
1304}
1305
1306###########################################################################
1307#
1308#       logadm9 -- test of age check
1309#
1310###########################################################################
1311sub logadm9 {
1312	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1313	set_file('dir1/syslog', 'initially dir1/syslog');
1314	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1315	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1316	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1317	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1318	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1319	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1320	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1321	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1322	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1323	set_file('dir2/messages', 'initially dir2/messages');
1324	set_file('dir2/messages.0', 'initially dir2/messages.0');
1325	set_file('dir2/messages.1', 'initially dir2/messages.1');
1326	set_file('dir2/messages.2', 'initially dir2/messages.2');
1327	set_file('dir2/messages.3', 'initially dir2/messages.3');
1328
1329	$now = time;
1330	$nowstr = gmtime($now);
1331	# a week minus 30 seconds ago...
1332	# technically not a full week, but the heuristic used by logadm
1333	# should think this is "close enough" to a full week
1334	$closetoweeksecs = $now - (60 * 60 * 24 * 7 - 30);
1335	$closetoweek = gmtime($closetoweeksecs);
1336	# a week minus six hours ago...
1337	$lessthanweeksecs = $now - (60 * 60 * 24 * 7 - 60 * 60 * 6);
1338	$lessthanweek = gmtime($lessthanweeksecs);
1339
1340	set_file('logadm.conf', <<"EOF");
1341# now: $nowstr is $now
1342# $closetoweek is $closetoweeksecs
1343dir1/syslog -C 8 -P '$closetoweek'
1344# $lessthanweek is $lessthanweeksecs
1345dir2/messages -C 4 -P '$lessthanweek'
1346EOF
1347
1348	set_file('checktest', <<'EOF');
1349[ -s std.err ] && exit 1
1350[ -s std.out ] && exit 1
1351[ -f dir1/syslog ] || exit 1
1352[ -s dir1/syslog ] && exit 1
1353[ -f dir1/syslog.0 ] || exit 1
1354[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1355[ -f dir1/syslog.1 ] || exit 1
1356[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1357[ -f dir1/syslog.2 ] || exit 1
1358[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1359[ -f dir1/syslog.3 ] || exit 1
1360[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1361[ -f dir1/syslog.4 ] || exit 1
1362[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1363[ -f dir1/syslog.5 ] || exit 1
1364[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1365[ -f dir1/syslog.6 ] || exit 1
1366[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1367[ -f dir1/syslog.7 ] || exit 1
1368[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1369[ -f dir1/syslog.8 ] && exit 1
1370
1371[ -f dir2/messages ] || exit 1
1372[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1373[ -f dir2/messages.0 ] || exit 1
1374[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1375[ -f dir2/messages.1 ] || exit 1
1376[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1377[ -f dir2/messages.2 ] || exit 1
1378[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1379[ -f dir2/messages.3 ] || exit 1
1380[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1381[ -f dir2/messages.4 ] && exit 1
1382exit 0
1383EOF
1384
1385        set_file('runtest', <<"EOF");
1386# test "logadm9"
1387$envsetup
1388exec $bindir/logadm -f logadm.conf >std.out 2>std.err
1389EOF
1390}
1391
1392###########################################################################
1393#
1394#       logadm9d -- test of age check like logadm9, but age is a couple days
1395#
1396###########################################################################
1397sub logadm9d {
1398	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1399	set_file('dir1/syslog', 'initially dir1/syslog');
1400	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1401	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1402	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1403	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1404	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1405	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1406	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1407	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1408	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1409	set_file('dir2/messages', 'initially dir2/messages');
1410	set_file('dir2/messages.0', 'initially dir2/messages.0');
1411	set_file('dir2/messages.1', 'initially dir2/messages.1');
1412	set_file('dir2/messages.2', 'initially dir2/messages.2');
1413	set_file('dir2/messages.3', 'initially dir2/messages.3');
1414
1415	$now = time;
1416	$nowstr = gmtime($now);
1417	# a day minus 30 seconds ago...
1418	$closetodaysecs = $now - (60 * 60 * 24 - 30);
1419	$closetoday = gmtime($closetodaysecs);
1420	# a day minus six hours ago...
1421	$lessthandaysecs = $now - (60 * 60 * 24 - 60 * 60 * 6);
1422	$lessthanday = gmtime($lessthandaysecs);
1423
1424	set_file('logadm.conf', <<"EOF");
1425# now: $nowstr is $now
1426# $closetoday is $closetodaysecs
1427dir1/syslog -p 1d -C 8 -P '$closetoday'
1428# $lessthanday is $lessthandaysecs
1429dir2/messages -p 1d -C 4 -P '$lessthanday'
1430EOF
1431
1432	set_file('checktest', <<'EOF');
1433[ -s std.err ] && exit 1
1434[ -s std.out ] && exit 1
1435[ -f dir1/syslog ] || exit 1
1436[ -s dir1/syslog ] && exit 1
1437[ -f dir1/syslog.0 ] || exit 1
1438[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1439[ -f dir1/syslog.1 ] || exit 1
1440[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1441[ -f dir1/syslog.2 ] || exit 1
1442[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1443[ -f dir1/syslog.3 ] || exit 1
1444[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1445[ -f dir1/syslog.4 ] || exit 1
1446[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1447[ -f dir1/syslog.5 ] || exit 1
1448[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1449[ -f dir1/syslog.6 ] || exit 1
1450[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1451[ -f dir1/syslog.7 ] || exit 1
1452[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1453[ -f dir1/syslog.8 ] && exit 1
1454
1455[ -f dir2/messages ] || exit 1
1456[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1457[ -f dir2/messages.0 ] || exit 1
1458[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1459[ -f dir2/messages.1 ] || exit 1
1460[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1461[ -f dir2/messages.2 ] || exit 1
1462[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1463[ -f dir2/messages.3 ] || exit 1
1464[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1465[ -f dir2/messages.4 ] && exit 1
1466exit 0
1467EOF
1468
1469        set_file('runtest', <<"EOF");
1470# test "logadm9d"
1471$envsetup
1472exec $bindir/logadm -f logadm.conf >std.out 2>std.err
1473EOF
1474}
1475
1476###########################################################################
1477#
1478#       logadm10 -- test of size-based rotation check
1479#
1480###########################################################################
1481sub logadm10 {
1482	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1483	set_file('dir1/syslog', 'initially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
1484	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1485	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1486	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1487	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1488	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1489	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1490	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1491	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1492	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1493	set_file('dir2/messages', 'initially dir2/messages');
1494	set_file('dir2/messages.0', 'initially dir2/messages.0');
1495	set_file('dir2/messages.1', 'initially dir2/messages.1');
1496	set_file('dir2/messages.2', 'initially dir2/messages.2');
1497	set_file('dir2/messages.3', 'initially dir2/messages.3');
1498
1499	set_file('logadm.conf', <<"EOF");
1500dir1/syslog -C 8 -s 30b
1501dir2/messages -C 4 -s 30b
1502EOF
1503
1504	set_file('checktest', <<'EOF');
1505[ -s std.err ] && exit 1
1506[ -s std.out ] && exit 1
1507[ -f dir1/syslog ] || exit 1
1508[ -s dir1/syslog ] && exit 1
1509[ -f dir1/syslog.0 ] || exit 1
1510[ "xinitially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1511[ -f dir1/syslog.1 ] || exit 1
1512[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1513[ -f dir1/syslog.2 ] || exit 1
1514[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1515[ -f dir1/syslog.3 ] || exit 1
1516[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1517[ -f dir1/syslog.4 ] || exit 1
1518[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1519[ -f dir1/syslog.5 ] || exit 1
1520[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1521[ -f dir1/syslog.6 ] || exit 1
1522[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1523[ -f dir1/syslog.7 ] || exit 1
1524[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1525[ -f dir1/syslog.8 ] && exit 1
1526
1527[ -f dir2/messages ] || exit 1
1528[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1529[ -f dir2/messages.0 ] || exit 1
1530[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1531[ -f dir2/messages.1 ] || exit 1
1532[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1533[ -f dir2/messages.2 ] || exit 1
1534[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1535[ -f dir2/messages.3 ] || exit 1
1536[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1537[ -f dir2/messages.4 ] && exit 1
1538exit 0
1539EOF
1540
1541        set_file('runtest', <<"EOF");
1542# test "logadm10"
1543$envsetup
1544exec $bindir/logadm -f logadm.conf >std.out 2>std.err
1545EOF
1546}
1547
1548###########################################################################
1549#
1550#       logadm11 -- test of size-based expiration check
1551#
1552###########################################################################
1553sub logadm11 {
1554	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1555	set_file('dir1/syslog', 'initially dir1/syslog');
1556	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1557	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1558	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1559	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1560	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1561	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1562	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1563	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1564	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1565	set_file('dir2/messages', 'initially dir2/messages');
1566	set_file('dir2/messages.0', 'initially dir2/messages.0');
1567	set_file('dir2/messages.1', 'initially dir2/messages.1');
1568	set_file('dir2/messages.2', 'initially dir2/messages.2');
1569	set_file('dir2/messages.3', 'initially dir2/messages.3');
1570
1571	set_file('logadm.conf', <<"EOF");
1572dir1/syslog -C 8 -s 30b -S 75b
1573dir2/messages -C 4 -s 30b -S 75b
1574EOF
1575
1576	set_file('checktest', <<'EOF');
1577[ -s std.err ] && exit 1
1578[ -s std.out ] && exit 1
1579[ -f dir1/syslog ] || exit 1
1580[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
1581[ -f dir1/syslog.0 ] || exit 1
1582[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1583[ -f dir1/syslog.1 ] || exit 1
1584[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1585[ -f dir1/syslog.2 ] || exit 1
1586[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1587[ -f dir1/syslog.3 ] && exit 1
1588[ -f dir1/syslog.4 ] && exit 1
1589[ -f dir1/syslog.5 ] && exit 1
1590[ -f dir1/syslog.6 ] && exit 1
1591[ -f dir1/syslog.7 ] && exit 1
1592[ -f dir1/syslog.8 ] && exit 1
1593
1594[ -f dir2/messages ] || exit 1
1595[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1596[ -f dir2/messages.0 ] || exit 1
1597[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1598[ -f dir2/messages.1 ] || exit 1
1599[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1600[ -f dir2/messages.2 ] || exit 1
1601[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1602[ -f dir2/messages.3 ] && exit 1
1603[ -f dir2/messages.4 ] && exit 1
1604exit 0
1605EOF
1606
1607        set_file('runtest', <<"EOF");
1608# test "logadm11"
1609$envsetup
1610exec $bindir/logadm -f logadm.conf >std.out 2>std.err
1611EOF
1612}
1613
1614###########################################################################
1615#
1616#	logadm12 -- ENOENT error path
1617#
1618###########################################################################
1619sub logadm12 {
1620	set_file('std.err.expect', <<'EOF');
1621logadm: Warning: logfile: No such file or directory
1622EOF
1623
1624	set_file('checktest', <<"EOF");
1625[ -s std.out ] && exit 1
1626exec /bin/diff std.err std.err.expect
1627EOF
1628
1629	set_file('runtest', <<"EOF");
1630# test "logadm12"
1631$envsetup
1632exec $bindir/logadm -f /dev/null logfile >std.out 2>std.err
1633EOF
1634}
1635
1636###########################################################################
1637#
1638#	logadm13 -- ENOENT error path with -N flag
1639#
1640###########################################################################
1641sub logadm13 {
1642	set_file('checktest', <<"EOF");
1643[ -s std.out ] && exit 1
1644[ -s std.err ] && exit 1
1645exit 0
1646EOF
1647
1648	set_file('runtest', <<"EOF");
1649# test "logadm13"
1650$envsetup
1651exec $bindir/logadm -N -f /dev/null logfile >std.out 2>std.err
1652EOF
1653}
1654
1655###########################################################################
1656#
1657#       logadm14 -- test of -n and -v flags
1658#
1659###########################################################################
1660sub logadm14 {
1661	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1662	set_file('dir1/syslog', 'initially dir1/syslog');
1663	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1664	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1665	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1666	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1667	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1668	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1669	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1670	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1671	mkdir 'dir2', 0777 or die "mkdir dir2: $!\n";
1672	set_file('dir2/messages', 'initially dir2/messages');
1673	set_file('dir2/messages.0', 'initially dir2/messages.0');
1674	set_file('dir2/messages.1', 'initially dir2/messages.1');
1675	set_file('dir2/messages.2', 'initially dir2/messages.2');
1676	set_file('dir2/messages.3', 'initially dir2/messages.3');
1677
1678	set_file('logadm.conf', <<'EOF');
1679#
1680# logadm.conf
1681#
1682# Default settings for system log file management.
1683# The -w option to logadm(1M) is the preferred way to write to this file,
1684# but if you do edit it by hand, use "logadm -V" to check it for errors.
1685# but if you do edit it by hand, use "logadm -V" to check it for errors.
1686#
1687# The format of lines in this file is:
1688#       <logname> <options>
1689# For each logname listed here, the default options to logadm
1690# are given.  Options given on the logadm command line override
1691# the defaults contained in this file.
1692#
1693# logadm typically runs early every morning via an entry in
1694# root's crontab (see crontab(1)).
1695#
1696dir1/syslog -C 8 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
1697dir2/messages -C 4 -a 'echo kill -HUP `cat /etc/syslog.pid` >> cmd.out'
1698#
1699# The entry below is used by turnacct(1M)
1700#
1701/var/adm/pacct -C 0 -a '/usr/lib/acct/accton pacct' -g adm -m 664 -o adm -p never
1702EOF
1703
1704	$gid = $);
1705	$gid =~ s/ .*//;
1706	set_file('grep.out.expect', <<'EOF'.<<"EOF".<<'EOF'.<<"EOF".<<'EOF');
1707# loading logadm.conf
1708# processing logname: dir1/syslog
1709#     using default rotate rules: -s1b -p1w
1710#     using default template: $file.$n
1711mkdir -p dir1 # verify directory exists
1712mv -f dir1/syslog.7 dir1/syslog.8 # rotate log file
1713mkdir -p dir1 # verify directory exists
1714mv -f dir1/syslog.6 dir1/syslog.7 # rotate log file
1715mkdir -p dir1 # verify directory exists
1716mv -f dir1/syslog.5 dir1/syslog.6 # rotate log file
1717mkdir -p dir1 # verify directory exists
1718mv -f dir1/syslog.4 dir1/syslog.5 # rotate log file
1719mkdir -p dir1 # verify directory exists
1720mv -f dir1/syslog.3 dir1/syslog.4 # rotate log file
1721mkdir -p dir1 # verify directory exists
1722mv -f dir1/syslog.2 dir1/syslog.3 # rotate log file
1723mkdir -p dir1 # verify directory exists
1724mv -f dir1/syslog.1 dir1/syslog.2 # rotate log file
1725mkdir -p dir1 # verify directory exists
1726mv -f dir1/syslog.0 dir1/syslog.1 # rotate log file
1727mkdir -p dir1 # verify directory exists
1728mv -f dir1/syslog dir1/syslog.0 # rotate log file
1729touch dir1/syslog
1730EOF
1731chown $>:$gid dir1/syslog
1732EOF
1733chmod 664 dir1/syslog
1734# processing logname: dir2/messages
1735#     using default rotate rules: -s1b -p1w
1736#     using default template: $file.$n
1737mkdir -p dir2 # verify directory exists
1738mv -f dir2/messages.3 dir2/messages.4 # rotate log file
1739mkdir -p dir2 # verify directory exists
1740mv -f dir2/messages.2 dir2/messages.3 # rotate log file
1741mkdir -p dir2 # verify directory exists
1742mv -f dir2/messages.1 dir2/messages.2 # rotate log file
1743mkdir -p dir2 # verify directory exists
1744mv -f dir2/messages.0 dir2/messages.1 # rotate log file
1745mkdir -p dir2 # verify directory exists
1746mv -f dir2/messages dir2/messages.0 # rotate log file
1747touch dir2/messages
1748EOF
1749chown $>:$gid dir2/messages
1750EOF
1751chmod 664 dir2/messages
1752# processing logname: /var/adm/pacct
1753#     using default template: $file.$n
1754sh -c echo kill -HUP `cat /etc/syslog.pid` >> cmd.out # -a cmd
1755# logadm.conf unchanged
1756EOF
1757
1758	set_file('checktest', <<'EOF');
1759[ -s std.err ] && exit 1
1760[ -f std.out ] || exit 1
1761[ -f dir1/syslog ] || exit 1
1762[ "xinitially dir1/syslog" = "x`/bin/cat dir1/syslog`" ] || exit 1
1763[ -f dir1/syslog.0 ] || exit 1
1764[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1765[ -f dir1/syslog.1 ] || exit 1
1766[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1767[ -f dir1/syslog.2 ] || exit 1
1768[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1769[ -f dir1/syslog.3 ] || exit 1
1770[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1771[ -f dir1/syslog.4 ] || exit 1
1772[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1773[ -f dir1/syslog.5 ] || exit 1
1774[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1775[ -f dir1/syslog.6 ] || exit 1
1776[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1777[ -f dir1/syslog.7 ] || exit 1
1778[ "xinitially dir1/syslog.7" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1779[ -f dir1/syslog.8 ] && exit 1
1780
1781[ -f dir2/messages ] || exit 1
1782[ "xinitially dir2/messages" = "x`/bin/cat dir2/messages`" ] || exit 1
1783[ -f dir2/messages.0 ] || exit 1
1784[ "xinitially dir2/messages.0" = "x`/bin/cat dir2/messages.0`" ] || exit 1
1785[ -f dir2/messages.1 ] || exit 1
1786[ "xinitially dir2/messages.1" = "x`/bin/cat dir2/messages.1`" ] || exit 1
1787[ -f dir2/messages.2 ] || exit 1
1788[ "xinitially dir2/messages.2" = "x`/bin/cat dir2/messages.2`" ] || exit 1
1789[ -f dir2/messages.3 ] || exit 1
1790[ "xinitially dir2/messages.3" = "x`/bin/cat dir2/messages.3`" ] || exit 1
1791[ -f dir2/messages.4 ] && exit 1
1792/bin/grep -v 'recording rotation date' std.out > grep.out
1793exec /bin/diff grep.out grep.out.expect
1794EOF
1795
1796        set_file('runtest', <<"EOF");
1797# test "logadm14"
1798$envsetup
1799exec $bindir/logadm -nv -f logadm.conf >std.out 2>std.err
1800EOF
1801}
1802
1803###########################################################################
1804#
1805#	logadm15 -- test of -T
1806#
1807###########################################################################
1808sub logadm15 {
1809	set_file('logfile', '');
1810	set_file('logfile.0', 'initially logfile.0');
1811	set_file('logfile.1', 'initially logfile.1');
1812	set_file('logfile.2', 'initially logfile.2');
1813	set_file('logfile.3', 'initially logfile.3');
1814	set_file('logfile.4', 'initially logfile.4');
1815	set_file('logfile.5', 'initially logfile.5');
1816	set_file('logfile.6', 'initially logfile.6');
1817	set_file('logfile.7', 'initially logfile.7');
1818	set_file('logfile.8', 'initially logfile.8');
1819	set_file('logfile.9', 'initially logfile.9');
1820
1821	set_file('checktest', <<'EOF');
1822[ -s std.err ] && exit 1
1823[ -s std.out ] && exit 1
1824[ -f logfile ] || exit 1
1825[ "x" = "x`/bin/cat logfile`" ] || exit 1
1826[ -f logfile.0 ] || exit 1
1827[ "xinitially logfile.0" = "x`/bin/cat logfile.0`" ] || exit 1
1828[ -f logfile.1 ] || exit 1
1829[ "xinitially logfile.1" = "x`/bin/cat logfile.1`" ] || exit 1
1830[ -f logfile.2 ] || exit 1
1831[ "xinitially logfile.2" = "x`/bin/cat logfile.2`" ] || exit 1
1832[ -f logfile.3 ] && exit 1
1833[ -f logfile.4 ] || exit 1
1834[ "xinitially logfile.4" = "x`/bin/cat logfile.4`" ] || exit 1
1835[ -f logfile.5 ] && exit 1
1836[ -f logfile.6 ] || exit 1
1837[ "xinitially logfile.6" = "x`/bin/cat logfile.6`" ] || exit 1
1838[ -f logfile.7 ] && exit 1
1839[ -f logfile.8 ] || exit 1
1840[ "xinitially logfile.8" = "x`/bin/cat logfile.8`" ] || exit 1
1841[ -f logfile.9 ] && exit 1
1842[ -f logfile.10 ] && exit 1
1843exit 0
1844EOF
1845
1846	set_file('runtest', <<"EOF");
1847# test "logadm15"
1848$envsetup
1849exec $bindir/logadm -f /dev/null logfile -C1 -T '*.[13579]'>std.out 2>std.err
1850EOF
1851}
1852
1853###########################################################################
1854#
1855#	logadm16 -- test of -h
1856#
1857###########################################################################
1858sub logadm16 {
1859	set_file('std.err.expect', <<'EOF');
1860Usage: logadm [options]
1861       (processes all entries in /etc/logadm.conf or conffile given by -f)
1862   or: logadm [options] logname...
1863       (processes the given lognames)
1864
1865General options:
1866        -e mailaddr     mail errors to given address
1867        -f conffile     use conffile instead of /etc/logadm.conf
1868        -h              display help
1869        -N              not an error if log file nonexistent
1870        -n              show actions, don't perform them
1871        -r              remove logname entry from conffile
1872        -V              ensure conffile entries exist, correct
1873        -v              print info about actions happening
1874        -w entryname    write entry to config file
1875
1876Options which control when a logfile is rotated:
1877(default is: -s1b -p1w if no -s or -p)
1878        -p period       only rotate if period passed since last rotate
1879        -P timestamp    used to store rotation date in conffile
1880        -s size         only rotate if given size or greater
1881
1882Options which control how a logfile is rotated:
1883(default is: -t '$file.$n', owner/group/mode taken from log file)
1884        -a cmd          execute cmd after taking actions
1885        -b cmd          execute cmd before taking actions
1886        -c              copy & truncate logfile, don't rename
1887        -g group        new empty log file group
1888        -l              rotate log file with local time rather than UTC
1889        -m mode         new empty log file mode
1890        -M cmd          execute cmd to rotate the log file
1891        -o owner        new empty log file owner
1892        -R cmd          run cmd on file after rotate
1893        -t template     template for naming old logs
1894        -z count        gzip old logs except most recent count
1895
1896Options which control the expiration of old logfiles:
1897(default is: -C10 if no -A, -C, or -S)
1898        -A age          expire logs older than age
1899        -C count        expire old logs until count remain
1900        -E cmd          run cmd on file to expire
1901        -S size         expire until space used is below size
1902        -T pattern      pattern for finding old logs
1903EOF
1904
1905	set_file('checktest', <<'EOF');
1906[ -s std.out ] && exit 1
1907exec /bin/diff std.err std.err.expect
1908EOF
1909
1910	set_file('runtest', <<"EOF");
1911# test "logadm16"
1912$envsetup
1913exec $bindir/logadm -h >std.out 2>std.err
1914EOF
1915}
1916
1917###########################################################################
1918#
1919#       logadm17 -- test that mkdir -p happens as necessary
1920#
1921###########################################################################
1922sub logadm17 {
1923	set_file('logfile', 'initially logfile');
1924
1925	set_file('checktest', <<'EOF');
1926[ -s std.err ] && exit 1
1927[ -s std.out ] && exit 1
1928[ -f dir1/dir2/logfile ] || exit 1
1929[ -f logfile ] || exit 1
1930[ "xinitially logfile" = "x`/bin/cat dir1/dir2/logfile`" ] || exit 1
1931exit 0
1932EOF
1933
1934        set_file('runtest', <<"EOF");
1935# test "logadm17"
1936$envsetup
1937exec $bindir/logadm -f /dev/null -t 'dir1/dir2/\$basename' logfile -p now >std.out 2>std.err
1938EOF
1939}
1940
1941###########################################################################
1942#
1943#       logadm18 -- test of -M option
1944#
1945###########################################################################
1946sub logadm18 {
1947	mkdir 'dir1', 0777 or die "mkdir dir1: $!\n";
1948	set_file('dir1/syslog', 'initially dir1/syslog');
1949	set_file('dir1/syslog.0', 'initially dir1/syslog.0');
1950	set_file('dir1/syslog.1', 'initially dir1/syslog.1');
1951	set_file('dir1/syslog.2', 'initially dir1/syslog.2');
1952	set_file('dir1/syslog.3', 'initially dir1/syslog.3');
1953	set_file('dir1/syslog.4', 'initially dir1/syslog.4');
1954	set_file('dir1/syslog.5', 'initially dir1/syslog.5');
1955	set_file('dir1/syslog.6', 'initially dir1/syslog.6');
1956	set_file('dir1/syslog.7', 'initially dir1/syslog.7');
1957
1958	set_file('logadm.conf', <<"EOF");
1959dir1/syslog -C 8 -s 1b -M '/bin/tr [a-z] [A-Z] < \$file > \$nfile; /bin/rm -f \$file'
1960EOF
1961
1962	set_file('checktest', <<'EOF');
1963[ -s std.err ] && exit 1
1964[ -s std.out ] && exit 1
1965[ -f dir1/syslog ] || exit 1
1966[ -s dir1/syslog ] && exit 1
1967[ -f dir1/syslog.0 ] || exit 1
1968[ "xINITIALLY DIR1/SYSLOG" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
1969[ -f dir1/syslog.1 ] || exit 1
1970[ "xinitially dir1/syslog.0" = "x`/bin/cat dir1/syslog.1`" ] || exit 1
1971[ -f dir1/syslog.2 ] || exit 1
1972[ "xinitially dir1/syslog.1" = "x`/bin/cat dir1/syslog.2`" ] || exit 1
1973[ -f dir1/syslog.3 ] || exit 1
1974[ "xinitially dir1/syslog.2" = "x`/bin/cat dir1/syslog.3`" ] || exit 1
1975[ -f dir1/syslog.4 ] || exit 1
1976[ "xinitially dir1/syslog.3" = "x`/bin/cat dir1/syslog.4`" ] || exit 1
1977[ -f dir1/syslog.5 ] || exit 1
1978[ "xinitially dir1/syslog.4" = "x`/bin/cat dir1/syslog.5`" ] || exit 1
1979[ -f dir1/syslog.6 ] || exit 1
1980[ "xinitially dir1/syslog.5" = "x`/bin/cat dir1/syslog.6`" ] || exit 1
1981[ -f dir1/syslog.7 ] || exit 1
1982[ "xinitially dir1/syslog.6" = "x`/bin/cat dir1/syslog.7`" ] || exit 1
1983[ -f dir1/syslog.8 ] && exit 1
1984
1985exit 0
1986EOF
1987
1988        set_file('runtest', <<"EOF");
1989# test "logadm18"
1990$envsetup
1991exec $bindir/logadm -f logadm.conf >std.out 2>std.err
1992EOF
1993}
1994
1995#############################################################################
1996#
1997#         logadm19 -- test of  -l
1998#
1999#############################################################################
2000sub logadm19 {
2001        set_file('logfile', 'initially logfile');
2002
2003        set_file('checktest', <<'EOF');
2004[ -s std.err ] && exit 1
2005[ -s std.out ] && exit 1
2006[ -s logfile ] && exit 1
2007TZ= export TZ
2008d=`/bin/date +\%d\%H\%M`
2009[ -f logfile.$d ] || exit 1
2010[ "xinitially logfile" = "x`/bin/cat logfile.$d`" ] || exit 1
2011exit 0
2012EOF
2013
2014        set_file('runtest', <<"EOF");
2015# test "logadm4"
2016$envsetup
2017exec $bindir/logadm -f /dev/null -l -p now logfile -t '\$file.\%d\%H\%M' >std.out 2>std.err
2018EOF
2019}
2020