From: Sebastian Harl Date: Thu, 19 Feb 2009 10:04:49 +0000 (+0100) Subject: contrib/cussh.pl: Improved error reporting. X-Git-Tag: collectd-4.5.3~3 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2b17fd929a6d6a3146cd57183f96a94c49dfc035;p=collectd.git contrib/cussh.pl: Improved error reporting. --- diff --git a/contrib/cussh.pl b/contrib/cussh.pl index ee4c8939..47c72c33 100755 --- a/contrib/cussh.pl +++ b/contrib/cussh.pl @@ -182,13 +182,20 @@ sub putval { my $id = getid(\$line); + my $ret; + if (! $id) { - print STDERR $sock->{'error'} . $/; + print STDERR "Invalid id \"$line\"." . $/; return; } my ($time, @values) = split m/:/, $line; - return $sock->putval(%$id, time => $time, values => \@values); + $ret = $sock->putval(%$id, time => $time, values => \@values); + + if (! $ret) { + print STDERR "socket error: " . $sock->{'error'} . $/; + } + return $ret; } =item B I I @@ -202,14 +209,14 @@ sub getval { my $id = getid(\$line); if (! $id) { - print STDERR $sock->{'error'} . $/; + print STDERR "Invalid id \"$line\"." . $/; return; } my $vals = $sock->getval(%$id); if (! $vals) { - print STDERR $sock->{'error'} . $/; + print STDERR "socket error: " . $sock->{'error'} . $/; return; } @@ -264,10 +271,9 @@ sub flush { } if (! $res) { - print STDERR $sock->{'error'} . $/; - return; + print STDERR "socket error: " . $sock->{'error'} . $/; } - return 1; + return $res; } =item B @@ -282,7 +288,7 @@ sub listval { @res = $sock->listval(); if (! @res) { - print STDERR $sock->{'error'} . $/; + print STDERR "socket error: " . $sock->{'error'} . $/; return; } @@ -300,6 +306,8 @@ sub putnotif { my $sock = shift || return; my $line = shift || return; + my $ret; + my (%values) = (); foreach my $i (split m/ /, $line) { my($key,$val) = split m/=/, $i, 2; @@ -311,8 +319,12 @@ sub putnotif { } } $values{'time'} ||= time(); - my(@tmp) = %values; - return $sock->putnotif(%values); + + $ret = $sock->putnotif(%values); + if (! $ret) { + print STDERR "socket error: " . $sock->{'error'} . $/; + } + return $ret; } =back