Subject: | setlogsock() and default methods |
Changes to setlogsock() in 0.28 made the function prepend the
requested socket types to the list of default ones instead of
overriding the default list.
This behaviour is undocumented and makes the test suite unwittingly
test unrelated socket types: for instance, it now claims 'tcp' is fully
working even when "syslog/tcp" cannot be resolved and there is no TCP
listener on the system.
It also makes it impossible to spot things like a missing UDP receiver,
as openlog() will silently fall back to the native logging method.
Please consider the attached patch that reverts this behaviour change
and augments the test suite. The patch context requires the one in
[rt.cpan.org #69986] to be applied, but this should be easily resolvable
should you decide to reject that one.
Thanks for your work on Sys-Syslog,
--
Niko Tyni
ntyni@debian.org
Subject: | 0001-Only-use-the-requested-socket-types-if-setlogsock-is.patch |
From 8a3e720a7f84248c86ade7a7898c084b0faec85b Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Wed, 3 Aug 2011 21:32:19 +0300
Subject: [PATCH] Only use the requested socket types if setlogsock() is
called
Changes to setlogsock() in 0.28 made the function prepend the
requested socket types to the list of default ones instead of
overriding the default list.
This behaviour is undocumented and makes the test suite unwittingly
test unrelated socket types: for instance, it now claims 'tcp' is fully
working even when "syslog/tcp" cannot be resolved and there is no TCP
listener on the system.
Restore the 0.27 behaviour of using only the requested socket
type(s) and augment the test suite to cover this.
---
Syslog.pm | 2 +-
t/syslog.t | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/Syslog.pm b/Syslog.pm
index 4fcedd7..bc6752f 100644
--- a/Syslog.pm
+++ b/Syslog.pm
@@ -314,7 +314,7 @@ sub setlogsock {
for my $sock_type (@sock_types) {
if ( $mechanism{$sock_type}{check}->() ) {
- unshift @connectMethods, $sock_type;
+ @connectMethods = ( $sock_type );
$found = 1;
}
else {
diff --git a/t/syslog.t b/t/syslog.t
index ebc1326..90df65d 100644
--- a/t/syslog.t
+++ b/t/syslog.t
@@ -296,3 +296,17 @@ SKIP: {
ok( !$r, "setlogsock failed correctly when tcp services can't be resolved");
is( $@, '', "setlogsock didn't croak");
}
+
+BEGIN { $tests += 2 }
+SKIP: {
+ my $file = "foobar";
+ open(TST, ">$file") or skip "can't create file '$file': $!", 2;
+ close(TST);
+ eval { $r = setlogsock("stream", $file) };
+ skip "can't test openlog() failures with a missing stream", 2 if !$r;
+ unlink $file;
+ $r = eval { openlog('perl', 'ndelay', 'local0') };
+ ok( !defined $r, "openlog() failed correctly with a nonexistent stream");
+ like( $@, "/not writable/", "openlog() croaked correctly with a nonexistent stream");
+}
+
--
1.7.5.4