From bae95355d7b8a2dfe606823feecd58ad793d0560 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Wed, 11 Feb 2009 20:55:02 -0500 Subject: [PATCH 1/3] Make sure it's possible to stop a dhcp client that's in the process of getting a lease. Have gui.py trigger connection status updates every .5 seconds if in a connecting state. Fix typo in wicd-client.py --- wicd/gui.py | 17 ++++++++++++----- wicd/misc.py | 4 +++- wicd/networking.py | 16 ++++++++++++++-- wicd/wicd-client.py | 2 +- wicd/wicd-daemon.py | 3 +++ wicd/wnettools.py | 3 ++- 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/wicd/gui.py b/wicd/gui.py index f5a0cbd..72fbe75 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -390,23 +390,29 @@ class appGui(object): return True def set_not_connected_state(self, info): - self.connecting = False - self._set_not_connecting_state() + if self.connecting: + self._set_not_connecting_state() self.set_status(language['not_connected']) return True def _set_not_connecting_state(self): - self.connecting = False + if self.connecting: + gobject.source_remove(self.update_cb) + self.update_cb = misc.timeout_add(2, self.update_statusbar) + self.connecting = False if self.pulse_active: self.pulse_active = False gobject.idle_add(self.network_list.set_sensitive, True) gobject.idle_add(self.status_area.hide_all) - if self.statusID: gobject.idle_add(self.status_bar.remove, 1, self.statusID) def set_connecting_state(self, info): - self.connecting = True + if not self.connecting: + gobject.source_remove(self.update_cb) + self.update_cb = misc.timeout_add(500, self.update_statusbar, + milli=True) + self.connecting = True if not self.pulse_active: self.pulse_active = True misc.timeout_add(100, self.pulse_progress_bar, milli=True) @@ -710,6 +716,7 @@ class appGui(object): daemon.SetGUIOpen(True) self.wait_for_events(0.1) gobject.idle_add(self.refresh_clicked) + self._do_statusbar_update(*daemon.GetConnectionStatus()) bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged', 'org.wicd.daemon') self.update_cb = misc.timeout_add(2, self.update_statusbar) diff --git a/wicd/misc.py b/wicd/misc.py index a221a70..d42418c 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -69,7 +69,7 @@ class WicdError(Exception): __LANG = None -def Run(cmd, include_stderr=False, return_pipe=False): +def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False): """ Run a command. Runs the given command, returning either the output @@ -112,6 +112,8 @@ def Run(cmd, include_stderr=False, return_pipe=False): return "" + if return_obj: + return f if return_pipe: return f.stdout else: diff --git a/wicd/networking.py b/wicd/networking.py index a9ed8c7..aea3d04 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -44,7 +44,9 @@ class WiredConnectThread() -- Connection thread for wired import re import time import threading +import os import thread +from signal import SIGTERM # wicd imports import misc @@ -202,7 +204,8 @@ class Controller(object): iface = self.iface if self.disconnect_script != None: print 'Running disconnect script' - misc.ExecuteScript(expand_script_macros(self.disconnect_script, 'disconnection', *args)) + misc.ExecuteScript(expand_script_macros(self.disconnect_script, + 'disconnection', *args)) iface.ReleaseDHCP() iface.SetAddress('0.0.0.0') iface.FlushRoutes() @@ -213,6 +216,14 @@ class Controller(object): """ Release the DHCP lease for this interface. """ return self.iface.ReleaseDHCP() + def KillDHCP(self): + """ Kill the managed DHCP client if its in a connecting state. """ + if (self.connecting_thread.is_connecting and + self.iface.dhcp_object): + if self.iface.dhcp_object.poll() is None: + os.kill(self.iface.dhcp_object.pid, SIGTERM) + self.iface.dhcp_object = None + def IsUp(self): """ Calls the IsUp method for the wired interface. @@ -404,7 +415,8 @@ class ConnectThread(threading.Thread): print "Running DHCP" dhcp_status = iface.StartDHCP() if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']: - self.abort_connection(dhcp_status) + if self.connect_result != "aborted": + self.abort_connection(dhcp_status) return @abortable diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index f284a6e..cc04b19 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -80,7 +80,7 @@ def catchdbus(func): try: return func(*args, **kwargs) except DBusException, e: - print "warning: ignoring exception %s" % egg + print "warning: ignoring exception %s" % e return None wrapper.__name__ = func.__name__ wrapper.__module__ = func.__module__ diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 70e2c1a..26df66c 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -380,6 +380,9 @@ class WicdDaemon(dbus.service.Object): if self.wifi.connecting_thread: self.wifi.connecting_thread.should_die = True self.wifi.ReleaseDHCP() + # We have to actually kill dhcp if its still hanging + # around. It could still be trying to get a lease. + self.wifi.KillDHCP() self.wifi.StopWPA() self.wifi.connecting_thread.connect_result = 'aborted' if self.wired.connecting_thread: diff --git a/wicd/wnettools.py b/wicd/wnettools.py index 9dd9d8c..c653237 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -453,7 +453,8 @@ class BaseInterface(object): cmd = self._get_dhcp_command('connect') #cmd = self.DHCP_CMD + " " + self.iface if self.verbose: print cmd - pipe = misc.Run(cmd, include_stderr=True, return_pipe=True) + self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True) + pipe = self.dhcp_object.stdout DHCP_CLIENT = self.DHCP_CLIENT if DHCP_CLIENT == misc.DHCLIENT: From 8127dc194b9290492d62d358db572b1fbe3623b0 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Wed, 11 Feb 2009 21:01:12 -0500 Subject: [PATCH 2/3] Fix possible crash when handling D-Bus exceptions in monitor.py --- wicd/monitor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wicd/monitor.py b/wicd/monitor.py index 55dbfa2..592ec53 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -54,6 +54,8 @@ def diewithdbus(func): self.__lost_dbus_count = 0 return ret except dbusmanager.DBusException: + if not hasattr(self, "__lost_dbus_count"): + self.__lost_dbus_count = 0 if self.__lost_dbus_count > 3: sys.exit(1) self.__lost_dbus_count += 1 From 407615379693e08b714181da1c1d7bd6966b72e5 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Wed, 11 Feb 2009 22:44:38 -0500 Subject: [PATCH 3/3] Make default init script executable. --- in/init=default=wicd.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 in/init=default=wicd.in diff --git a/in/init=default=wicd.in b/in/init=default=wicd.in old mode 100644 new mode 100755