[Mimedefang] mimedefang.pl spilling "Use of inherited AUTOLOAD for non-method" errors

Jan-Pieter Cornet johnpc at xs4all.net
Wed Feb 16 16:41:22 EST 2011


On 2011 Feb 16, at 0:03 , Chris Hoogendyk wrote:
>> It is likely caused by the fact that the OP's syslog.h is missing a couple of constants, that are mentioned in the original errors:
>>> Feb 11 06:46:31 marlin mimedefang-multiplexor[1229]: [ID 980602 mail.info] Slave 3 stderr: Use of inherited AUTOLOAD for non-method Unix::Syslog::LOG_AUTHPRIV() is deprecated at (eval 103) line 1.
>>> ank you, Jan-Pieter!
> 
> We believe your's is the definitive response. We believe we fixed the problem by editing Unix/Syslog.pm and removing the items from EXPORT that were not defined in our environment. We believe none of those were used in mimedefang. Following is the segment showing what we changed:
[snip]

That looks fine, and is also a very good solution.

Now that you pointed out that the problem was in the existance of the tags in @EXPORT_OK and %EXPORT_TAGS, I knew where to look for the routine that triggers the bug!

The problem is triggered by sub _make_fac_map in mimedefang.pl... which is part of the _wrap_for_unix_syslog mechanism, and comes from the Log::Syslog::Abstract module... ah, that's written by Dave O'Neill, very convenient, I'm sure he's also on this list (or at least someone sitting next to him is :).

Dave (or David)... wouldn't it be better to map the facilities 'on demand'? The patch below fixes things for me. It might be slightly less efficient if your program uses a number of different facilities, but (and I haven't benchmarked this so it's speculation) it'll probably be more efficient in case you're only using one or two facilities, which will be true for the vast majority of programs.

Since I'm lacking access to a limited syslog.h :), I fabricated a test version of Unix::Syslog that has LOG_LOCAL8 in the EXPORT_OK, but that's obviously not really present (just like LOG_FTP or LOG_AUTHPRIV would be on Solaris).

One-liner test on the original distribution:
$ perl -MLog::Syslog::Abstract=openlog -we 'openlog("test","","local7")'
Use of inherited AUTOLOAD for non-method Unix::Syslog::LOG_LOCAL8() is deprecated at (eval 42) line 1.

That warning doesn't appear with the patch below applied. The only way to get the warning is to explicitly request for local8, like this:

$ perl -MLog::Syslog::Abstract=openlog,syslog -we 'openlog("test","","local8"); syslog("auth|info", "this is just a test")'
Use of inherited AUTOLOAD for non-method Unix::Syslog::LOG_LOCAL8() is deprecated at (eval 6) line 1.

(yet the test message still appears in the appropriate auth.info syslog file).

Patch is against Log::Syslog::Abstract:

$ diff -u Log-Syslog-Abstract-1.200/lib/Log/Syslog/Abstract.pm{.orig,}
--- Log-Syslog-Abstract-1.200/lib/Log/Syslog/Abstract.pm.orig	2011-01-05 21:33:07.000000000 +0100
+++ Log-Syslog-Abstract-1.200/lib/Log/Syslog/Abstract.pm	2011-02-16 22:23:12.000000000 +0100
@@ -132,13 +132,12 @@
 	{
 		my($facility) = @_;
 
-		if( ! defined $fac_map ) {
-			$fac_map = _make_fac_map();
-		}
-
 		my $num = 0;
 		foreach my $thing (split(/\|/, $facility)) {
-			if ( ! exists $fac_map->{$thing} ) {
+                        if ( ! exists $fac_map->{$thing} ) {
+                                $fac_map->{$thing} = _fac_to_num($thing);
+                        }
+			if ( ! defined $fac_map->{$thing} ) {
 				next;
 			}
 			$num |= $fac_map->{$thing};
@@ -162,31 +161,24 @@
 		LOG_FAC
 	);
 
-	sub _make_fac_map
+	sub _fac_to_num
 	{
-		my %map;
-
-		# Ugh.  Make sure we map only the available constants
-		# on this platform.  Some are not defined properly on
-		# all platforms.
-		foreach my $constant ( grep { /^LOG_/ && !exists $blacklisted{$_} } @{ $Unix::Syslog::EXPORT_TAGS{macros}} ) {
-			my $name = lc $constant;
-			$name =~ s/^log_//;
-
-			my $value = eval "Unix::Syslog::$constant()";
-			if( defined $value ) {
-				$map{$name} = $value;
-			}
-		}
-
-		# Some strings supported by Sys::Syslog don't
-		# correspond to a Unix::Syslog LOG_XXXX constant.
-		while( my($new_key, $existing_key) = each %special ) {
-			$map{$new_key} = $map{$existing_key};
-		}
+                my($fac) = @_;
 
-		return \%map;
-	}
+                $fac = $special{$fac} if exists $special{$fac};
+                my $name = uc "log_$fac";
+                return if exists $blacklisted{$name};
+
+                return if !grep { $_ eq $name }
+                          @{ $Unix::Syslog::EXPORT_TAGS{macros} };
+
+                # some constants aren't available on all platforms (like
+                # LOG_FTP on Solaris). If you ask for such a constant, you'll
+                # get a warning from the eval below (on modern perl versions).
+
+                my $value = eval "Unix::Syslog::$name()";
+                return $value;
+        }
 }
 
 1;


(just to cut legal corners (is this really necessary?): patch is now public domain, you are free to use this patch however you like).

-- 
Jan-Pieter Cornet <johnpc at xs4all.net>
Systeembeheer XS4ALL Internet bv
Internet: www.xs4all.nl
Contact: www.xs4all.nl/contact




More information about the MIMEDefang mailing list