summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-09-06 13:13:22 +0200
committerThomas Haller <thaller@redhat.com>2017-09-08 11:05:04 +0200
commit9574472f9b8f7841d7e0ffb7a1eefa39214e8263 (patch)
tree2f46ab8c6845dc7cd5e9da18459434939483d371
parent959944d6230e4a9e3983f4c24bb4454790d62ebf (diff)
policy: refactor setting hostname from DHCP in update_system_hostname()
-rw-r--r--src/nm-policy.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 1a97b0273..2d4dc7e03 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -671,15 +671,13 @@ update_system_hostname (NMPolicy *self, NMDevice *best4, NMDevice *best6, const
/* Grab a hostname out of the device's DHCP4 config */
dhcp4_config = nm_device_get_dhcp4_config (best4);
if (dhcp4_config) {
- p = dhcp_hostname = nm_dhcp4_config_get_option (dhcp4_config, "host_name");
- if (dhcp_hostname && strlen (dhcp_hostname)) {
- /* Sanity check; strip leading spaces */
- while (*p) {
- if (!g_ascii_isspace (*p++)) {
- _set_hostname (self, p-1, "from DHCPv4");
- priv->dhcp_hostname = TRUE;
- return;
- }
+ dhcp_hostname = nm_dhcp4_config_get_option (dhcp4_config, "host_name");
+ if (dhcp_hostname && dhcp_hostname[0]) {
+ p = nm_str_skip_leading_spaces (dhcp_hostname);
+ if (p[0]) {
+ _set_hostname (self, p, "from DHCPv4");
+ priv->dhcp_hostname = TRUE;
+ return;
}
_LOGW (LOGD_DNS, "set-hostname: DHCPv4-provided hostname '%s' looks invalid; ignoring it",
dhcp_hostname);
@@ -691,15 +689,13 @@ update_system_hostname (NMPolicy *self, NMDevice *best4, NMDevice *best6, const
/* Grab a hostname out of the device's DHCP6 config */
dhcp6_config = nm_device_get_dhcp6_config (best6);
if (dhcp6_config) {
- p = dhcp_hostname = nm_dhcp6_config_get_option (dhcp6_config, "host_name");
- if (dhcp_hostname && strlen (dhcp_hostname)) {
- /* Sanity check; strip leading spaces */
- while (*p) {
- if (!g_ascii_isspace (*p++)) {
- _set_hostname (self, p-1, "from DHCPv6");
- priv->dhcp_hostname = TRUE;
- return;
- }
+ dhcp_hostname = nm_dhcp6_config_get_option (dhcp6_config, "host_name");
+ if (dhcp_hostname && dhcp_hostname[0]) {
+ p = nm_str_skip_leading_spaces (dhcp_hostname);
+ if (p[0]) {
+ _set_hostname (self, p, "from DHCPv6");
+ priv->dhcp_hostname = TRUE;
+ return;
}
_LOGW (LOGD_DNS, "set-hostname: DHCPv6-provided hostname '%s' looks invalid; ignoring it",
dhcp_hostname);