At 11:38 AM 8/29/02 +0200, you ([EMAIL PROTECTED]) wrote:
>
>I'm interrested :o)
>
All right, I have attached the stuff I have tried.
First net_monitor and tools.pm; these patches go together.
Comment : I have changed code a bit :-). My feeling is that
the connected_bg routine, although elegant, is not precise
enough to achieve a good control of what is going on. The
problem is that the background process restart automatically
and it's difficult to control what it's doing with a timer-run
task. I don't have time enough to solve the problem with
connected_bg, sorry.
Second drakconnect and adsl.pm; here is where I have tried to
make the expert mode, with only partial success :-/
The big problem is that the device used for net connection is
not saved anywhere, to the best of my limited knowledge.
I would have liked to save it in drakconnect.conf, entry
ADSLModem, but :
ADSLModem= # Obsolete information. Please don't use it
Argh. Why?
So I have used gateway device instead; it's not correct but it's
the best I found available for a quick hack.
There is also a huge problem because I have changed only
for the adsl pppoe case, the only one I can test...That's because I'm
not sure where the real writing of the net_cnx_up file (and friends)
should occur.
I'm hoping for a bit of comment and advice here.
Thanks,
Gerard
--- drakconnect.orig 2002-08-23 21:57:10.000000000 +0200
+++ temp/drakconnect 2002-08-28 22:23:27.000000000 +0200
@@ -604,6 +604,10 @@
my $vbox2 = new Gtk::VBox(0,0);
$frame1->add($vbox2);
my $i = 0;
+ my @all_ether = [];
+ foreach my $i (0..$#all_cards) { @all_ether[0]->[$i] = @all_cards[$i]->[0]; };
+ # bugged, but NET_DEVICE is not saved anywhere.
+ if ($netc->{NET_DEVICE} == "") { $netc->{NET_DEVICE} = $netc->{GATEWAYDEV} };
my @conf_data = ([_("Card IRQ"), \$cnx->{irq} ],
[_("Card mem (DMA)"), \$cnx->{mem} ],
[_("Card IO"), \$cnx->{io} ],
@@ -626,7 +630,7 @@
[_("Domain name"), \$cnx->{domain} ],
[_("First DNS Server (optional)"), \$cnx->{dns1} ],
[_("Second DNS Server (optional)"), \$cnx->{dns2} ],
- [_("Ethernet Card"), \$netc->{NET_DEVICE}, [ 'eth0', 'eth1',
'eth2', 'eth3', 'eth4', 'eth5','eth6', 'eth7', 'eth8', 'eth9' ]],
+ [_("Ethernet Card"), \$netc->{NET_DEVICE}, @all_ether],
[_("DHCP Client"), \$netcnx->{dhcp_client}, ["dhcpcd", "dhcpxd",
"dhcp-client"] ],
[_("Connection speed"), \$cnx->{speed}, ["64 Kb/s", "128 Kb/s"]],
[_("Connection timeout (in sec)"), \$cnx->{huptimeout} ]
--- net_monitor.real.orig 2002-08-23 21:57:10.000000000 +0200
+++ net_monitor.real 2002-08-29 18:59:56.000000000 +0200
@@ -162,27 +162,36 @@
$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 @@
$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 @@
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 @@
}
@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");
--- tools.pm.orig 2002-08-23 21:57:10.000000000 +0200
+++ tools.pm 2002-08-29 19:19:08.000000000 +0200
@@ -8,7 +8,7 @@
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 @@
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;
--- adsl.pm.orig 2002-08-23 21:57:10.000000000 +0200
+++ adsl.pm 2002-08-29 19:06:27.000000000 +0200
@@ -193,7 +193,13 @@
",
'/usr/sbin/adsl-stop
/usr/bin/killall pppoe pppd
-', $netc->{adsltype}) } elsif ($adsl_type eq 'speedtouch') {
+', $netc->{adsltype});
+if ($netc->{NET_DEVICE} ne '') {
+ $netc->{internet_cnx_choice}="adsl";
+ write_cnx_script($netc);
+ }
+}
+elsif ($adsl_type eq 'speedtouch') {
write_cnx_script($netc, 'adsl',
'/sbin/route del default
/usr/share/speedtouch/speedtouch.sh start