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