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