diff options
28 files changed, 419 insertions, 21 deletions
diff --git a/regress/usr.sbin/syslogd/Makefile b/regress/usr.sbin/syslogd/Makefile index e6321443204..988a01a9cff 100644 --- a/regress/usr.sbin/syslogd/Makefile +++ b/regress/usr.sbin/syslogd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.2 2014/08/29 21:55:55 bluhm Exp $ +# $OpenBSD: Makefile,v 1.3 2014/09/02 00:26:30 bluhm Exp $ # The following ports must be installed for the regression tests: # p5-IO-Socket-INET6 object interface for AF_INET and AF_INET6 domain sockets @@ -24,7 +24,7 @@ regress: ARGS != cd ${.CURDIR} && ls args-*.pl TARGETS ?= ${ARGS} REGRESS_TARGETS = ${TARGETS:S/^/run-regress-/} -CLEANFILES += *.log *.pem *.crt *.key syslogd.conf stamp-* +CLEANFILES += *.log *.log.? *.pem *.crt *.key syslogd.conf stamp-* CLEANFILES += ktrace.out *.ktrace *.fstat .MAIN: all diff --git a/regress/usr.sbin/syslogd/Proc.pm b/regress/usr.sbin/syslogd/Proc.pm index ca4081b5186..a3d0976d58c 100644 --- a/regress/usr.sbin/syslogd/Proc.pm +++ b/regress/usr.sbin/syslogd/Proc.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Proc.pm,v 1.1 2014/08/20 20:52:14 bluhm Exp $ +# $OpenBSD: Proc.pm,v 1.2 2014/09/02 00:26:30 bluhm Exp $ # Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org> # Copyright (c) 2014 Florian Riehm <mail@friehm.de> @@ -72,6 +72,7 @@ sub new { or die "$class log file $self->{logfile} create failed: $!"; $fh->autoflush; $self->{log} = $fh; + $self->{ppid} = $$; return bless $self, $class; } @@ -125,6 +126,9 @@ sub wait { my $self = shift; my $flags = shift; + # if we a not the parent process, assume the child is still running + return 0 unless $self->{ppid} == $$; + my $pid = $self->{pid} or croak ref($self), " no child pid"; my $kid = waitpid($pid, $flags); @@ -194,4 +198,20 @@ sub kill_child { return $self; } +sub kill { + my $self = shift; + my $sig = shift // 'TERM'; + my $pid = shift // $self->{pid}; + + if (kill($sig => $pid) != 1) { + my $sudo = $ENV{SUDO}; + $sudo && $!{EPERM} + or die ref($self), " kill $pid failed: $!"; + my @cmd = ($sudo, '/bin/kill', "-$sig", $pid); + system(@cmd) + and die ref($self), " sudo kill $pid failed: $?"; + } + return $self; +} + 1; diff --git a/regress/usr.sbin/syslogd/Syslogd.pm b/regress/usr.sbin/syslogd/Syslogd.pm index 0ab7f2a4ea5..b5f5ec550b0 100644 --- a/regress/usr.sbin/syslogd/Syslogd.pm +++ b/regress/usr.sbin/syslogd/Syslogd.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Syslogd.pm,v 1.2 2014/08/29 21:55:55 bluhm Exp $ +# $OpenBSD: Syslogd.pm,v 1.3 2014/09/02 00:26:30 bluhm Exp $ # Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org> # Copyright (c) 2014 Florian Riehm <mail@friehm.de> @@ -61,7 +61,13 @@ sub new { print $fh "*.*\t$loghost\n"; close $fh; - open($fh, '>', $self->{outfile}) + return $self->create_out(); +} + +sub create_out { + my $self = shift; + + open(my $fh, '>', $self->{outfile}) or die ref($self), " create log file $self->{outfile} failed: $!"; close $fh; @@ -120,6 +126,7 @@ sub up { close($fh) or die ref($self), " close $self->{fstatfile} failed: $!"; } + return $self; } sub _make_abspath { @@ -131,4 +138,56 @@ sub _make_abspath { return $file; } +sub kill_privsep { + return Proc::kill(@_); +} + +sub kill_syslogd { + my $self = shift; + my $sig = shift // 'TERM'; + my $ppid = shift // $self->{pid}; + + # find syslogd child of privsep parent + my @cmd = ("ps", "-ww", "-p", $ppid, "-U", "_syslogd", + "-o", "pid,ppid,comm", ); + open(my $ps, '-|', @cmd) + or die ref($self), " open pipe from '@cmd' failed: $!"; + my @pslist; + my @pshead = split(' ', scalar <$ps>); + while (<$ps>) { + s/\s+$//; + my %h; + @h{@pshead} = split(' ', $_, scalar @pshead); + push @pslist, \%h; + } + close($ps) or die ref($self), $! ? + " close pipe from '@cmd' failed: $!" : + " command '@cmd' failed: $?"; + my @pschild = + grep { $_->{PPID} == $ppid && $_->{COMMAND} eq "syslogd" } @pslist; + @pschild == 1 + or die ref($self), " not one privsep child: ", + join(" ", map { $_->{PID} } @pschild); + + return Proc::kill($self, $sig, $pschild[0]{PID}); +} + +my $rotate_num = 0; +sub rotate { + my $self = shift; + + foreach my $name (qw(file pipe)) { + my $file = $self->{"out$name"}; + for (my $i = $rotate_num; $i >= 0; $i--) { + my $new = $file. ".$i"; + my $old = $file. ($i > 0 ? ".".($i-1) : ""); + + rename($old, $new) or die ref($self), + " rename from '$old' to '$new' failed: $!"; + } + } + $rotate_num++; + return $self->create_out(); +}; + 1; diff --git a/regress/usr.sbin/syslogd/args-client-udp4-nodns.pl b/regress/usr.sbin/syslogd/args-client-udp4-nodns.pl index c1a7bbc344a..a0cced6d04f 100644 --- a/regress/usr.sbin/syslogd/args-client-udp4-nodns.pl +++ b/regress/usr.sbin/syslogd/args-client-udp4-nodns.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( client => { diff --git a/regress/usr.sbin/syslogd/args-client-udp4.pl b/regress/usr.sbin/syslogd/args-client-udp4.pl index 8b16fb16458..de58100b4d5 100644 --- a/regress/usr.sbin/syslogd/args-client-udp4.pl +++ b/regress/usr.sbin/syslogd/args-client-udp4.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( client => { diff --git a/regress/usr.sbin/syslogd/args-client-udp6-nodns.pl b/regress/usr.sbin/syslogd/args-client-udp6-nodns.pl index c608fff2539..b8b7da109eb 100644 --- a/regress/usr.sbin/syslogd/args-client-udp6-nodns.pl +++ b/regress/usr.sbin/syslogd/args-client-udp6-nodns.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( client => { diff --git a/regress/usr.sbin/syslogd/args-client-udp6.pl b/regress/usr.sbin/syslogd/args-client-udp6.pl index dda6b91b61a..8580516087c 100644 --- a/regress/usr.sbin/syslogd/args-client-udp6.pl +++ b/regress/usr.sbin/syslogd/args-client-udp6.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( client => { diff --git a/regress/usr.sbin/syslogd/args-localhost-only4.pl b/regress/usr.sbin/syslogd/args-localhost-only4.pl index e350ac8d595..44947517922 100644 --- a/regress/usr.sbin/syslogd/args-localhost-only4.pl +++ b/regress/usr.sbin/syslogd/args-localhost-only4.pl @@ -6,6 +6,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-localhost-only6.pl b/regress/usr.sbin/syslogd/args-localhost-only6.pl index c6b3e2cca5c..fbe9437c92b 100644 --- a/regress/usr.sbin/syslogd/args-localhost-only6.pl +++ b/regress/usr.sbin/syslogd/args-localhost-only6.pl @@ -6,6 +6,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-localhost-proto-udp4.pl b/regress/usr.sbin/syslogd/args-localhost-proto-udp4.pl index 820cad18f63..e9d726875ee 100644 --- a/regress/usr.sbin/syslogd/args-localhost-proto-udp4.pl +++ b/regress/usr.sbin/syslogd/args-localhost-proto-udp4.pl @@ -5,9 +5,9 @@ # Find the message in client, file, pipe, syslogd, server log. # Check that localhost gets resolved to the 127.0.0.1 address. - use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-localhost-proto-udp6.pl b/regress/usr.sbin/syslogd/args-localhost-proto-udp6.pl index 7b00b59669f..2ee688d9d8f 100644 --- a/regress/usr.sbin/syslogd/args-localhost-proto-udp6.pl +++ b/regress/usr.sbin/syslogd/args-localhost-proto-udp6.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-localhost.pl b/regress/usr.sbin/syslogd/args-localhost.pl index adb1dbdb078..f38de8b3e0c 100644 --- a/regress/usr.sbin/syslogd/args-localhost.pl +++ b/regress/usr.sbin/syslogd/args-localhost.pl @@ -6,6 +6,7 @@ use strict; use warnings; +use Socket; our %args = ( client => { diff --git a/regress/usr.sbin/syslogd/args-maxportlen.pl b/regress/usr.sbin/syslogd/args-maxportlen.pl index 89028f40aa9..842ae23883b 100644 --- a/regress/usr.sbin/syslogd/args-maxportlen.pl +++ b/regress/usr.sbin/syslogd/args-maxportlen.pl @@ -6,6 +6,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-only4.pl b/regress/usr.sbin/syslogd/args-only4.pl index a22eb4afe90..c4b46602ca3 100644 --- a/regress/usr.sbin/syslogd/args-only4.pl +++ b/regress/usr.sbin/syslogd/args-only4.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( client => { diff --git a/regress/usr.sbin/syslogd/args-only6.pl b/regress/usr.sbin/syslogd/args-only6.pl index 019bcb1cdb0..5978dd94ab5 100644 --- a/regress/usr.sbin/syslogd/args-only6.pl +++ b/regress/usr.sbin/syslogd/args-only6.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( client => { diff --git a/regress/usr.sbin/syslogd/args-proto-udp.pl b/regress/usr.sbin/syslogd/args-proto-udp.pl index 0b4d71530f7..daf42e12236 100644 --- a/regress/usr.sbin/syslogd/args-proto-udp.pl +++ b/regress/usr.sbin/syslogd/args-proto-udp.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-proto-udp4.pl b/regress/usr.sbin/syslogd/args-proto-udp4.pl index 2c44dd6e460..178fb73cd58 100644 --- a/regress/usr.sbin/syslogd/args-proto-udp4.pl +++ b/regress/usr.sbin/syslogd/args-proto-udp4.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-proto-udp6.pl b/regress/usr.sbin/syslogd/args-proto-udp6.pl index 40080a45573..45da6564248 100644 --- a/regress/usr.sbin/syslogd/args-proto-udp6.pl +++ b/regress/usr.sbin/syslogd/args-proto-udp6.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-server-udp4.pl b/regress/usr.sbin/syslogd/args-server-udp4.pl index 26f063dfcb4..06e2994a1bc 100644 --- a/regress/usr.sbin/syslogd/args-server-udp4.pl +++ b/regress/usr.sbin/syslogd/args-server-udp4.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-server-udp6.pl b/regress/usr.sbin/syslogd/args-server-udp6.pl index cb5922347de..91a866babe4 100644 --- a/regress/usr.sbin/syslogd/args-server-udp6.pl +++ b/regress/usr.sbin/syslogd/args-server-udp6.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Socket; our %args = ( syslogd => { diff --git a/regress/usr.sbin/syslogd/args-sighup-config.pl b/regress/usr.sbin/syslogd/args-sighup-config.pl new file mode 100644 index 00000000000..4dd4723c3e6 --- /dev/null +++ b/regress/usr.sbin/syslogd/args-sighup-config.pl @@ -0,0 +1,58 @@ +# The client writes a message to Sys::Syslog native method. +# The syslogd writes it into a file and through a pipe. +# The syslogd passes it via UDP to the loghost. +# The server receives the message on its UDP socket. +# Find the message in client, file, pipe, syslogd, server log. +# Check that a modified config file restarts syslogd child. + +use strict; +use warnings; + +our %args = ( + client => { + func => sub { + my $self = shift; + write_between2logs($self, sub { + ${$self->{server}}->loggrep("Signal", 8) + or die ref($self), " no 'Signal' between logs"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + syslogd => { + loggrep => { + qr/config file modified: restarting/ => 1, + qr/config file changed: dying/ => 1, + qr/syslogd: restarted/ => 0, + get_between2loggrep(), + } + }, + server => { + func => sub { + my $self = shift; + read_between2logs($self, sub { + my $conffile = ${$self->{syslogd}}->{conffile}; + open(my $fh, '>>', $conffile) + or die ref($self), " append conf file $conffile failed: $!"; + print $fh "# modified\n"; + close($fh); + ${$self->{syslogd}}->kill_syslogd('HUP'); + ${$self->{syslogd}}->loggrep("syslogd: started", 5) + or die ref($self), " no 'syslogd: started' between logs"; + print STDERR "Signal\n"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + check => sub { + my $self = shift; + my $r = $self->{syslogd}; + foreach my $name (qw(file pipe)) { + my $file = $r->{"out$name"}.".0"; + my $pattern = (get_between2loggrep())[0]; + check_pattern($name, $file, $pattern, \&filegrep); + } + }, +); + +1; diff --git a/regress/usr.sbin/syslogd/args-sighup-privsep.pl b/regress/usr.sbin/syslogd/args-sighup-privsep.pl new file mode 100644 index 00000000000..0b44a2f40ad --- /dev/null +++ b/regress/usr.sbin/syslogd/args-sighup-privsep.pl @@ -0,0 +1,53 @@ +# The client writes a message to Sys::Syslog native method. +# The syslogd writes it into a file and through a pipe. +# The syslogd passes it via UDP to the loghost. +# The server receives the message on its UDP socket. +# Find the message in client, file, pipe, syslogd, server log. +# Check that a SIGHUP is propagated from privsep parent to syslog child. + +use strict; +use warnings; + +our %args = ( + client => { + func => sub { + my $self = shift; + write_between2logs($self, sub { + ${$self->{server}}->loggrep("Signal", 8) + or die ref($self), " no 'Signal' between logs"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + syslogd => { + loggrep => { + qr/syslogd: restarted/ => 1, + get_between2loggrep(), + } + }, + server => { + func => sub { + my $self = shift; + read_between2logs($self, sub { + ${$self->{syslogd}}->rotate(); + ${$self->{syslogd}}->rotate(); + ${$self->{syslogd}}->kill_privsep('HUP'); + ${$self->{syslogd}}->loggrep("syslogd: restarted", 5) + or die ref($self), " no 'syslogd: restarted' between logs"; + print STDERR "Signal\n"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + check => sub { + my $self = shift; + my $r = $self->{syslogd}; + foreach my $name (qw(file pipe)) { + my $file = $r->{"out$name"}.".1"; + my $pattern = (get_between2loggrep())[0]; + check_pattern($name, $file, $pattern, \&filegrep); + } + }, +); + +1; diff --git a/regress/usr.sbin/syslogd/args-sighup.pl b/regress/usr.sbin/syslogd/args-sighup.pl new file mode 100644 index 00000000000..e16234616dd --- /dev/null +++ b/regress/usr.sbin/syslogd/args-sighup.pl @@ -0,0 +1,54 @@ +# The client writes a message to Sys::Syslog native method. +# The syslogd writes it into a file and through a pipe. +# The syslogd passes it via UDP to the loghost. +# The server receives the message on its UDP socket. +# Find the message in client, file, pipe, syslogd, server log. +# Check that a SIGHUP reopens logfile and restarts pipe. + +use strict; +use warnings; + +our %args = ( + client => { + func => sub { + my $self = shift; + write_between2logs($self, sub { + ${$self->{server}}->loggrep("Signal", 8) + or die ref($self), " no 'Signal' between logs"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + syslogd => { + loggrep => { + qr/config file changed: dying/ => 0, + qr/config file modified: restarting/ => 0, + qr/syslogd: restarted/ => 1, + get_between2loggrep(), + } + }, + server => { + func => sub { + my $self = shift; + read_between2logs($self, sub { + ${$self->{syslogd}}->rotate(); + ${$self->{syslogd}}->kill_syslogd('HUP'); + ${$self->{syslogd}}->loggrep("syslogd: restarted", 5) + or die ref($self), " no 'syslogd: restarted' between logs"; + print STDERR "Signal\n"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + check => sub { + my $self = shift; + my $r = $self->{syslogd}; + foreach my $name (qw(file pipe)) { + my $file = $r->{"out$name"}.".0"; + my $pattern = (get_between2loggrep())[0]; + check_pattern($name, $file, $pattern, \&filegrep); + } + }, +); + +1; diff --git a/regress/usr.sbin/syslogd/args-sigpipe.pl b/regress/usr.sbin/syslogd/args-sigpipe.pl new file mode 100644 index 00000000000..bb1c05ce031 --- /dev/null +++ b/regress/usr.sbin/syslogd/args-sigpipe.pl @@ -0,0 +1,40 @@ +# The client writes a message to Sys::Syslog native method. +# The syslogd writes it into a file and through a pipe. +# The syslogd passes it via UDP to the loghost. +# The server receives the message on its UDP socket. +# Find the message in client, file, pipe, syslogd, server log. +# Check that a SIGPIPE is ignored by syslogd. + +use strict; +use warnings; + +our %args = ( + client => { + func => sub { + my $self = shift; + write_between2logs($self, sub { + ${$self->{server}}->loggrep("Signal", 8) + or die ref($self), " no 'Signal' between logs"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + syslogd => { + loggrep => { get_between2loggrep() }, + }, + server => { + func => sub { + my $self = shift; + read_between2logs($self, sub { + ${$self->{syslogd}}->kill_syslogd('PIPE'); + sleep 1; # schedule syslogd + print STDERR "Signal\n"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + file => { loggrep => { get_between2loggrep() } }, + pipe => { loggrep => { get_between2loggrep() } }, +); + +1; diff --git a/regress/usr.sbin/syslogd/args-sigterm.pl b/regress/usr.sbin/syslogd/args-sigterm.pl new file mode 100644 index 00000000000..7973e24a578 --- /dev/null +++ b/regress/usr.sbin/syslogd/args-sigterm.pl @@ -0,0 +1,47 @@ +# The client writes a message to Sys::Syslog native method. +# The syslogd writes it into a file and through a pipe. +# The syslogd passes it via UDP to the loghost. +# The server receives the message on its UDP socket. +# Find the message in client, file, pipe, syslogd, server log. +# Check that a SIGTERM terminates the syslogd child process. + +use strict; +use warnings; + +our %args = ( + client => { + func => sub { + my $self = shift; + write_between2logs($self, sub { + ${$self->{server}}->loggrep("Signal", 8) + or die ref($self), " no 'Signal' between logs"; + }); + }, + loggrep => { get_between2loggrep() }, + }, + syslogd => { + loggrep => qr/\[unpriv\] syslogd child about to exit/, + }, + server => { + func => sub { + my $self = shift; + read_between2logs($self, sub { + ${$self->{syslogd}}->kill_syslogd('TERM'); + my $pattern = "syslogd: exiting on signal 15"; + ${$self->{syslogd}}->loggrep("syslogd: exiting on signal 15", + 5) or die ref($self), + " no 'syslogd: exiting on signal 15' between logs"; + print STDERR "Signal\n"; + }); + }, + down => qr/syslogd: exiting on signal 15/, + loggrep => { + (get_between2loggrep())[0] => 1, + (get_between2loggrep())[2] => 0, + }, + }, + file => { loggrep => (get_between2loggrep())[0] }, + pipe => { loggrep => (get_between2loggrep())[0] }, +); + +1; diff --git a/regress/usr.sbin/syslogd/args-socket.pl b/regress/usr.sbin/syslogd/args-socket.pl index 17c6ed415be..afb48650ff8 100644 --- a/regress/usr.sbin/syslogd/args-socket.pl +++ b/regress/usr.sbin/syslogd/args-socket.pl @@ -8,6 +8,7 @@ use strict; use warnings; +use Socket; our %args = ( client => { diff --git a/regress/usr.sbin/syslogd/funcs.pl b/regress/usr.sbin/syslogd/funcs.pl index 55d3bfcd6b9..bc73c763237 100644 --- a/regress/usr.sbin/syslogd/funcs.pl +++ b/regress/usr.sbin/syslogd/funcs.pl @@ -1,4 +1,4 @@ -# $OpenBSD: funcs.pl,v 1.3 2014/08/29 21:57:17 bluhm Exp $ +# $OpenBSD: funcs.pl,v 1.4 2014/09/02 00:26:30 bluhm Exp $ # Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org> # @@ -24,6 +24,7 @@ use Sys::Syslog qw(:standard :extended :macros); use IO::Socket; use IO::Socket::INET6; +my $firstlog = "syslogd regress test first message"; my $testlog = "syslogd regress test log message"; my $downlog = "syslogd regress client shutdown"; @@ -34,13 +35,29 @@ my $downlog = "syslogd regress client shutdown"; sub write_log { my $self = shift; + write_message($self, $testlog); + write_shutdown($self, @_); +} + +sub write_between2logs { + my $self = shift; + my $func = shift; + + write_message($self, $firstlog); + $func->($self, @_); + write_message($self, $testlog); + write_shutdown($self, @_); +} + +sub write_message { + my $self = shift; + if (defined($self->{connectdomain})) { - print $testlog; - print STDERR $testlog, "\n"; + print @_; + print STDERR @_, "\n"; } else { - syslog(LOG_INFO, $testlog); + syslog(LOG_INFO, @_); } - write_shutdown($self, @_); } sub write_shutdown { @@ -58,12 +75,31 @@ sub write_shutdown { sub read_log { my $self = shift; + read_message($self, $downlog, @_); +} + +sub read_between2logs { + my $self = shift; + my $func = shift; + + read_message($self, $firstlog, @_); + $func->($self, @_); + read_message($self, $testlog, @_); + read_message($self, $downlog, @_); +} + +sub read_message { + my $self = shift; + my $regex = shift; + + local $_; for (;;) { - defined(sysread(STDIN, my $line, 8194)) + # reading udp packets works only with sysread() + defined(sysread(STDIN, $_, 8194)) or die ref($self), " read log line failed: $!"; - chomp $line; - print STDERR ">>> $line\n"; - last if $line =~ /$downlog/; + chomp; + print STDERR ">>> $_\n"; + last if /$regex/; } } @@ -75,6 +111,13 @@ sub get_log { return $testlog; } +sub get_between2loggrep { + return ( + qr/$firstlog/ => 1, + qr/$testlog/ => 1, + ); +} + sub check_logs { my ($c, $r, $s, %args) = @_; diff --git a/regress/usr.sbin/syslogd/syslogd.pl b/regress/usr.sbin/syslogd/syslogd.pl index 794848b6f49..98c351e6f7f 100644 --- a/regress/usr.sbin/syslogd/syslogd.pl +++ b/regress/usr.sbin/syslogd/syslogd.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: syslogd.pl,v 1.1 2014/08/20 20:52:14 bluhm Exp $ +# $OpenBSD: syslogd.pl,v 1.2 2014/09/02 00:26:30 bluhm Exp $ # Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org> # @@ -46,30 +46,36 @@ foreach my $name (qw(client syslogd server)) { } } } -my $s = Server->new( +my($s, $c, $r); +$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}; -my $r = Syslogd->new( +$r = Syslogd->new( connectaddr => "127.0.0.1", connectport => $s && $s->{listenport}, %{$args{syslogd}}, testfile => $testfile, + client => \$c, + server => \$s, ); -my $c = Client->new( +$c = Client->new( func => \&write_log, %{$args{client}}, testfile => $testfile, + syslogd => \$r, + server => \$s, ) unless $args{client}{noclient}; -$s->run unless $args{server}{noserver}; $r->run; +$s->run->up unless $args{server}{noserver}; $r->up; $c->run->up unless $args{client}{noclient}; -$s->up unless $args{server}{noserver}; $c->down unless $args{client}{noclient}; $s->down unless $args{server}{noserver}; @@ -77,3 +83,4 @@ $r->kill_child; $r->down; check_logs($c, $r, $s, %args); +$args{check}->({client => $c, syslogd => $r, server => $s}) if $args{check}; |