diff options
author | David A. Madore <david+config@madore.org> | 2010-02-16 17:46:19 +0100 |
---|---|---|
committer | David A. Madore <david+config@madore.org> | 2010-02-16 17:46:19 +0100 |
commit | 8eeeb14f4284e2ee1fa040ae0209a6c02432005d (patch) | |
tree | ea69809085ef33b20e8197a274f2764cf1227a03 | |
parent | fb276c9a2c882505aa635926f36c9e6e9330ba9a (diff) | |
download | emergency-8eeeb14f4284e2ee1fa040ae0209a6c02432005d.tar.gz emergency-8eeeb14f4284e2ee1fa040ae0209a6c02432005d.tar.bz2 emergency-8eeeb14f4284e2ee1fa040ae0209a6c02432005d.zip |
Check recv() return value.
-rwxr-xr-x | emergencyc.pl | 7 | ||||
-rwxr-xr-x | 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] // ""; |