From ca912dd7da426f083100096a009ef5064479d45b Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Wed, 20 Apr 2011 01:37:06 -0400 Subject: [PATCH] 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. --- Crypt/Monkeysphere/MSVA.pm | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) 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); } -- 2.26.2