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