Skip to contentSkip to conversation

DhcpWatch::leases: Check errors

PATCH In review Ian Jackson 2 participants 3 messages Oct 31, 2014 – Nov 4, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DhcpWatch::leases: Check errors

Check error returns from connect() et al (which present as an undef return from IO::Socket::INET), and from read() (which can be detected via IO::Handle::error).

---
 Osstest/DhcpWatch/leases.pm |    4 ++++
 1 file changed, 4 insertions(+)
Osstest/DhcpWatch/leases.pm +4 -0
index 6f142e7..9a74c40 100644
@@ -58,6 +58,7 @@ sub check_ip ($$) {
 	if (!defined $leases) { return "open $leasesfn: $!"; }
     } else {
 	$leases= new IO::Socket::INET(PeerAddr => $leasesfn);
+	if (!defined $leases) { return "connect to $leasesfn: $!"; }
     }
 
     my $lstash= "dhcpleases-$gho->{Guest}";
@@ -163,6 +164,9 @@ sub check_ip ($$) {
 
     if (!$best) {
         $saveas->("$lstash.nolease", 3);
+	if ($leases->error) {
+	    return "error reading $leasesfn";
+	}
         return "no active lease";
     }
     $gho->{Ip}= $best->{' addr'};
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Ian Jackson

Check error returns from connect() et al (which present as an undef return from IO::Socket::INET), and from read() (which can be detected via IO::Handle::error).

Looks like you have a mixture of tabs and spaces in the second hunk, but otherwise:

Quoted 26 lines
---
 Osstest/DhcpWatch/leases.pm |    4 ++++
 1 file changed, 4 insertions(+)
Osstest/DhcpWatch/leases.pm +4 -0
index 6f142e7..9a74c40 100644
@@ -58,6 +58,7 @@ sub check_ip ($$) {
 	if (!defined $leases) { return "open $leasesfn: $!"; }
     } else {
 	$leases= new IO::Socket::INET(PeerAddr => $leasesfn);
+	if (!defined $leases) { return "connect to $leasesfn: $!"; }
     }
 
     my $lstash= "dhcpleases-$gho->{Guest}";
@@ -163,6 +164,9 @@ sub check_ip ($$) {
 
     if (!$best) {
         $saveas->("$lstash.nolease", 3);
+	if ($leases->error) {
+	    return "error reading $leasesfn";
+	}
         return "no active lease";
     }
     $gho->{Ip}= $best->{' addr'};
#2 lore raw

Ian Campbell writes ("Re: [OSSTEST PATCH] DhcpWatch::leases: Check errors"):

Quoted 8 lines · Ian Jackson
Quoted 3 lines

Check error returns from connect() et al (which present as an undef return from IO::Socket::INET), and from read() (which can be detected via IO::Handle::error).

Looks like you have a mixture of tabs and spaces in the second hunk, but otherwise:

osstest is full of a mixture of tabs and spaces. It's not the kind of thing I think is worth caring about.

Ian.