]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
30-hostname: set to localhost when hostname is reqlinquished
authorPaul Walrath <paul.walrath@hp.com>
Mon, 27 Feb 2017 22:41:46 +0000 (22:41 +0000)
committerRoy Marples <roy@marples.name>
Mon, 27 Feb 2017 23:36:46 +0000 (23:36 +0000)
Summary:
If the DHCP controlled hostname is relinquished,
set it to a default value of localhost.
This allows a future lease to set it again.

Fixes T106.

Reviewers: pwalrath, test

Reviewed By: pwalrath

Maniphest Tasks: T106

Differential Revision: https://dev.marples.name/D101

dhcpcd-hooks/30-hostname

index 44c2ecdcf64452a2ba84daef0d0e9081bd8268ec..6f8623f896aedb91149729fcfaf587559ded3d96 100644 (file)
 # is always assigned.
 : ${hostname_fqdn:=true}
 
+# If we used to set the hostname, but relinquish control of it, we should
+# reset to the default value.
+: ${hostname_default=localhost}
+
 # Some systems don't have hostname(1)
 _hostname()
 {
@@ -58,7 +62,8 @@ need_hostname()
        # Always load the hostname variable for future use
        hostname="$(_hostname)"
        case "$hostname" in
-       ""|"(none)"|localhost|localhost.localdomain) return 0;;
+       ""|"(none)"|localhost|localhost.localdomain|"$hostname_default")
+               return 0;;
        esac
 
        case "$force_hostname" in
@@ -142,6 +147,8 @@ set_hostname()
                else
                        try_hostname "$new_host_name"
                fi
+       elif [ -n "${hostname_default+x}" ]; then
+               try_hostname "$hostname_default"
        fi
 }