]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: properly reset transient hostname when we lose a DHCP lease
authorLennart Poettering <lennart@poettering.net>
Thu, 27 Aug 2015 10:53:43 +0000 (12:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 27 Aug 2015 10:53:43 +0000 (12:53 +0200)
Previously we were setting the transient hostname again, rather than
resetting it.

src/network/networkd-dhcp4.c
src/network/networkd-link.c

index 4e2936f637b1187a2bf580611db3c26b904a5d61..a075015c3c5534c24aef956e923cb483c1491602 100644 (file)
@@ -270,18 +270,16 @@ static int dhcp_lease_lost(Link *link) {
         if (link->network->dhcp_hostname) {
                 const char *hostname = NULL;
 
-                if (!link->network->hostname)
-                        r = sd_dhcp_lease_get_hostname(link->dhcp_lease, &hostname);
-                else
+                if (link->network->hostname)
                         hostname = link->network->hostname;
+                else
+                        (void) sd_dhcp_lease_get_hostname(link->dhcp_lease, &hostname);
 
-                if (r >= 0 || hostname) {
-                        r = link_set_hostname(link, hostname);
+                if (hostname) {
+                        /* If a hostname was set due to the lease, then unset it now. */
+                        r = link_set_hostname(link, NULL);
                         if (r < 0)
-                                log_link_error_errno(link, r,
-                                                     "Failed to set transient hostname to '%s': %m",
-                                                     hostname);
-
+                                log_link_warning_errno(link, r, "Failed to reset transient hostname: %m");
                 }
         }
 
@@ -470,12 +468,12 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
         if (link->network->dhcp_hostname) {
                 const char *hostname = NULL;
 
-                if (!link->network->hostname)
-                        r = sd_dhcp_lease_get_hostname(lease, &hostname);
-                else
+                if (link->network->hostname)
                         hostname = link->network->hostname;
+                else
+                        (void) sd_dhcp_lease_get_hostname(lease, &hostname);
 
-                if (r >= 0 || hostname) {
+                if (hostname) {
                         r = link_set_hostname(link, hostname);
                         if (r < 0)
                                 log_link_error_errno(link, r, "Failed to set transient hostname to '%s': %m", hostname);
index 371136a11ef1699e4a22e3d426df43a279459271..5af82059d812404206423fb8830c8f729264fcba 100644 (file)
@@ -801,9 +801,8 @@ int link_set_hostname(Link *link, const char *hostname) {
 
         assert(link);
         assert(link->manager);
-        assert(hostname);
 
-        log_link_debug(link, "Setting transient hostname: '%s'", hostname);
+        log_link_debug(link, "Setting transient hostname: '%s'", strna(hostname));
 
         if (!link->manager->bus) {
                 /* TODO: replace by assert when we can rely on kdbus */