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
|
# The client writes 300 long messages to UDP socket.
# The syslogd writes it into a file and through a pipe.
# The syslogd does a TCP reconnect and passes it to loghost.
# The server blocks the message on its TCP socket.
# The server waits until the client has written all messages.
# The server closes the TCP connection and accepts a new one.
# The server receives the messages on its new accepted TCP socket.
# This way the server receives a block of messages that is truncated
# at the beginning and at the end.
# Find the message in client, file, pipe, syslogd, server log.
# Check that the server does not get lines that are cut in the middle.
use strict;
use warnings;
use Socket;
our %args = (
client => {
connect => { domain => AF_UNSPEC, addr => "localhost", port => 514 },
func => sub { write_between2logs(shift, sub {
my $self = shift;
write_message($self, get_secondlog());
write_lines($self, 300, 2000);
write_message($self, get_thirdlog());
${$self->{server}}->loggrep("Accepted", 5, 2)
or die ref($self), " server did not accept second connection";
${$self->{syslogd}}->loggrep(qr/syslogd: dropped \d+ messages?/, 5)
or die ref($self), " syslogd did not write dropped message";
})},
},
syslogd => {
options => ["-u"],
loghost => '@tcp://127.0.0.1:$connectport',
loggrep => {
get_between2loggrep(),
get_charlog() => 300,
qr/loghost .* dropped partial message/ => 1,
},
},
server => {
listen => { domain => AF_INET, proto => "tcp", addr => "127.0.0.1" },
redo => 0,
func => sub { read_between2logs(shift, sub {
my $self = shift;
if ($self->{redo}) {
$self->{redo}--;
return;
}
# read slowly to get output buffer out of sync
foreach (1..10) {
print STDERR ">>> ". scalar <STDIN>;
sleep 1;
last if ${$self->{syslogd}}->loggrep(get_thirdlog());
}
${$self->{syslogd}}->loggrep(get_thirdlog(), 30)
or die ref($self), " syslogd did not receive third log";
shutdown(\*STDOUT, 1)
or die "shutdown write failed: $!";
$self->{redo}++;
})},
loggrep => {
qr/Accepted/ => 2,
get_between2loggrep(),
get_thirdlog() => 0,
},
},
file => {
loggrep => {
get_between2loggrep(),
get_secondlog() => 1,
get_thirdlog() => 1,
get_charlog() => 300,
},
},
);
1;
|