1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-22 14:07:59 +01:00

Fix issue where GetForcedDisconnect was returning True when we had just connected.

Fix issues with auto-switch to wired.
Change to how the gui handles changing state from connecting to not-connecting to be nicer.
Make the gui trigger monitor state updates while in the connecting state.
Make sure the monitor logs a warning when it catches a D-Bus exception.
Make sure cancelling a wired connection attempt kills DHCP.
Fix issue where DHCP wouldn't get run if automatic dhcp tool was enabled.
This commit is contained in:
Dan O'Reilly
2009-02-12 18:38:40 -05:00
parent 4076153796
commit f237f421ab
5 changed files with 66 additions and 76 deletions

View File

@@ -197,6 +197,7 @@ class appGui(object):
self.connecting = False self.connecting = False
self.refreshing = False self.refreshing = False
self.prev_state = None self.prev_state = None
self.update_cb = None
self.network_list.set_sensitive(False) self.network_list.set_sensitive(False)
label = gtk.Label("%s..." % language['scanning']) label = gtk.Label("%s..." % language['scanning'])
self.network_list.pack_start(label) self.network_list.pack_start(label)
@@ -356,10 +357,11 @@ class appGui(object):
if not self.is_visible: if not self.is_visible:
return True return True
if self.connecting:
self._do_statusbar_update(*daemon.GetConnectionStatus())
else:
daemon.UpdateState() daemon.UpdateState()
if self.connecting:
# If we're connecting, don't wait for the monitor to send
# us a signal, since it won't until the connection is made.
self._do_statusbar_update(*daemon.GetConnectionStatus())
return True return True
def _do_statusbar_update(self, state, info): def _do_statusbar_update(self, state, info):
@@ -377,11 +379,15 @@ class appGui(object):
return True return True
def set_wired_state(self, info): def set_wired_state(self, info):
if self.connecting:
# Adjust our state from connecting->connected.
self._set_not_connecting_state() self._set_not_connecting_state()
self.set_status(language['connected_to_wired'].replace('$A', info[0])) self.set_status(language['connected_to_wired'].replace('$A', info[0]))
return True return True
def set_wireless_state(self, info): def set_wireless_state(self, info):
if self.connecting:
# Adjust our state from connecting->connected.
self._set_not_connecting_state() self._set_not_connecting_state()
self.set_status(language['connected_to_wireless'].replace self.set_status(language['connected_to_wireless'].replace
('$A', info[1]).replace ('$A', info[1]).replace
@@ -391,12 +397,13 @@ class appGui(object):
def set_not_connected_state(self, info): def set_not_connected_state(self, info):
if self.connecting: if self.connecting:
# Adjust our state from connecting->not-connected.
self._set_not_connecting_state() self._set_not_connecting_state()
self.set_status(language['not_connected']) self.set_status(language['not_connected'])
return True return True
def _set_not_connecting_state(self): def _set_not_connecting_state(self):
if self.connecting: if self.connecting and self.update_cb:
gobject.source_remove(self.update_cb) gobject.source_remove(self.update_cb)
self.update_cb = misc.timeout_add(2, self.update_statusbar) self.update_cb = misc.timeout_add(2, self.update_statusbar)
self.connecting = False self.connecting = False
@@ -408,7 +415,7 @@ class appGui(object):
gobject.idle_add(self.status_bar.remove, 1, self.statusID) gobject.idle_add(self.status_bar.remove, 1, self.statusID)
def set_connecting_state(self, info): def set_connecting_state(self, info):
if not self.connecting: if not self.connecting and self.update_cb:
gobject.source_remove(self.update_cb) gobject.source_remove(self.update_cb)
self.update_cb = misc.timeout_add(500, self.update_statusbar, self.update_cb = misc.timeout_add(500, self.update_statusbar,
milli=True) milli=True)
@@ -661,6 +668,7 @@ class appGui(object):
""" """
widget.hide() widget.hide()
networkentry.connect_button.show() networkentry.connect_button.show()
daemon.SetForcedDisconnect(True)
if nettype == "wired": if nettype == "wired":
wired.DisconnectWired() wired.DisconnectWired()
else: else:

View File

@@ -53,7 +53,8 @@ def diewithdbus(func):
ret = func(self, *__args, **__kargs) ret = func(self, *__args, **__kargs)
self.__lost_dbus_count = 0 self.__lost_dbus_count = 0
return ret return ret
except dbusmanager.DBusException: except dbusmanager.DBusException, e:
print "Caught exception %e" % str(e)
if not hasattr(self, "__lost_dbus_count"): if not hasattr(self, "__lost_dbus_count"):
self.__lost_dbus_count = 0 self.__lost_dbus_count = 0
if self.__lost_dbus_count > 3: if self.__lost_dbus_count > 3:
@@ -102,6 +103,7 @@ class ConnectionStatus(object):
2) A wired connection is currently active. 2) A wired connection is currently active.
""" """
self.trigger_reconnect = False
if not wired_ip and daemon.GetPreferWiredNetwork(): if not wired_ip and daemon.GetPreferWiredNetwork():
if not daemon.GetForcedDisconnect() and wired.CheckPluggedIn(): if not daemon.GetForcedDisconnect() and wired.CheckPluggedIn():
self.trigger_reconnect = True self.trigger_reconnect = True
@@ -196,15 +198,6 @@ class ConnectionStatus(object):
# Check for wired. # Check for wired.
wired_ip = wired.GetWiredIP("") wired_ip = wired.GetWiredIP("")
wired_found = self.check_for_wired_connection(wired_ip) wired_found = self.check_for_wired_connection(wired_ip)
# Trigger an AutoConnect if we're plugged in, not connected
# to a wired network, and the "autoswitch to wired" option
# is on.
if self.trigger_reconnect:
self.trigger_reconnect = False
wireless.DisconnectWireless()
daemon.AutoConnect(False, reply_handler=lambda:None,
error_handler=lambda:None)
return True
if wired_found: if wired_found:
self.update_state(misc.WIRED, wired_ip=wired_ip) self.update_state(misc.WIRED, wired_ip=wired_ip)
return True return True
@@ -214,6 +207,22 @@ class ConnectionStatus(object):
self.signal_changed = False self.signal_changed = False
wireless_found = self.check_for_wireless_connection(wifi_ip) wireless_found = self.check_for_wireless_connection(wifi_ip)
if wireless_found: if wireless_found:
if self.trigger_reconnect:
# If we made it here, that means we want to switch
# to a wired network whenever possible, but a wireless
# connection is active. So we kill the wireless connection
# so the autoconnect logic will connect to the wired network.
self.trigger_reconnect = False
# Don't trigger it if the gui is open, because autoconnect
# is disabled while it's open.
if not daemon.GetGUIOpen():
print 'Killing wireless connection to switch to wired...'
wireless.DisconnectWireless()
daemon.AutoConnect(False, reply_handler=lambda:None,
error_handler=lambda:None)
self.update_state(misc.NOT_CONNECTED)
return True
self.update_state(misc.WIRELESS, wifi_ip=wifi_ip) self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
return True return True

View File

@@ -218,6 +218,7 @@ class Controller(object):
def KillDHCP(self): def KillDHCP(self):
""" Kill the managed DHCP client if its in a connecting state. """ """ Kill the managed DHCP client if its in a connecting state. """
print 'running kill dhcp.'
if (self.connecting_thread.is_connecting and if (self.connecting_thread.is_connecting and
self.iface.dhcp_object): self.iface.dhcp_object):
if self.iface.dhcp_object.poll() is None: if self.iface.dhcp_object.poll() is None:

View File

@@ -323,12 +323,15 @@ class WicdDaemon(dbus.service.Object):
""" """
print "Autoconnecting..." print "Autoconnecting..."
if self.CheckIfConnecting():
if self.debug_mode:
print 'Already connecting, doing nothing.'
return
# We don't want to rescan/connect if the gui is open. # We don't want to rescan/connect if the gui is open.
if self.gui_open: if self.gui_open:
if self.debug_mode: if self.debug_mode:
print "Skipping autoconnect because GUI is open." print "Skipping autoconnect because GUI is open."
return return
if self.wired_bus.CheckPluggedIn(): if self.wired_bus.CheckPluggedIn():
if self.debug_mode: if self.debug_mode:
print "Starting wired autoconnect..." print "Starting wired autoconnect..."
@@ -388,6 +391,7 @@ class WicdDaemon(dbus.service.Object):
if self.wired.connecting_thread: if self.wired.connecting_thread:
self.wired.connecting_thread.should_die = True self.wired.connecting_thread.should_die = True
self.wired.ReleaseDHCP() self.wired.ReleaseDHCP()
self.wired.KillDHCP()
self.wired.connecting_thread.connect_result = 'aborted' self.wired.connecting_thread.connect_result = 'aborted'
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
@@ -425,9 +429,7 @@ class WicdDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetForcedDisconnect(self): def GetForcedDisconnect(self):
""" Returns the forced_disconnect status. See SetForcedDisconnect. """ """ Returns the forced_disconnect status. See SetForcedDisconnect. """
return (bool(self.forced_disconnect) or return bool(self.forced_disconnect)
bool(self.wireless_bus.GetForcedDisconnect()) or
bool(self.wired_bus.GetForcedDisconnect()))
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetForcedDisconnect(self, value): def SetForcedDisconnect(self, value):
@@ -440,8 +442,6 @@ class WicdDaemon(dbus.service.Object):
""" """
if self.debug_mode and value: print "Forced disconnect on" if self.debug_mode and value: print "Forced disconnect on"
self.forced_disconnect = bool(value) self.forced_disconnect = bool(value)
self.wireless_bus.SetForcedDisconnect(bool(value))
self.wired_bus.SetForcedDisconnect(bool(value))
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetSignalDisplayType(self): def GetSignalDisplayType(self):
@@ -923,7 +923,6 @@ class WirelessDaemon(dbus.service.Object):
self.daemon = daemon self.daemon = daemon
self.wifi = wifi self.wifi = wifi
self._debug_mode = debug self._debug_mode = debug
self.forced_disconnect = False
self._scanning = False self._scanning = False
self.LastScan = [] self.LastScan = []
self.config = ConfigManager(os.path.join(wpath.etc, self.config = ConfigManager(os.path.join(wpath.etc,
@@ -1041,26 +1040,9 @@ class WirelessDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def DisconnectWireless(self): def DisconnectWireless(self):
""" Disconnects the wireless network. """ """ Disconnects the wireless network. """
self.SetForcedDisconnect(True)
self.wifi.Disconnect() self.wifi.Disconnect()
self.daemon.UpdateState() self.daemon.UpdateState()
@dbus.service.method('org.wicd.daemon.wireless')
def GetForcedDisconnect(self):
""" Returns the forced_disconnect status. See SetForcedDisconnect. """
return bool(self.forced_disconnect)
@dbus.service.method('org.wicd.daemon.wireless')
def SetForcedDisconnect(self, value):
""" Sets the forced_disconnect status.
Set to True when a user manually disconnects or cancels a connection.
It gets set to False as soon as the connection process is manually
started.
"""
self.forced_disconnect = bool(value)
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def IsWirelessUp(self): def IsWirelessUp(self):
""" Returns a boolean specifying if wireless is up or down. """ """ Returns a boolean specifying if wireless is up or down. """
@@ -1119,13 +1101,13 @@ class WirelessDaemon(dbus.service.Object):
# Will returned instantly, that way we don't hold up dbus. # Will returned instantly, that way we don't hold up dbus.
# CheckIfWirelessConnecting can be used to test if the connection # CheckIfWirelessConnecting can be used to test if the connection
# is done. # is done.
self.SetForcedDisconnect(False)
self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript') self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript')
self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript') self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript')
self.wifi.disconnect_script = self.GetWirelessProperty(id, self.wifi.disconnect_script = self.GetWirelessProperty(id,
'disconnectscript') 'disconnectscript')
print 'Connecting to wireless network ' + self.LastScan[id]['essid'] print 'Connecting to wireless network ' + self.LastScan[id]['essid']
self.daemon.wired_bus.DisconnectWired() self.daemon.wired_bus.wired.Disconnect()
self.daemon.SetForcedDisconnect(False)
conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode) conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
self.daemon.UpdateState() self.daemon.UpdateState()
@@ -1298,7 +1280,6 @@ class WiredDaemon(dbus.service.Object):
self.daemon = daemon self.daemon = daemon
self.wired = wired self.wired = wired
self._debug_mode = debug self._debug_mode = debug
self.forced_disconnect = False
self.WiredNetwork = {} self.WiredNetwork = {}
self.config = ConfigManager(os.path.join(wpath.etc, self.config = ConfigManager(os.path.join(wpath.etc,
"wired-settings.conf"), "wired-settings.conf"),
@@ -1378,7 +1359,6 @@ class WiredDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def DisconnectWired(self): def DisconnectWired(self):
""" Disconnects the wired network. """ """ Disconnects the wired network. """
self.SetForcedDisconnect(True)
self.wired.Disconnect() self.wired.Disconnect()
self.daemon.UpdateState() self.daemon.UpdateState()
@@ -1405,30 +1385,14 @@ class WiredDaemon(dbus.service.Object):
""" Calls a method to disable the wired interface. """ """ Calls a method to disable the wired interface. """
return self.wired.DisableInterface() return self.wired.DisableInterface()
@dbus.service.method('org.wicd.daemon.wired')
def GetForcedDisconnect(self):
""" Returns the forced_disconnect status. See SetForcedDisconnect. """
return bool(self.forced_disconnect)
@dbus.service.method('org.wicd.daemon.wired')
def SetForcedDisconnect(self, value):
""" Sets the forced_disconnect status.
Set to True when a user manually disconnects or cancels a connection.
It gets set to False as soon as the connection process is manually
started.
"""
self.forced_disconnect = bool(value)
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def ConnectWired(self): def ConnectWired(self):
""" Connects to a wired network. """ """ Connects to a wired network. """
self.SetForcedDisconnect(False)
self.wired.before_script = self.GetWiredProperty("beforescript") self.wired.before_script = self.GetWiredProperty("beforescript")
self.wired.after_script = self.GetWiredProperty("afterscript") self.wired.after_script = self.GetWiredProperty("afterscript")
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript") self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
self.daemon.wireless_bus.DisconnectWireless() self.daemon.wireless_bus.wifi.Disconnect()
self.daemon.SetForcedDisconnect(False)
self.wired.Connect(self.WiredNetwork, debug=self.debug_mode) self.wired.Connect(self.WiredNetwork, debug=self.debug_mode)
self.daemon.UpdateState() self.daemon.UpdateState()

View File

@@ -217,15 +217,22 @@ class BaseInterface(object):
cmd = "" cmd = ""
return (client, cmd) return (client, cmd)
connect_dict = { client_dict = {
"dhclient" : r"%s %s", "dhclient" :
"pump" : r"%s -i %s", {'connect' : r"%s %s",
"dhcpcd" : r"%s %s", 'release' : r"%s -r %s",
} 'id' : misc.DHCLIENT,
release_dict = { },
"dhclient" : r"%s -r %s", "pump" :
"pump" : r"%s -r -i %s", { 'connect' : r"%s -i %s",
"dhcpcd" : r"%s -k %s", 'release' : r"%s -r -i %s",
'id' : misc.PUMP,
},
"dhcpcd" :
{'connect' : r"%s %s",
'release' : r"%s -k %s",
'id' : misc.DHCPCD,
},
} }
(client_name, cmd) = get_client_name(self.DHCP_CLIENT) (client_name, cmd) = get_client_name(self.DHCP_CLIENT)
if not client_name or not cmd: if not client_name or not cmd:
@@ -233,11 +240,11 @@ class BaseInterface(object):
return "" return ""
if flavor == "connect": if flavor == "connect":
return connect_dict[client_name] % (cmd, self.iface) return client_dict[client_name]['connect'] % (cmd, self.iface)
elif flavor == "release": elif flavor == "release":
return release_dict[client_name] % (cmd, self.iface) return client_dict[client_name]['release'] % (cmd, self.iface)
else: else:
return str(cmd) return client_dict[client_name]['id']
def AppAvailable(self, app): def AppAvailable(self, app):
""" Return whether a given app is available. """ Return whether a given app is available.
@@ -451,18 +458,19 @@ class BaseInterface(object):
if not self.iface: return False if not self.iface: return False
cmd = self._get_dhcp_command('connect') cmd = self._get_dhcp_command('connect')
#cmd = self.DHCP_CMD + " " + self.iface
if self.verbose: print cmd if self.verbose: print cmd
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True) self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
pipe = self.dhcp_object.stdout pipe = self.dhcp_object.stdout
DHCP_CLIENT = self.DHCP_CLIENT DHCP_CLIENT = self._get_dhcp_command()
if DHCP_CLIENT == misc.DHCLIENT: if DHCP_CLIENT == misc.DHCLIENT:
return self._parse_dhclient(pipe) return self._parse_dhclient(pipe)
elif DHCP_CLIENT == misc.PUMP: elif DHCP_CLIENT == misc.PUMP:
return self._parse_pump(pipe) return self._parse_pump(pipe)
elif DHCP_CLIENT == misc.DHCPCD: elif DHCP_CLIENT == misc.DHCPCD:
return self._parse_dhcpcd(pipe) return self._parse_dhcpcd(pipe)
else:
print 'ERROR no dhclient found!'
def ReleaseDHCP(self): def ReleaseDHCP(self):
""" Release the DHCP lease for this interface. """ """ Release the DHCP lease for this interface. """