wicd: fix dhclient interaction

wicd used to write dhclient config file into $out/var/lib/wicd directory attempting
to change nix-store. That didn't work and thats why we couldn't use dhclient.
With this patch wicd will generate temporary file name for this purpose. File is
generated each time the daemon starts.

+109 -1
+8 -1
pkgs/tools/networking/wicd/default.nix
··· 16 16 17 17 buildInputs = [ python ]; 18 18 19 - patches = [ ./no-var-install.patch ./no-trans.patch ./mkdir-networks.patch ./pygtk.patch ./no-optimization.patch ]; 19 + patches = [ 20 + ./no-var-install.patch 21 + ./no-trans.patch 22 + #./mkdir-networks.patch 23 + ./pygtk.patch 24 + ./no-optimization.patch 25 + ./dhclient.patch 26 + ]; 20 27 21 28 # Should I be using pygtk's propogated build inputs? 22 29 # !!! Should use makeWrapper.
+101
pkgs/tools/networking/wicd/dhclient.patch
··· 1 + diff -ruN wicd-1.7.2.4.orig/wicd/wnettools.py wicd-1.7.2.4/wicd/wnettools.py 2 + --- wicd-1.7.2.4.orig/wicd/wnettools.py 2013-03-30 21:47:19.804907552 +0000 3 + +++ wicd-1.7.2.4/wicd/wnettools.py 2013-03-31 08:44:37.572792110 +0000 4 + @@ -37,6 +37,7 @@ 5 + import time 6 + from string import maketrans, translate 7 + 8 + +import tempfile 9 + import wpath 10 + import misc 11 + from misc import find_path 12 + @@ -216,6 +217,7 @@ 13 + self.flush_tool = None 14 + self.link_detect = None 15 + self.dhcp_object = None 16 + + self.dhclient_conf_path = None; 17 + 18 + def SetDebugMode(self, value): 19 + """ If True, verbose output is enabled. """ 20 + @@ -277,12 +279,6 @@ 21 + cmd = "" 22 + return (client, cmd) 23 + 24 + - # probably /var/lib/wicd/dhclient.conf with defaults 25 + - dhclient_conf_path = os.path.join( 26 + - wpath.varlib, 27 + - 'dhclient.conf' 28 + - ) 29 + - 30 + client_dict = { 31 + "dhclient" : 32 + {'connect' : r"%(cmd)s -cf %(dhclientconf)s %(iface)s", 33 + @@ -307,41 +303,44 @@ 34 + } 35 + (client_name, cmd) = get_client_name(self.DHCP_CLIENT) 36 + 37 + - # cause dhclient doesn't have a handy dandy argument 38 + - # for specifing the hostname to be sent 39 + - if client_name == "dhclient" and flavor: 40 + - if hostname == None: 41 + - # <hostname> will use the system hostname 42 + - # we'll use that if there is hostname passed 43 + - # that shouldn't happen, though 44 + - hostname = '<hostname>' 45 + - print 'attempting to set hostname with dhclient' 46 + - print 'using dhcpcd or another supported client may work better' 47 + - dhclient_template = \ 48 + - open(os.path.join(wpath.etc, 'dhclient.conf.template'), 'r') 49 + - 50 + - output_conf = open(dhclient_conf_path, 'w') 51 + - 52 + - for line in dhclient_template.readlines(): 53 + - line = line.replace('$_HOSTNAME', hostname) 54 + - output_conf.write(line) 55 + - 56 + - output_conf.close() 57 + - dhclient_template.close() 58 + - os.chmod(dhclient_conf_path, 0644) 59 + - 60 + if not client_name or not cmd: 61 + print "WARNING: Failed to find a valid dhcp client!" 62 + return "" 63 + 64 + if flavor == "connect": 65 + + # cause dhclient doesn't have a handy dandy argument 66 + + # for specifing the hostname to be sent 67 + + if client_name == "dhclient" and flavor: 68 + + if hostname == None: 69 + + # <hostname> will use the system hostname 70 + + # we'll use that if there is hostname passed 71 + + # that shouldn't happen, though 72 + + hostname = '<hostname>' 73 + + print 'attempting to set hostname with dhclient' 74 + + print 'using dhcpcd or another supported client may work better' 75 + + if not self.dhclient_conf_path: 76 + + _,self.dhclient_conf_path = tempfile.mkstemp() 77 + + print 'New dhclient conf path: %s ' % self.dhclient_conf_path 78 + + dhclient_template = \ 79 + + open(os.path.join(wpath.etc, 'dhclient.conf.template'), 'r') 80 + + 81 + + output_conf = open(self.dhclient_conf_path, 'w') 82 + + 83 + + for line in dhclient_template.readlines(): 84 + + line = line.replace('$_HOSTNAME', hostname) 85 + + output_conf.write(line) 86 + + 87 + + output_conf.close() 88 + + dhclient_template.close() 89 + + os.chmod(self.dhclient_conf_path, 0644) 90 + + 91 + if not hostname: 92 + hostname = os.uname()[1] 93 + return client_dict[client_name]['connect'] % \ 94 + { "cmd" : cmd, 95 + "iface" : self.iface, 96 + "hostname" : hostname, 97 + - 'dhclientconf' : dhclient_conf_path } 98 + + 'dhclientconf' : self.dhclient_conf_path } 99 + elif flavor == "release": 100 + return client_dict[client_name]['release'] % {"cmd":cmd, "iface":self.iface} 101 + else: