1# The TCP 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 TCP reconnect and passes it to loghost.
5# The server receives the message on its new accepted TCP 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 ref($self), " no $errors in syslogd.log";
23	})},
24    },
25    syslogd => {
26	loghost => '@tcp://127.0.0.1:$connectport',
27	loggrep => {
28	    qr/Logging to FORWTCP \@tcp:\/\/127.0.0.1:\d+/ => '>=6',
29	    qr/syslogd\[\d+\]: (connect .*|.*connection error): $errors/ => 1,
30	    get_between2loggrep(),
31	},
32    },
33    server => {
34	listen => { domain => AF_INET, proto => "tcp", addr => "127.0.0.1" },
35	func => sub { accept_between2logs(shift, sub {
36	    my $self = shift;
37	    $self->close();
38	    shutdown(\*STDOUT, 1)
39		or die ref($self), " shutdown write failed: $!";
40	    ${$self->{syslogd}}->loggrep($errors, 5)
41		or die ref($self), " no $errors in syslogd.log";
42	    $self->listen();
43	})},
44	loggrep => {
45	    qr/^Accepted$/ => 2,
46	    qr/syslogd\[\d+\]: loghost .* connection close/ => 1,
47	    qr/syslogd\[\d+\]: (connect .*|.*connection error): $errors/ => 1,
48	    get_between2loggrep(),
49	},
50    },
51    file => {
52	loggrep => {
53	    qr/syslogd\[\d+\]: (connect .*|.*connection error): $errors/ => 1,
54	    get_between2loggrep(),
55	},
56    },
57);
58
591;
60