From 56accd5e5acc423d059109b76d8f6d92e4193286 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 13 Sep 2013 10:51:48 -0400 Subject: [PATCH] SIP Multi : avoid die in parent Don't allow a connection-level die() to affect the parent process. The parent process must be highly resilient. More logging. Signed-off-by: Bill Erickson --- SIPServer.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/SIPServer.pm b/SIPServer.pm index 05f71a2..8324ed6 100644 --- a/SIPServer.pm +++ b/SIPServer.pm @@ -216,7 +216,8 @@ sub mux_input { if (! defined($self->{service})) { syslog( "LOG_ERR", "process_request: Unrecognized server connection: %s:%s/%s", $sockaddr, $port, $proto ); - die "process_request: Bad server connection"; + syslog('LOG_ERR', "process_request: Bad server connection"); + return; } my $transport = $transports{ $self->{service}->{transport} }; @@ -226,7 +227,11 @@ sub mux_input { return; } - &$transport($self, $str_fh); + eval { &$transport($self, $str_fh) }; + if ($@) { + syslog('LOG_ERR', "ILS login error: $@"); + return; + } $active_connections{$conn_id} = { id => $conn_id, @@ -250,7 +255,10 @@ sub mux_input { $self = $active_connections{$conn_id}->{net_server}; my $pid = fork(); - die "Cannot fork: $!" unless (defined($pid) && $pid > -1); + if (!defined($pid) or $pid < 0) { + syslog('LOG_ERR', "Unable to fork new child process $!"); + return; + } if ($pid == 0) { # in kid @@ -281,7 +289,8 @@ sub mux_input { sub mux_close { my ($self, $mux, $fh) = @_; delete $active_connections{''.$fh}; - syslog("LOG_DEBUG", "multi: cleaning up child: $fh"); + syslog("LOG_DEBUG", "multi: cleaning up child: $fh; ". + scalar(keys %active_connections)." remain"); } -- 2.11.0