Hello again Thomas,

On Wed, 31 Oct 2012 21:31:55 +0100, Thomas Hood wrote:

> If resolvconf is installed, wnettools.py uses "resolvconf -a" to add a
> nameserver information record. However, a grep through the code reveals
> that it nowhere removes that record (using "resolvconf -d"). This is a bug.
> When the program deconfigures the interface, or at the very least when it
> quits, it must delete the record that it earlier created. Otherwise this
> stale record remains in the system until reboot.
> 
> I am guessing that the reason that there is no "resolvconf -d" is that
> wicd-daemon.py backs up and restores /etc/resolv.conf and that this was
> thought to make it unnecessary to do "resolvconf -d".

As said in another mail, where wicd-daemon.py does the backup/restore
operations, it doesn't know anything about the interfaces or resolvconf.

Would you please be so kind to test the attached patch? I'm not a user of
resolvconf, and I'd prefer someone more knowledgeable than me to test it :)

It simply flushes the records added to resolvconf whenever a "disconnect"
operation is done: be it a "real" disconnection, or putting up an interface, or
killing the daemon.
The only thing missing is, I believe, flushing the record when wicd is
abruptly killed (kill -9, or kinda). I'm not sure how to handle that, sorry.

I'll wait for a reply before committing this patch upstream.

Thanks,
David

-- 
 . ''`.   Debian developer | http://wiki.debian.org/DavidPaleino
 : :'  : Linuxer #334216 --|-- http://www.hanskalabs.net/
 `. `'`  GPG: 1392B174 ----|---- http://deb.li/dapal
   `-   2BAB C625 4E66 E7B8 450A C3E1 E6AA 9017 1392 B174
diff --git a/wicd/networking.py b/wicd/networking.py
index ced94b6..a431886 100644
--- a/wicd/networking.py
+++ b/wicd/networking.py
@@ -222,6 +222,7 @@ class Controller(object):
         iface.ReleaseDHCP()
         iface.SetAddress('0.0.0.0')
         iface.FlushRoutes()
+        iface.FlushDNS()
         iface.Down()
         iface.Up()
         misc.ExecuteScripts(wpath.postdisconnectscripts, self.debug,
@@ -465,6 +466,17 @@ class ConnectThread(threading.Thread):
                 return
 
     @abortable
+    def flush_dns_addresses(self, iface):
+        """ Flush the added DNS address(es).
+
+        This is only useful when using resolvconf, since we effectively have no
+        foolproof way of removing added DNS addresses from a non-resolvconf
+        setup.
+
+        """
+        iface.FlushDNS()
+
+    @abortable
     def set_dns_addresses(self, iface):
         """ Set the DNS address(es).
 
@@ -908,6 +920,7 @@ class WirelessConnectThread(ConnectThread):
         self.reset_ip_addresses(wiface)
         self.stop_wpa(wiface)
         self.flush_routes(wiface)
+        self.flush_dns_addresses(wiface)
         wiface.SetMode(self.network['mode'])
         wiface.SetBitrate(self.bitrate, self.allow_lower_bitrates)
 
@@ -983,6 +996,7 @@ class WirelessConnectThread(ConnectThread):
                 # Clean up before aborting.
                 iface.SetAddress('0.0.0.0')
                 iface.FlushRoutes()
+                iface.FlushDNS()
                 if hasattr(iface, "StopWPA"):
                     iface.StopWPA()
                 self.abort_connection('association_failed')
@@ -1162,6 +1176,7 @@ class WiredConnectThread(ConnectThread):
         self.reset_ip_addresses(liface)
         self.stop_wpa(liface)
         self.flush_routes(liface)
+        self.flush_dns_addresses(liface)
         
         # Bring up interface.
         self.put_iface_up(liface)
diff --git a/wicd/wnettools.py b/wicd/wnettools.py
index 2690b2c..efa6724 100644
--- a/wicd/wnettools.py
+++ b/wicd/wnettools.py
@@ -644,6 +644,19 @@ class BaseInterface(object):
         misc.Run(cmd)
 
     @neediface(False)
+    def FlushDNS(self):
+        """ Remove added DNS servers from system resolv.conf.
+
+        Only useful for resolvconf-based setups.
+
+        """
+        if self.resolvconf_cmd:
+            cmd = [self.resolvconf_cmd, '-d', self.iface + '.wicd']
+            if self.verbose: print cmd
+            p = misc.Run(cmd, include_stderr=True, return_obj=True)
+            p.communicate()
+
+    @neediface(False)
     def SetDNS(self, dns1=None, dns2=None, dns3=None, 
                dns_dom=None, search_dom=None):
         """ Set the DNS of the system to the specified DNS servers.

Attachment: signature.asc
Description: PGP signature

Reply via email to