From 8eeeb14f4284e2ee1fa040ae0209a6c02432005d Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Tue, 16 Feb 2010 17:46:19 +0100 Subject: Check recv() return value. --- emergencyc.pl | 7 +++++-- emergencyd.pl | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/emergencyc.pl b/emergencyc.pl index 86c9da7..5d59be1 100755 --- a/emergencyc.pl +++ b/emergencyc.pl @@ -77,10 +77,13 @@ eval { alarm 5; do { $sender = recv($socket, $buf, 16384, 0); - } while ( $sender ne $haddr ); + } while ( defined($sender) && $sender ne $haddr ); }; if ( $@ ) { - printf "timeout\n"; + print "timeout\n"; + exit 1; +} elsif ( !defined($sender) ) { + die "Failed to receive packet: $!"; } else { printf "%s", $buf; } diff --git a/emergencyd.pl b/emergencyd.pl index f2fed7a..47c39e4 100755 --- a/emergencyd.pl +++ b/emergencyd.pl @@ -131,6 +131,7 @@ PACKET: while (1) { my $buf; my $sender = recv($socket, $buf, 16384, 0); + die "Failed to receive packet: $!" unless defined($sender); my @lines = split /\015*\012|\|/s, $buf; my $command = $lines[0] // ""; my $timestamp = $lines[1] // ""; -- cgit v1.2.3