From: Daniel Kahn Gillmor Date: Wed, 20 Apr 2011 05:37:06 +0000 (-0400) Subject: Handle server restarts (SIGHUP) cleanly even with Net::Server 0.99 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ca912dd7da426f083100096a009ef5064479d45b;p=monkeysphere-validation-agent.git Handle server restarts (SIGHUP) cleanly even with Net::Server 0.99 With Net::Server 0.97, the old code was working. With Net::Server 0.99, @{ $server->{server}->{sock} }[0]->sockport() was returning undef() after a HUP. The simple solution is that we don't try to re-set the port at all after a SIGHUP. --- diff --git a/Crypt/Monkeysphere/MSVA.pm b/Crypt/Monkeysphere/MSVA.pm index 6442fbb..fd3540b 100755 --- a/Crypt/Monkeysphere/MSVA.pm +++ b/Crypt/Monkeysphere/MSVA.pm @@ -764,18 +764,20 @@ $server->set_exit_status(10); $server->server_close(); } - my $port = @{ $server->{server}->{sock} }[0]->sockport(); - if ((! defined $port) || ($port < 1) || ($port >= 65536)) { - msvalog('error', "got nonsense port: %d.\n", $port); - $server->set_exit_status(11); - $server->server_close(); - } - if ((exists $ENV{MSVA_PORT}) && (($ENV{MSVA_PORT} + 0) != $port)) { - msvalog('error', "Explicitly requested port %d, but got port: %d.", ($ENV{MSVA_PORT}+0), $port); - $server->set_exit_status(13); - $server->server_close(); + if (!defined($self->port) || $self->port == 0) { + my $port = @{ $server->{server}->{sock} }[0]->sockport(); + if ((! defined($port)) || ($port < 1) || ($port >= 65536)) { + msvalog('error', "got nonsense port: %d.\n", $port); + $server->set_exit_status(11); + $server->server_close(); + } + if ((exists $ENV{MSVA_PORT}) && (($ENV{MSVA_PORT} + 0) != $port)) { + msvalog('error', "Explicitly requested port %d, but got port: %d.", ($ENV{MSVA_PORT}+0), $port); + $server->set_exit_status(13); + $server->server_close(); + } + $self->port($port); } - $self->port($port); $self->{updatemonitor} = Crypt::Monkeysphere::MSVA::Monitor::->new($logger); }