Author: sparky
Date: Tue Dec  7 21:56:14 2010
New Revision: 11974

Modified:
   toys/rsget.pl/RSGet/Dispatch.pm
   toys/rsget.pl/RSGet/Line.pm
   toys/rsget.pl/RSGet/Main.pm
Log:
- implemented "soft stop" for SIGINT, send twice to terminate immediatelly


Modified: toys/rsget.pl/RSGet/Dispatch.pm
==============================================================================
--- toys/rsget.pl/RSGet/Dispatch.pm     (original)
+++ toys/rsget.pl/RSGet/Dispatch.pm     Tue Dec  7 21:56:14 2010
@@ -29,7 +29,7 @@
 our %downloading;
 our %checking;
 
-my $soft_restart = 0;
+my $soft_stop = 0;
 
 my %working = (
        get => \%downloading,
@@ -259,14 +259,19 @@
                'checking URIs' => scalar keys %checking,
        );
 
-       if ( $soft_restart ) {
+       if ( $soft_stop ) {
                foreach my $obj ( values %downloading ) {
                        unless ( $obj->{started_download} ) {
                                $obj->{_abort} = "Soft restart";
                        }
                }
-               RSGet::Main::restart()
-                       unless $downloading_num;
+               unless ( $downloading_num ) {
+                       if ( $soft_stop == 2 ) {
+                               RSGet::Main::restart()
+                       } else {
+                               RSGet::Main::stop()
+                       }
+               }
                return 1;
        }
 
@@ -309,10 +314,10 @@
 
 sub soft_restart
 {
-       if ( $soft_restart ) {
+       if ( $soft_stop == 2 ) {
                RSGet::Main::restart();
        } else {
-               $soft_restart = 1;
+               $soft_stop = 2;
                new RSGet::Line( "NOTICE: ", "rsget.pl will restart after 
finishing all current downloads" );
                new RSGet::Line( "NOTICE: ", "send SIGUSR2 again to restart 
now" );
                RSGet::FileList::update();
@@ -321,6 +326,20 @@
 
 $SIG{USR2} = \&soft_restart;
 
+sub soft_stop
+{
+       if ( $soft_stop == 1 ) {
+               RSGet::Main::stop();
+       } else {
+               $soft_stop = 1;
+               new RSGet::Line( "NOTICE: ", "rsget.pl will terminate after 
finishing all current downloads" );
+               new RSGet::Line( "NOTICE: ", "send SIGINT again to terminate 
now" );
+               RSGet::FileList::update();
+       }
+}
+
+$SIG{INT} = \&soft_stop;
+
 sub abort_missing
 {
        my $all = shift;

Modified: toys/rsget.pl/RSGet/Line.pm
==============================================================================
--- toys/rsget.pl/RSGet/Line.pm (original)
+++ toys/rsget.pl/RSGet/Line.pm Tue Dec  7 21:56:14 2010
@@ -233,12 +233,6 @@
 
        return if $nooutput;
 
-       $SIG{INT} = sub {
-               print_all_lines();
-               print "\nTERMINATED\n";
-               exit 0;
-       };
-
        $SIG{WINCH} = sub {
                print "\033[2J\033[1;1H\n";
                term_size();
@@ -250,8 +244,7 @@
 
        $SIG{__DIE__} = sub {
                print_all_lines();
-               print "\n";
-               print "DIED: ", shift, "\n\n";
+               print "\n\nDIED: ", shift, "\n\n";
                exit 1;
        };
 }

Modified: toys/rsget.pl/RSGet/Main.pm
==============================================================================
--- toys/rsget.pl/RSGet/Main.pm (original)
+++ toys/rsget.pl/RSGet/Main.pm Tue Dec  7 21:56:14 2010
@@ -178,6 +178,14 @@
        exit 0;
 }
 
+sub stop
+{
+       $restart = 0;
+       RSGet::Line::print_all_lines();
+       printf "\n\nTerminating at %s\n\n", scalar localtime;
+       exit 0;
+}
+
 END {
        if ( $restart ) {
                exec $0, @$argv;
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to