Subject: | Handle getprotobyn{ame,umber} not being available |
On Perls built without those functions (either because the system lacks them, ala Android, or because they were undefined during Configure), calling these results in an exception, so they should either be protected by an eval {} or only called as 'if ($Config{func}) { func() }'.
The attached patch implements the latter.
diff --git a/cpan/Sys-Syslog/Syslog.pm b/cpan/Sys-Syslog/Syslog.pm
index 75a1832..dbceb13 100644
--- a/cpan/Sys-Syslog/Syslog.pm
+++ b/cpan/Sys-Syslog/Syslog.pm
@@ -3,6 +3,7 @@ use strict;
use warnings;
use warnings::register;
use Carp;
+use Config;
use Exporter qw< import >;
use File::Basename;
use POSIX qw< strftime setlocale LC_TIME >;
@@ -11,7 +12,7 @@ require 5.005;
{ no strict 'vars';
- $VERSION = '0.33';
+ $VERSION = '0.33_1';
%EXPORT_TAGS = (
standard => [qw(openlog syslog closelog setlogmask)],
@@ -429,7 +430,6 @@ sub syslog {
$buf = $message;
}
else {
- require Config;
my $whoami = $ident;
$whoami .= "[$$]" if $options{pid};
@@ -628,7 +628,10 @@ sub connect_log {
sub connect_tcp {
my ($errs) = @_;
- my $proto = getprotobyname('tcp');
+ my $proto;
+ if ( $Config{d_getpbyname} ) {
+ $proto = getprotobyname('tcp');
+ }
if (!defined $proto) {
push @$errs, "getprotobyname failed for tcp";
return 0;
@@ -676,7 +679,10 @@ sub connect_tcp {
sub connect_udp {
my ($errs) = @_;
- my $proto = getprotobyname('udp');
+ my $proto;
+ if ( $Config{d_getpbyname} ) {
+ $proto = getprotobyname('udp');
+ }
if (!defined $proto) {
push @$errs, "getprotobyname failed for udp";
return 0;