Subject: | Clamd fails to return errors in a meaningful way |
Hi,
I noticed while using the Clamd application in one of my scripts that it either warns or dies on error, and there is no meaningful way of returning error messages from the Clamd module it self. The solution is to provide an error handler routine which can collect and return the error message it self.
Commonly this error handler routine is known as: errstr() - which is the name I've chosen to use.
I've attached a patch which adds this functionality to the Clamd.pm library, Nothing else has been modified.
--- Clamd-1.04/lib/Clamd.pm Thu Nov 21 07:51:45 2002
+++ Clamd-1.05/lib/Clamd.pm Sun Jun 13 14:07:34 2004
@@ -6,7 +6,7 @@
use File::Find qw(find);
use IO::Socket;
-$VERSION = '1.04';
+$VERSION = '1.05';
=head1 NAME
@@ -219,14 +219,21 @@
while (my $result = $conn->getline) {
chomp($result);
- if ($result !~ /^(.*): (.*)(ERROR|FOUND|OK)$/ and $options->{ShowWarnings}) {
- warn("Unrecognised line from clamd: $result\n");
+ if ($result !~ /^(.*): (.*)(ERROR|FOUND|OK)$/){
+ if($options->{ShowWarnings}){
+ warn("Unrecognised line from clamd: $result\n");
+ } else {
+ $self->errstr("Unrecognised line from clamd: $result");
+ return;
+ }
}
my ($filename, $desc, $type) = ($1, $2, $3);
if ($type eq 'ERROR' and $options->{RaiseError}) {
die("Error processing $filename: $desc");
- }
- elsif ($type eq 'FOUND') {
+ } elsif($type eq 'ERROR'){
+ $self->errstr("Error professing $filename: $desc");
+ return;
+ } elsif ($type eq 'FOUND') {
push @results, $filename, $desc;
}
}
@@ -273,6 +280,18 @@
1 while (<$conn>);
$conn->close;
return 1;
+}
+
+=head2 errstr()
+
+Return the last error message.
+
+=cut
+
+sub errstr {
+ my ($self, $err) = @_;
+ $self->{'.errstr'} = $err if $err;
+ return $self->{'.errstr'};
}
sub _get_connection {