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