From 6e858487b4db7054748d3d82830249bb134265b4 Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Thu, 22 Dec 2011 22:42:15 +0000 Subject: [PATCH] fix console.pl so it ends gracefully --- cmd/bye.pl | 2 +- perl/Msg.pm | 7 +++++++ perl/Version.pm | 4 ++-- perl/console.pl | 29 +++++++++++++++++++++-------- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/cmd/bye.pl b/cmd/bye.pl index 4d8a8754..ec04f056 100644 --- a/cmd/bye.pl +++ b/cmd/bye.pl @@ -13,7 +13,7 @@ if ($self->is_user && -e "$main::data/logout") { my @in = ; close(I); $self->send_now('D', @in); - Msg->sleep(1); +# Msg->sleep(1); } #$self->send_now('Z', ""); diff --git a/perl/Msg.pm b/perl/Msg.pm index 4bc31fad..dcc3c812 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -61,6 +61,13 @@ sub set_error $conn->{eproc} = $callback; } +sub set_eof +{ + my $conn = shift; + my $callback = shift; + $conn->{sock}->on_eof(sub {$callback}); +} + sub set_rproc { my $conn = shift; diff --git a/perl/Version.pm b/perl/Version.pm index 580ef44f..8c84cfc1 100644 --- a/perl/Version.pm +++ b/perl/Version.pm @@ -11,7 +11,7 @@ use vars qw($version $subversion $build $gitversion); $version = '1.56'; $subversion = '0'; -$build = '2'; -$gitversion = '38aa5af'; +$build = '3'; +$gitversion = 'bbc51ff'; 1; diff --git a/perl/console.pl b/perl/console.pl index a25e1533..4ba23d43 100755 --- a/perl/console.pl +++ b/perl/console.pl @@ -71,6 +71,7 @@ my @time = (); my $lastmin = 0; my $sigint; my $sigterm; +my $decease; #$SIG{WINCH} = sub {@time = gettimeofday}; @@ -140,13 +141,23 @@ sub do_resize show_screen(); } +my $ceasing = 0; + # cease communications sub cease { my $sendz = shift; + + print "ceasing ($ceasing)\r\n"; + + return if $ceasing; + ++$ceasing; + $conn->disconnect if $conn; - endwin(); dbgclose(); + endwin(); + $decease->send; + print @_ if @_; exit(0); } @@ -505,6 +516,9 @@ if ($call eq $main::mycall) { exit(0); } +# create end condvar +$decease = AnyEvent->condvar; + dbginit(); $conn = IntMsg->connect("$main::clusteraddr", $main::clusterport, \&rec_socket); @@ -521,22 +535,22 @@ if (! $conn) { exit(0); } -# create end condvar -my $decease = AnyEvent->condvar; - -$conn->set_error(sub{cease(0)}); unless ($DB::VERSION) { $sigint = AnyEvent->signal(signal=>'INT', cb=> sub{$decease->send}); $sigterm = AnyEvent->signal(signal=>'TERM', cb=> sub{$decease->send}); } -$SIG{'HUP'} = \&sig_term; +#$SIG{'HUP'} = \&sig_term; +my $sighup = AnyEvent->signal(signal=>'HUP', cb=> sub{$decease->send}); +$conn->{sock}->on_eof(sub{$decease->send}); +$conn->{sock}->on_error(sub{$decease->send}); # start up do_resize(); -$SIG{__DIE__} = \&sig_term; +#$SIG{__DIE__} = \&sig_term; +#my $sigdie = AnyEvent->signal(signal=>'__DIE__', cb=> sub{$decease->send}); $conn->send_later("A$call|$connsort width=$cols"); $conn->send_later("I$call|set/page $maxshist"); @@ -551,4 +565,3 @@ my $event_loop = AnyEvent->timer(after => 0, interval => 0.010, cb => sub{idle_ $decease->recv; cease(0); -exit(0); -- 2.43.0