1# The TLS server closes the connection to syslogd.
2# The client writes a message to Sys::Syslog native method.
3# The syslogd writes it into a file and through a pipe.
4# The syslogd does a TLS reconnect and passes it to loghost.
5# The server receives the message on its new accepted TLS socket.
6# Find the message in client, pipe, syslogd, server log.
7# Check that syslogd and server close and reopen the connection.
8
9use strict;
10use warnings;
11use Socket;
12use Errno ':POSIX';
13
14my @errors = (ECONNREFUSED, EPIPE);
15my $errors = "(". join("|", map { $! = $_ } @errors). ")";
16
17our %args = (
18    client => {
19	func => sub { write_between2logs(shift, sub {
20	    my $self = shift;
21	    ${$self->{syslogd}}->loggrep($errors, 5)
22		or die "no $errors in syslogd.log";
23	})},
24    },
25    syslogd => {
26	loghost => '@tls://127.0.0.1:$connectport',
27	loggrep => {
28	    qr/Logging to FORWTLS \@tls:\/\/127.0.0.1:\d+/ => '>=6',
29	    qr/syslogd: (connect .*|.* connection error: handshake failed): /.
30		$errors => '>=2',
31	    get_between2loggrep(),
32	},
33    },
34    server => {
35	listen => { domain => AF_INET, proto => "tls", addr => "127.0.0.1" },
36	redo => 0,
37	func => sub { read_between2logs(shift, sub {
38	    my $self = shift;
39	    if ($self->{redo}) {
40		$self->{redo}--;
41		return;
42	    }
43	    $self->close();
44	    shutdown(\*STDOUT, 1)
45		or die "shutdown write failed: $!";
46	    ${$self->{syslogd}}->loggrep($errors, 5)
47		or die "no $errors in syslogd.log";
48	    $self->listen();
49	    $self->{redo}++;
50	})},
51	loggrep => {
52	    qr/Accepted/ => 2,
53	    qr/syslogd: loghost .* connection close/ => 1,
54	    qr/syslogd: (connect .*|.* connection error: handshake failed): /.
55		$errors => 1,
56	    get_between2loggrep(),
57	},
58    },
59    file => {
60	loggrep => {
61	    qr/syslogd: (connect .*|.* connection error: handshake failed): /.
62		$errors => '>=1',
63	    get_between2loggrep(),
64	},
65    },
66);
67
681;
69