[interchange] Avoid eval in Sys::Syslog::xlate() by using cached constants where possible
Jon Jensen
interchange-cvs at icdevgroup.org
Sat Dec 12 16:30:08 UTC 2009
commit 19bc13c7fb103cab7eb2e2ac75149ab24efb4ad8
Author: Jon Jensen <jon at endpoint.com>
Date: Sat Dec 12 09:26:35 2009 -0700
Avoid eval in Sys::Syslog::xlate() by using cached constants where possible
This hack works around a bizarre problem in some versions of Sys::Syslog.
I believe the bug this works around may no longer exist in the latest
versions of Sys::Syslog shipped with Perl 5.10.1 and later, which use
ExtUtils::Constant.
lib/Vend/Util.pm | 52 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/lib/Vend/Util.pm b/lib/Vend/Util.pm
index cf1eb9e..0cf538c 100644
--- a/lib/Vend/Util.pm
+++ b/lib/Vend/Util.pm
@@ -1715,6 +1715,44 @@ sub show_times {
logDebug("$message: " . join " ", @times);
}
+# This %syslog_constant_map is an attempt to work around a strange problem
+# where the eval inside &Sys::Syslog::xlate fails, which then croaks.
+# The cause of this freakish problem is still to be determined.
+
+my %syslog_constant_map;
+
+sub setup_syslog_constant_map {
+ for (
+ (map { "local$_" } (0..7)),
+ qw(
+ auth
+ authpriv
+ cron
+ daemon
+ ftp
+ kern
+ lpr
+ mail
+ news
+ syslog
+ user
+ uucp
+
+ emerg
+ alert
+ crit
+ err
+ warning
+ notice
+ info
+ debug
+ )
+ ) {
+ $syslog_constant_map{$_} = Sys::Syslog::xlate($_);
+ }
+ return;
+}
+
sub logGlobal {
return 1 if $Vend::ExternalProgram;
@@ -1784,6 +1822,7 @@ sub logGlobal {
print "to report this error:\n", $msg;
exit 1;
}
+ setup_syslog_constant_map() unless %syslog_constant_map;
$Vend::SysLogReady = 1;
}
}
@@ -1827,10 +1866,15 @@ sub logGlobal {
}
elsif ($Vend::SysLogReady) {
- # Do not call this from within an eval, because in some strange circumstances
- # it will cause the eval inside &Sys::Syslog::xlate to fail, which then croaks.
- # The cause of this freakish problem is still to be determined.
- Sys::Syslog::syslog "$level|$facility", $msg;
+ eval {
+ # avoid eval in Sys::Syslog::xlate() by using cached constants where possible
+ my $level_mapped = $syslog_constant_map{$level};
+ $level_mapped = $level unless defined $level_mapped;
+ my $facility_mapped = $syslog_constant_map{$facility};
+ $facility_mapped = $facility unless defined $facility_mapped;
+ my $priority = "$level_mapped|$facility_mapped";
+ Sys::Syslog::syslog $priority, $msg;
+ };
}
return 1;
More information about the interchange-cvs
mailing list