]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If a new hostname is set, log it.
authorRoy Marples <roy@marples.name>
Mon, 27 Feb 2017 22:06:11 +0000 (22:06 +0000)
committerRoy Marples <roy@marples.name>
Mon, 27 Feb 2017 22:06:11 +0000 (22:06 +0000)
dhcpcd-hooks/30-hostname

index eea6a5ce7c3ba8229b2ccdc5d521b04b242b3ab6..44c2ecdcf64452a2ba84daef0d0e9081bd8268ec 100644 (file)
@@ -20,7 +20,7 @@ _hostname()
 {
        local name=
 
-       if [ -z "$1" ]; then
+       if [ -z "${1+x}" ]; then
                if type hostname >/dev/null 2>&1; then
                        hostname
                elif [ -r /proc/sys/kernel/hostname ]; then
@@ -53,17 +53,18 @@ _hostname()
 
 need_hostname()
 {
-       local hostname hfqdn=false hshort=false
-
-       case "$force_hostname" in
-       [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
-       esac
+       local hfqdn=false hshort=false
 
+       # Always load the hostname variable for future use
        hostname="$(_hostname)"
        case "$hostname" in
        ""|"(none)"|localhost|localhost.localdomain) return 0;;
        esac
-       
+
+       case "$force_hostname" in
+       [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
+       esac
+
        case "$hostname_fqdn" in
        [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)        hfqdn=true;;
        ""|[Ss][Ee][Rr][Vv][Ee][Rr])            ;;
@@ -100,7 +101,9 @@ need_hostname()
 try_hostname()
 {
 
+       [ "$hostname" = "$1" ] && return 0
        if valid_domainname "$1"; then
+               syslog info "Setting hostname: $1"
                _hostname "$1"
        else
                syslog err "Invalid hostname: $1"