From: Stephen L Johnson Date: Fri, 18 Feb 2000 20:38:04 +0000 (+0000) Subject: added alarm block around client connection code in listen_for_updates() X-Git-Tag: spong-2_6e~1 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b09ff3fbb8e5e4b8f504e4062615ab33712c786;p=spong.git added alarm block around client connection code in listen_for_updates() --- diff --git a/src/spong-server.pl b/src/spong-server.pl index 205a610..153e017 100755 --- a/src/spong-server.pl +++ b/src/spong-server.pl @@ -69,6 +69,7 @@ foreach $host ( Spong::HostList->new( "all" )->hosts() ) { # additional subprocesses, they just deal with the message setting at their # queue, and then process the next message as it comes in. +$SIG{'ALRM'} = 'IGNORE'; $SIG{'CHLD'} = \&chld_handler; if( $upd_pid = fork() ) { @@ -124,14 +125,31 @@ sub listen_for_updates { # Read all from the client, and disconnect, we process the message next. - my $header = ; chomp $header; + my( $header, $ok ) = ( "", 0 ); my( $message, $cnt, $line ) = ( "", "", "" ); - while( defined( $line = ) ) { - last if ($cnt += length($line)) > 100000; - $message .= $line; - } + + # Set an alarm on this block in case the client runs into problems + eval + { + local $SIG{'ALRM'} = sub { die; }; + alarm($SPONG_SERVER_ALARM) if $SPONG_SERVER_ALARM; + + $header = ; chomp $header; + while( defined( $line = ) ) { + last if ($cnt += length($line)) > 100000; + $message .= $line; + } + + $ok = 1; + }; + alarm(0); close( CLIENT ); + if ( ! $ok ) { + &error( "ss_update: Connection from $paddr timed out" ); + next; + } + # Now depending on what kind of message it is, pass it off to a routine # that can process the message. Currently valid messages are "status", # "ack", "config", and "stat".