diff options
author | Damien Chaumette <dchaumette@mandriva.com> | 2002-09-12 18:06:44 +0000 |
---|---|---|
committer | Damien Chaumette <dchaumette@mandriva.com> | 2002-09-12 18:06:44 +0000 |
commit | 642d348c347f6c9389684148395829a2b3e7f4d0 (patch) | |
tree | 93640ad4686ecf1f2e6ed913e37b87b07cc34176 | |
parent | 4c32fa0682b1703defb3b1e1a19643a263f2848e (diff) | |
download | drakx-backup-do-not-use-642d348c347f6c9389684148395829a2b3e7f4d0.tar drakx-backup-do-not-use-642d348c347f6c9389684148395829a2b3e7f4d0.tar.gz drakx-backup-do-not-use-642d348c347f6c9389684148395829a2b3e7f4d0.tar.bz2 drakx-backup-do-not-use-642d348c347f6c9389684148395829a2b3e7f4d0.tar.xz drakx-backup-do-not-use-642d348c347f6c9389684148395829a2b3e7f4d0.zip |
- patch net_monitor
-rw-r--r-- | perl-install/drakxtools.spec | 5 | ||||
-rw-r--r-- | perl-install/network/tools.pm | 52 | ||||
-rwxr-xr-x | perl-install/standalone/net_monitor | 118 |
3 files changed, 136 insertions, 39 deletions
diff --git a/perl-install/drakxtools.spec b/perl-install/drakxtools.spec index 951b18b49..158b5d5cd 100644 --- a/perl-install/drakxtools.spec +++ b/perl-install/drakxtools.spec @@ -1,7 +1,7 @@ Summary: The drakxtools (XFdrake, diskdrake, keyboarddrake, mousedrake...) Name: drakxtools Version: 1.1.9 -Release: 45mdk +Release: 46mdk Url: http://www.linux-mandrake.com/en/drakx.php3 Source0: %name-%version.tar.bz2 License: GPL @@ -288,6 +288,9 @@ file /etc/sysconfig/harddrake2/previous_hw | fgrep -q perl && %_datadir/harddrak %config(noreplace) %_sysconfdir/logrotate.d/drakxtools-http %changelog +* Thu Sep 12 2002 Damien Chaumette <dchaumette@mandrakesoft.com> 1.1.9-46mdk +- fix broken net_monitor + * Thu Sep 12 2002 Guillaume Cottenceau <gc@mandrakesoft.com> 1.1.9-45mdk - try to fix drakgw & drakfirewall thx to pixel and florin - fix drakfloppy and logdrake (tv) diff --git a/perl-install/network/tools.pm b/perl-install/network/tools.pm index 95616a82a..d68f93747 100644 --- a/perl-install/network/tools.pm +++ b/perl-install/network/tools.pm @@ -8,7 +8,7 @@ use MDK::Common::Globals "network", qw($in $prefix $disconnect_file $connect_pro use MDK::Common::System qw(getVarsFromSh); @ISA = qw(Exporter); -@EXPORT = qw(write_cnx_script write_secret_backend write_initscript ask_connect_now connect_backend disconnect_backend read_providers_backend ask_info2 type2interface connected connected_bg connected2 disconnected); +@EXPORT = qw(write_cnx_script write_secret_backend write_initscript ask_connect_now connect_backend disconnect_backend read_providers_backend ask_info2 type2interface connected connected_bg test_connected connected2 disconnected); @EXPORT_OK = qw($in); sub write_cnx_script { @@ -157,9 +157,59 @@ sub connected_bg { 1; } +# test if connected; +# cmd = 0 : ask current status +# return : 0 : not connected; 1 : connected; -1 : no test ever done; -2 : test in progress +# cmd = 1 : start new connection test +# return : -2 +# cmd = 2 : cancel current test +# return : nothing +# cmd = 3 : return current status even if a test is in progress +my $kid_pipe_connect; +my $kid_pid; +my $current_connection_status; + +sub test_connected { + local $|=1; + my ($cmd) = @_; + + if (!defined $current_connection_status) { $current_connection_status = -1; } + + if ($cmd == 0) { + if (defined $kid_pipe_connect) { + local *F; + *F = *$kid_pipe_connect; + fcntl(F, c::F_SETFL(), c::O_NONBLOCK()) or die "can't fcntl F_SETFL: $!"; + my $a; + if (defined($a = <F>)) { + close($kid_pipe_connect) || warn "kid exited $?"; + undef $kid_pipe_connect; + undef $kid_pid; + $current_connection_status = $a; + } + } + return $current_connection_status; + } + + if ($cmd == 1) { + if ($current_connection_status != -2) { + $current_connection_status = -2; + $kid_pipe_connect = connected2(); + } + } + if ($cmd == 2) { + if (defined($kid_pid)) { + kill -9, $kid_pid; + undef $kid_pid; + } + } + return $current_connection_status; +} + sub connected2 { my $pid = open(KID_TO_READ, "-|"); if ($pid) { # parent + $kid_pid = $pid; return \*KID_TO_READ; } else { # child my $a = gethostbyname("mandrakesoft.com") ? 1 : 0; diff --git a/perl-install/standalone/net_monitor b/perl-install/standalone/net_monitor index d7254ba99..c39f65198 100755 --- a/perl-install/standalone/net_monitor +++ b/perl-install/standalone/net_monitor @@ -162,27 +162,36 @@ $button_connect->add(gtkpack__(new Gtk::VBox(0,3), $statusbar->push(1, _("Wait please, testing your connection...")); $window1->show_all(); #$window1->set_policy (1, 1, 1); + my $time_tag = Gtk->timeout_add(1000, \&rescan); -my $time_tag2 = Gtk->timeout_add(20000, \&update); +$time_tag2 = Gtk->timeout_add(1000, \&update); update(); rescan(); -while ($isconnected == -1) { + +while (($isconnected == -2) || ($isconnected == -1)) { Gtk->main_iteration while Gtk->events_pending; } + +Gtk->timeout_remove($time_tag2); +$time_tag2 = Gtk->timeout_add(20000, \&update); + connection() if ($connect && !$isconnected || $disconnect && $isconnected); Gtk->main; Gtk->exit(0); my $during_connection; +my $first; + sub connection { $during_connection = 1; - my $isconnected2 = $isconnected; + my $wasconnected = $isconnected; + $button_connect->set_sensitive(0); $button_close->set_sensitive(0); $statusbar->pop(1); - $statusbar->push(1, $isconnected2 ? _("Disconnecting from Internet ") : _("Connecting to Internet ")); - if(!$isconnected2) { + $statusbar->push(1, $wasconnected ? _("Disconnecting from Internet ") : _("Connecting to Internet ")); + if($wasconnected == 1) { $c_time = time(); $ct_tag = Gtk->timeout_add(1000, sub { my ($sec,$min,$hour) = gmtime(time() - $c_time); @@ -190,36 +199,69 @@ sub connection { $label_ct->set($e); 1; }); } else { Gtk->timeout_remove($ct_tag) } my $nb_point=1; - my $tag = Gtk->timeout_add(100, sub { + $first = 1; + + my $tag = Gtk->timeout_add(1000, sub { $statusbar->pop(1); - $statusbar->push(1, ($isconnected2 ? _("Disconnecting from Internet ") : _("Connecting to Internet ")) + $statusbar->push(1, ($wasconnected == 1 ? _("Disconnecting from Internet ") : _("Connecting to Internet ")) . join('', map { "." } (1..$nb_point))); $nb_point++; - 1; - }); - my $netc = {}; - my $tag2 = Gtk->timeout_add(10000, sub { - Gtk->timeout_remove($tag); - $statusbar->pop(1); - $statusbar->push(1, $isconnected2 ? ( $isconnected ? + if ($nb_point < 4) { return 1; } + my $ret = 1; + + my $isconnect = test_connected(0); + + if ($nb_point < 20) { + if ($first == 1) { # first time + if ($isconnect == -2) { # wait for last test to finish + test_connected(2); # not yet terminated, try to cancel it + return 1; + } + test_connected(1); # initiates new connection test + $first = 0; + return 1; + } + if ($isconnect == -2) { return 1;} # no result yet, wait. + if ($isconnect == $wasconnected) { + # we got a test result; but the connection state did not change; retry. + test_connected(1); + return 1; + } + } + # either we got a result, or we timed out. + if (($isconnect != -2) or ($nb_point > 20)) { + $isconnected = $isconnect; + $ret = 0; + $statusbar->pop(1); + $statusbar->push(1, $wasconnected ? ( $isconnected ? _("Disconnection from Internet failed.") : _("Disconnection from Internet complete.")) : ( $isconnected ? _("Connection complete.") : _("Connection failed.\nVerify your configuration in the Mandrake Control Center.")) ); - my $tag3 = Gtk->timeout_add(10000, sub { - $statusbar->pop(1); - $statusbar->push(1, $isconnected ? _("Connected") : _("Not connected")); - 0; - }); - $button_connect->set_sensitive(1); - $button_close->set_sensitive(1); - undef $during_connection; - 0; - }); + my $delay = 1000; + # keep the message displayed longer if there is a problem. + if ($isconnected == $wasconnected) { $delay = 5000; } + my $tag3 = Gtk->timeout_add($delay, sub { + + $button_connect->set_sensitive(1); + $button_close->set_sensitive(1); + undef $during_connection; + update(); + return 0; + } ); + } # END IF + return $ret; } ); + + my $netc = {}; Gtk->main_iteration while Gtk->events_pending; - $tag2 = Gtk->timeout_add(1000, sub { system( $isconnected2 ? "/etc/sysconfig/network-scripts/net_cnx_down &" : "/etc/sysconfig/network-scripts/net_cnx_up &"); 0; }); + + if ($wasconnected == 1) { + system("/etc/sysconfig/network-scripts/net_cnx_down &"); + } else { + system("/etc/sysconfig/network-scripts/net_cnx_up &"); + } } sub rescan { @@ -322,8 +364,15 @@ sub change_color { my $scale; sub update { - connected_bg(\$isconnected); - my @intfs = get_val(); + if (!$during_connection) { + my $isconnect = test_connected(0); + if ($isconnect != -2) { + $isconnected = $isconnect; # save current state + $isconnect = test_connected(1); # start new test + } + }; + + my @intfs = get_val(); # get values from /proc file system if($combo1->entry->get_text ne ($netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default")) { $combo1->entry->set_text($netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default"); } @@ -414,25 +463,20 @@ sub update { } @interfaces = @intfs; my $netc={}; - my $tmp; - connected_bg(\$tmp); - if(defined $tmp) { - $isconnected = $tmp; - if ($isconnected != -1 && !$during_connection) { - if($isconnected && !in_ifconfig($netcnx->{NET_INTERFACE})) { + if ($isconnected != -2 && $isconnected != -1 && !$during_connection) { + if(($isconnected == 1) && !in_ifconfig($netcnx->{NET_INTERFACE})) { $isconnected=0; $statusbar->pop(1); $statusbar->push(1, _("Warning, another internet connexion has been detected, maybe using your network")); } else { #- translators : $netcnx->{type} is the type of network connection (modem, adsl...) $statusbar->pop(1); - $statusbar->push(1, $isconnected ? _("Connected") : _("Not connected")); + $statusbar->push(1, $isconnected == 1 ? _("Connected") : _("Not connected")); } - $label_c->set($isconnected ? _("Disconnect %s", $netcnx->{type}) : _("Connect %s", $netcnx->{type})); - $isconnected ? $pix_c->set($pix_c_map, $pix_c_mask) : $pix_c->set($pix_d_map, $pix_d_mask); + $label_c->set($isconnected == 1 ? _("Disconnect %s", $netcnx->{type}) : _("Connect %s", $netcnx->{type})); + $isconnected == 1 ? $pix_c->set($pix_c_map, $pix_c_mask) : $pix_c->set($pix_d_map, $pix_d_mask); $button_connect->set_sensitive(1); } - } if (!(-e $connect_file && -e $disconnect_file)) { $button_connect->set_sensitive(0); $label_c->set("No internet connection configured"); |