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