1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#!/usr/bin/perl
# $OpenBSD: syslogd.pl,v 1.5 2015/02/13 21:40:50 bluhm Exp $
# Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use strict;
use warnings;
use Socket;
use Socket6;
use Client;
use Syslogd;
use Server;
use Syslogc;
use RSyslogd;
require 'funcs.pl';
sub usage {
die "usage: syslogd.pl [test-args.pl]\n";
}
my $testfile;
our %args;
if (@ARGV and -f $ARGV[-1]) {
$testfile = pop;
do $testfile
or die "Do test file $testfile failed: ", $@ || $!;
}
@ARGV == 0 or usage();
if ($args{rsyslogd}) {
$args{rsyslogd}{listen}{domain} ||= AF_INET;
$args{rsyslogd}{listen}{addr} ||= "127.0.0.1";
$args{rsyslogd}{listen}{proto} ||= "udp";
}
foreach my $name (qw(client syslogd server rsyslogd)) {
$args{$name} or next;
foreach my $action (qw(connect listen)) {
my $h = $args{$name}{$action} or next;
foreach my $k (qw(domain addr proto port)) {
$args{$name}{"$action$k"} = $h->{$k};
}
}
}
my($s, $c, $r, @m);
$s = RSyslogd->new(
%{$args{rsyslogd}},
listenport => scalar find_ports(%{$args{rsyslogd}{listen}}),
testfile => $testfile,
) if $args{rsyslogd};
$s ||= Server->new(
func => \&read_log,
listendomain => AF_INET,
listenaddr => "127.0.0.1",
%{$args{server}},
testfile => $testfile,
client => \$c,
syslogd => \$r,
) unless $args{server}{noserver};
$args{syslogc} = [ $args{syslogc} ] if ref $args{syslogc} eq 'HASH';
my $i = 0;
@m = map { Syslogc->new(
%{$_},
testfile => $testfile,
ktracefile => "syslogc-$i.ktrace",
logfile => "syslogc-".$i++.".log",
) } @{$args{syslogc}};
$r = Syslogd->new(
connectaddr => "127.0.0.1",
connectport => $s && $s->{listenport},
ctlsock => @m && $m[0]->{ctlsock},
%{$args{syslogd}},
testfile => $testfile,
client => \$c,
server => \$s,
);
$c = Client->new(
func => \&write_log,
%{$args{client}},
testfile => $testfile,
syslogd => \$r,
server => \$s,
) unless $args{client}{noclient};
$r->run unless $r->{late};
$s->run->up unless $args{server}{noserver};
$r->run if $r->{late};
$r->up;
my $control = 0;
foreach (@m) {
if ($_->{early} || $_->{stop}) {
$_->run->up;
$control++;
}
}
$r->loggrep("Accepting control connection") if $control;
foreach (@m) {
if ($_->{stop}) {
$_->kill('STOP');
}
}
$c->run->up unless $args{client}{noclient};
$c->down unless $args{client}{noclient};
$s->down unless $args{server}{noserver};
foreach (@m) {
if ($_->{stop}) {
$_->kill('CONT');
$_->down;
} elsif ($_->{early}) {
$_->down;
} else {
$_->run->up->down;
}
}
$r->kill_child;
$r->down;
$args{check}->({client => $c, syslogd => $r, server => $s}) if $args{check};
check_logs($c, $r, $s, \@m, %args);
|