From 23f427981f434cb35864ab6411325cfa05efa6ac Mon Sep 17 00:00:00 2001 From: bluhm Date: Thu, 6 Apr 2017 16:56:44 +0000 Subject: [PATCH] Check that local syslog messages have the the expected priority. --- .../usr.sbin/syslogd/args-selector-syslog.pl | 39 +++++++++++++++++++ regress/usr.sbin/syslogd/args-selector.pl | 30 +------------- regress/usr.sbin/syslogd/funcs.pl | 32 ++++++++++++++- 3 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 regress/usr.sbin/syslogd/args-selector-syslog.pl diff --git a/regress/usr.sbin/syslogd/args-selector-syslog.pl b/regress/usr.sbin/syslogd/args-selector-syslog.pl new file mode 100644 index 00000000000..e9808ffd13d --- /dev/null +++ b/regress/usr.sbin/syslogd/args-selector-syslog.pl @@ -0,0 +1,39 @@ +# The client connects with TCP. +# The syslogd writes local messages into multiple files depending on priority. +# 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 local syslog messages end up the correct priority file. + +use strict; +use warnings; +use Sys::Syslog; + +my %selector2messages = ( + "syslog.*" => [qw{ start .*accepted .*close exiting.* }], + "syslog.debug" => [qw{ start .*accepted .*close exiting.* }], + "syslog.info" => [qw{ start .*accepted .*close exiting.* }], + "syslog.notice" => [qw{ exiting.* }], + "syslog.warning" => [qw{ exiting.* }], + "syslog.err" => [qw{ exiting.* }], + "syslog.crit" => [], + "syslog.alert" => [], + "syslog.emerg" => [], + "syslog.none" => [], +); + +our %args = ( + client => { + logsock => { type => "tcp", host => "127.0.0.1", port => 514 }, + }, + syslogd => { + options => ["-T", "127.0.0.1:514"], + conf => selector2config(%selector2messages), + }, + multifile => [ + (map { { loggrep => $_ } } (selector2loggrep(%selector2messages))), + ], +); + +1; diff --git a/regress/usr.sbin/syslogd/args-selector.pl b/regress/usr.sbin/syslogd/args-selector.pl index d06dc9e7514..4325f537b66 100644 --- a/regress/usr.sbin/syslogd/args-selector.pl +++ b/regress/usr.sbin/syslogd/args-selector.pl @@ -47,34 +47,6 @@ my %selector2messages = ( "*.*;local6,local7.none" => [qw(local5.notice local5.warning local5.err)], ); -sub selector2config { - my %s2m = @_; - my $conf = ""; - my $i = 0; - foreach my $sel (sort keys %s2m) { - $conf .= "$sel\t\$objdir/file-$i.log\n"; - $i++; - } - return $conf; -} - -sub messages2loggrep { - my %s2m = @_; - my @loggrep; - foreach my $sel (sort keys %s2m) { - my @m = @{$s2m{$sel}}; - my (%msg, %nomsg); - @msg{@m} = (); - @nomsg{@messages} = (); - delete @nomsg{@m}; - push @loggrep, { - (map { qr/: $_$/ => 1 } sort keys %msg), - (map { qr/: $_$/ => 0 } sort keys %nomsg), - }; - } - return @loggrep; -} - our %args = ( client => { func => sub { @@ -89,7 +61,7 @@ our %args = ( conf => selector2config(%selector2messages), }, multifile => [ - (map { { loggrep => $_ } } (messages2loggrep(%selector2messages))), + (map { { loggrep => $_ } } (selector2loggrep(%selector2messages))), ], server => { loggrep => { map { qr/ <$_>/ => 1 } @priorities }, diff --git a/regress/usr.sbin/syslogd/funcs.pl b/regress/usr.sbin/syslogd/funcs.pl index 025de56803c..e9fd6923526 100644 --- a/regress/usr.sbin/syslogd/funcs.pl +++ b/regress/usr.sbin/syslogd/funcs.pl @@ -1,4 +1,4 @@ -# $OpenBSD: funcs.pl,v 1.30 2016/03/21 23:23:15 bluhm Exp $ +# $OpenBSD: funcs.pl,v 1.31 2017/04/06 16:56:44 bluhm Exp $ # Copyright (c) 2010-2015 Alexander Bluhm # @@ -278,6 +278,36 @@ sub get_downlog { return $downlog; } +sub selector2config { + my %s2m = @_; + my $conf = ""; + my $i = 0; + foreach my $sel (sort keys %s2m) { + $conf .= "$sel\t\$objdir/file-$i.log\n"; + $i++; + } + return $conf; +} + +sub selector2loggrep { + my %s2m = @_; + my %allmsg; + @allmsg{map { @$_} values %s2m} = (); + my @loggrep; + foreach my $sel (sort keys %s2m) { + my @m = @{$s2m{$sel}}; + my %msg; + @msg{@m} = (); + my %nomsg = %allmsg; + delete @nomsg{@m}; + push @loggrep, { + (map { qr/: $_$/ => 1 } sort keys %msg), + (map { qr/: $_$/ => 0 } sort keys %nomsg), + }; + } + return @loggrep; +} + sub check_logs { my ($c, $r, $s, $m, %args) = @_; -- 2.20.1