fix console.pl so it ends gracefully
authorDirk Koopman <djk@tobit.co.uk>
Thu, 22 Dec 2011 22:42:15 +0000 (22:42 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Thu, 22 Dec 2011 22:42:15 +0000 (22:42 +0000)
cmd/bye.pl
perl/Msg.pm
perl/Version.pm
perl/console.pl

index 4d8a8754d23f04e3de0516148893339645cf546d..ec04f0566e49ea92390e9a5876846ae55117687a 100644 (file)
@@ -13,7 +13,7 @@ if ($self->is_user && -e "$main::data/logout") {
        my @in = <I>;
        close(I);
        $self->send_now('D', @in);
-       Msg->sleep(1);
+#      Msg->sleep(1);
 }
 
 #$self->send_now('Z', "");
index 4bc31faddfcf92546427549c4a0f81d5e39f45c8..dcc3c812d1ac77763c3e41bd47439a17a4589885 100644 (file)
@@ -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;
index 580ef44fd62d3a807f256884b15a5dd143a447cc..8c84cfc191670c449f61e8e212bd478eec98e61a 100644 (file)
@@ -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;
index a25e1533a806469186e7d5d450eaac756efc2170..4ba23d43502e7aefe0de3fe0abb65b3fa9d0aa60 100755 (executable)
@@ -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);