1# The client writes 300 messages to Sys::Syslog native method.
2# The syslogd writes it into a file and through a pipe.
3# The syslogd passes it via TCP to the loghost.
4# The server blocks the message on its TCP socket.
5# The server waits until the client as written all messages.
6# The server sends a SIGHUP to syslogd and reads messages from kernel.
7# The client waits until the server has read the first message.
8# Find the message in client, file, pipe, syslogd, server log.
9# Check that the 300 messages are in syslogd and file log.
10# Check that the dropped message is in server and file log.
11
12use strict;
13use warnings;
14use Socket;
15
16our %args = (
17    client => {
18	func => sub { write_between2logs(shift, sub {
19	    my $self = shift;
20	    write_message($self, get_secondlog());
21	    write_lines($self, 300, 1024);
22	    write_message($self, get_thirdlog());
23	    ${$self->{server}}->loggrep(get_secondlog(), 8)
24		or die ref($self), " server did not receive second log";
25	})},
26    },
27    syslogd => {
28	loghost => '@tcp://localhost:$connectport',
29	loggrep => {
30	    get_between2loggrep(),
31	    get_charlog() => 300,
32	},
33    },
34    server => {
35	listen => { domain => AF_UNSPEC, proto => "tcp", addr => "localhost" },
36	rcvbuf => 2**12,
37	func => sub { accept_between2logs(shift, sub {
38	    my $self = shift;
39	    ${$self->{syslogd}}->loggrep(get_thirdlog(), 20)
40		or die ref($self), " syslogd did not receive third log";
41	    ${$self->{syslogd}}->kill_syslogd('HUP');
42	    ${$self->{syslogd}}->loggrep("syslogd: restarted", 5)
43		or die ref($self), " no 'syslogd: restarted' between logs";
44	    # syslogd has shut down, read from kernel socket buffer
45	    read_log($self);
46	})},
47	loggrep => {
48	    get_between2loggrep(),
49	    get_secondlog() => 1,
50	    get_thirdlog() => 0,
51	    qr/syslogd\[\d+\]: start/ => 1,
52	    qr/syslogd\[\d+\]: restart/ => 1,
53	    get_charlog() => '~95',
54	    qr/syslogd\[\d+\]: dropped 2[0-2][0-9] messages to remote loghost/
55		=> 1,
56	},
57    },
58    file => {
59	loggrep => {
60	    get_between2loggrep(),
61	    get_secondlog() => 1,
62	    get_thirdlog() => 1,
63	    qr/syslogd\[\d+\]: start/ => 1,
64	    qr/syslogd\[\d+\]: restart/ => 1,
65	    get_charlog() => 300,
66	    qr/syslogd\[\d+\]: dropped 2[0-2][0-9] messages to remote loghost/
67		=> 1,
68	},
69    },
70);
71
721;
73