Skip to content
Browse files

Only delete the current scheme file when changing

to a different scheme.
Add debugging messages and comments to try to solve the problem
of why switching from eth0 to wlan0 doesn't work.
  • Loading branch information...
1 parent 3c40023 commit 0c5a8c5f7c78a18db261ec561e6c29f5d182fd65 @akkana committed Mar 9, 2013
Showing with 32 additions and 7 deletions.
  1. +14 −6 netscheme
  2. +18 −1 netutils.py
View
20 netscheme
@@ -166,10 +166,10 @@ auto %s""" % (iface.name)
if not add :
netutils.ifdown_all()
- print "Calling ifconfig up"
iface.ifconfig_up()
if not iface.wireless :
+ print "It's not wireless"
pass
elif self.encryption == "wep" or self.encryption == "open" :
# iwconfig doesn't work reliably on some systems unless you
@@ -287,7 +287,8 @@ psk="%s"
# Figure out what interface we'll be using:
iface = None
all = netutils.get_interfaces()
- # find the first wireless interface
+ # Find the first wireless interface if the scheme is wireless,
+ # else the first wired.
for i in all :
print "Trying interface", i.name
if i.wireless: print i.name, "is wireless"
@@ -305,6 +306,7 @@ psk="%s"
if not iface :
print "Couldn't find an interface to set the scheme"
return
+ print "Using interface", iface
# Are we on debian?
is_deb = is_debian()
@@ -361,9 +363,10 @@ psk="%s"
# in particular, if more than one interface is up, make sure
# there's no wifi default route blocking on on a wired interface.
up_ifaces = netutils.get_interfaces(True)
+ print "Up interfaces now:", up_ifaces
if len(up_ifaces) > 0 :
rt = netutils.Route.read_route_table()
- # print "Route table:", rt
+ print "Route table:", rt
defaults = []
for r in rt :
if r.dest == 'default' or r.dest == '0.0.0.0' :
@@ -536,9 +539,14 @@ def find_and_set_scheme(newscheme, add=False, make_persistent=False) :
print >>fp, scheme.name
fp.close()
- # Otherwise make sure there is no default scheme.
- elif os.access(current_file, os.W_OK) :
- os.remove(current_file)
+ # Otherwise, if there's a default scheme and it's different
+ # from the one we're switching to, clear it.
+ elif os.access(current_file, os.R_OK & os.W_OK) :
+ fp = open(current_file)
+ filescheme = fp.readline().strip()
+ fp.close()
+ if filescheme != newscheme :
+ os.remove(current_file)
return
View
19 netutils.py
@@ -89,13 +89,29 @@ def reload(self) :
def ifconfig_up(self) :
"""Mark the interface UP with ifconfig"""
+
+ # Okay, I have no idea what's going on here.
+ # If I set an eth0 scheme (which works correctly),
+ # then later try to set a wlan0 WPA scheme,
+ # when we get here, all interfaces are properly down.
+ # ifconfig -a shows that.
+ # Then we call ifconfig wlan0 up,
+ # and immediately after that, another ifconfig -a
+ # shows that both wlan0 and eth0 have been marked up.
+ # How do we mark wlan0 up without bringing eth0 with it?
+ # Running ifconfig wlan0 up by hand doesn't do that.
+
+ print "Before calling ifconfig_up", self.name, ", ifconfig -a looks like:"
+ subprocess.call(["ifconfig", "-a"])
+ print "Calling ifconfig", self.name, "up"
subprocess.call(["ifconfig", self.name, "up"])
+ print "After calling ifconfig up, ifconfig -a looks like:"
+ subprocess.call(["ifconfig", "-a"])
def ifconfig_down(self) :
"""Mark the interface DOWN with ifconfig"""
subprocess.call(["ifconfig", self.name, "down"])
self.reload()
- subprocess.call(["ifconfig", "-a"])
class Connection :
def __init__(self, iface=None) :
@@ -587,6 +603,7 @@ def ifdown_all() :
"""
print "ifdown_all"
up_ifaces = get_interfaces(True)
+ print "Taking up interfaces down:", up_ifaces
# Kill DHCP and wpa_supplicant.
# In theory apparently it's better to stop wpa_supplicant with

0 comments on commit 0c5a8c5

Please sign in to comment.
Something went wrong with that request. Please try again.