summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+config@madore.org>2010-02-16 17:46:19 +0100
committerDavid A. Madore <david+config@madore.org>2010-02-16 17:46:19 +0100
commit8eeeb14f4284e2ee1fa040ae0209a6c02432005d (patch)
treeea69809085ef33b20e8197a274f2764cf1227a03
parentfb276c9a2c882505aa635926f36c9e6e9330ba9a (diff)
downloademergency-8eeeb14f4284e2ee1fa040ae0209a6c02432005d.tar.gz
emergency-8eeeb14f4284e2ee1fa040ae0209a6c02432005d.tar.bz2
emergency-8eeeb14f4284e2ee1fa040ae0209a6c02432005d.zip
Check recv() return value.
-rwxr-xr-xemergencyc.pl7
-rwxr-xr-xemergencyd.pl1
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] // "";