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