Ticket #118 (closed defect: fixed)
RRDp.pm does not return when error_mode is 'catch' and an error occurs
| Reported by: | human | Owned by: | oetiker |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | misc | Version: | 1.3dev |
| Keywords: | Cc: | bernard@… |
Description
There is a problem in source:trunk/program/bindings/perl-piped/RRDp.pm when the error_mode is set to catch and an error occurs.
Since the behaviour of rrdtool in pipe mode describes the result of a command being one of two things
- OK followed by the timings
- ERROR followed by a relevant string
the RRDp needs to take into account that the read sequence is complete in either case.
Unfortunately the ERROR case returns to the read loop rather than returning. A simple
return undef;
within the ERROR block should suffice, though I am not sure whether the timing variables should also be unset to avoid inappropriate use.



Try this:
--- RRDp.pm (revision 1199) +++ RRDp.pm (working copy) @@ -163,11 +163,14 @@ $RRDp::error = undef; if ($line =~ m|^ERROR|) { $RRDp::error_mode eq 'catch' ? $RRDp::error = $line : croak $line; - $ERR = 1; + $RRDp::sys = undef; + $RRDp::user = undef; + $RRDp::real = undef; + return undef; } - elsif ($line =~ m|^OK u:([\d\.]+) s:([\d\.]+) r:([\d\.]+)|){ + elsif ($line =~ m|^OK(?: u:([\d\.]+) s:([\d\.]+) r:([\d\.]+))?|){ ($RRDp::sys,$RRDp::user,$RRDp::real)=($1,$2,$3); - return $ERR == 1 ? undef : \$buffer; + return \$buffer; } else { $buffer .= $line. "\n"; }