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