[PATCH 1/2] save duid to lease file



get_duid() got a default-duid from the lease file, from
one of the system files, or from the machine-id but did
not save it back to the lease file so that dhclient
could use it.
Signed-off-by: Gene Czarcinski <gene czarc net>
---
 src/dhcp-manager/nm-dhcp-dhclient.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c
index d9f5135..ad41dcd 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient.c
@@ -643,7 +643,6 @@ get_duid (NMDHCPClient *client)
 	                                    TRUE);
 	nm_log_dbg (LOGD_DHCP, "Looking for DHCPv6 DUID in '%s'.", leasefile);
 	duid = nm_dhcp_dhclient_read_duid (leasefile, &error);
-	g_free (leasefile);
 
 	if (error) {
 		nm_log_warn (LOGD_DHCP, "Failed to read leasefile '%s': (%d) %s",
@@ -666,8 +665,27 @@ get_duid (NMDHCPClient *client)
 		}
 	}
 
-	/* return our DUID, otherwise let the parent class make a default DUID */
-	return duid ? duid : NM_DHCP_CLIENT_CLASS (nm_dhcp_dhclient_parent_class)->get_duid (client);
+	/* If no DUID, let the parent class make a default DUID */
+	if (!duid)
+		duid = NM_DHCP_CLIENT_CLASS (nm_dhcp_dhclient_parent_class)->get_duid (client);
+
+	nm_log_dbg (LOGD_DHCP, "Attempting to write default-duid to leasefile '%s'", leasefile);
+	if (duid) {
+		if (!nm_dhcp_dhclient_save_duid (leasefile, nm_dhcp_dhclient_escape_duid (duid), &error)) {
+			nm_log_warn (LOGD_DHCP, "Failed to write default-duid to leasefile '%s' :(%d) %s",
+						leasefile,
+						error ? error->code : -1,
+						error ? error->message : "(unknown)");
+			g_clear_error(&error);
+		}
+	}
+	else {
+		nm_log_warn (LOGD_DHCP, "Failed to get duid-UUID from parent");
+	}
+
+	g_free (leasefile);
+
+	return duid;
 }
 
 /***************************************************/
-- 
1.8.1.2



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]