Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 122794 - a hostname set by the kernel / dhcp is ignored
Summary: a hostname set by the kernel / dhcp is ignored
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-14 06:53 UTC by Jörn Dreyer
Modified: 2006-04-21 04:47 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
now in correct order (hostname.patch,960 bytes, patch)
2006-02-14 06:55 UTC, Jörn Dreyer
Details | Diff
new to this ... gotta learn ;) (hostname.patch,1.20 KB, patch)
2006-02-14 10:32 UTC, Jörn Dreyer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jörn Dreyer 2006-02-14 06:53:30 UTC
The current implementation will overwrity any previously set hostname ( kernel / dhcp ) by either the contents of /etc/hostname or ${HOSTNAME} (which is set in /etc/conf.d/hostname, I assume)

This patch will check if the hostname has already been set and ignore any local configuration shoud that be the case. In effect you will only be able to run the script once. I hope this does not raise any problems, does it?
Comment 1 Jörn Dreyer 2006-02-14 06:55:59 UTC
Created attachment 79758 [details, diff]
now in correct order
Comment 2 SpanKY gentoo-dev 2006-02-14 08:08:30 UTC
your patch is reversed
Comment 3 Jörn Dreyer 2006-02-14 08:24:11 UTC
Comment on attachment 79758 [details, diff]
now in correct order

--- hostname.org        2006-02-14 15:09:56.000000000 +0100
+++ hostname    2006-02-14 15:38:07.000000000 +0100
@@ -10,17 +10,16 @@
        local myhost=$(/bin/hostname 2>/dev/null)
        local retval=0

-       # If the hostname is already set via the kernel, and /etc/hostname
-       # isn't setup, then we shouldn't go reseting the configuration #38172.
+       # If the hostname is NOT set already (e.g. via the kernel),
+       # reset the configuration #38172.
        if [[ -z ${myhost} ]] || [[ ${myhost} == "(none)" ]] ; then
-               myhost="localhost"
-       fi
-
-       if [[ -f /etc/hostname ]] ; then
-               ewarn "You should stop using /etc/hostname and use /etc/conf.d/hostname"
-               myhost=$(</etc/hostname)
-       else
-               myhost=${HOSTNAME}
+               # Warn if the old /etc/hostname is still set
+               if [[ -f /etc/hostname ]] ; then
+                       ewarn "You should stop using /etc/hostname and use /etc/conf.d/hostname"
+                       myhost=$(</etc/hostname)
+               else
+                       myhost=${HOSTNAME}
+               fi
        fi

        ebegin "Setting hostname to ${myhost}"
Comment 4 SpanKY gentoo-dev 2006-02-14 08:48:10 UTC
Comment on attachment 79758 [details, diff]
now in correct order

err, please just post a new one
Comment 5 Jörn Dreyer 2006-02-14 10:32:14 UTC
Created attachment 79782 [details, diff]
new to this ... gotta learn ;)
Comment 6 SpanKY gentoo-dev 2006-02-14 21:36:26 UTC
ok, now that i see the patch, current behavior is intended

if you dont want to reset the configuration, dont setup /etc/hostname and/or /etc/conf.d/hostname
Comment 7 Jörn Dreyer 2006-02-22 05:16:05 UTC
(In reply to comment #6)
> if you dont want to reset the configuration, dont setup /etc/hostname and/or
> /etc/conf.d/hostname
I do not have the file /etc/hostname, so the current script will set myhost to ${HOSTNAME} in the else statement. When /etc/conf.d/hostname contains a line like:
HOSTNAME=
or
HOSTNAME=""
or
#HOSTNAME=

The myhost variable will be overwritten and the hostname WILL be set to an empty string (/bin/hostname "${myhost}"). This means that the the configuration will always be overwritten ...

Where am I wrong?
Comment 8 Jörn Dreyer 2006-02-22 05:32:22 UTC
ok ... so I moved /etc/conf.d/hostname to somewhere else, now HOSTNAME is set to the hostname given by dhcp.

The behaviour is somewhat unintuitive, as the /etc/conf.d/hostname will be recreated everytime the baselayout gets updated ... thus people think this file must exist ... maybe an OVERRIDE option like in /etc/conf.d/domainname would be more consistent?

Tell me if I should submit a patch that works like that.
Comment 9 SpanKY gentoo-dev 2006-02-22 16:05:28 UTC
comment out HOSTNAME in your /etc/conf.d/hostname file

i'll update the default
Comment 10 SpanKY gentoo-dev 2006-02-22 19:18:27 UTC
Roy: how does the net scripts in baselayout-1.12.x+ handle this ?  i know we merged the domain name funk ...
Comment 11 Roy Marples (RETIRED) gentoo-dev 2006-02-22 23:34:30 UTC
We only set hostname in our net scripts from DHCP client setup like so

# Configure our hostname - but only if we need it
if [[ -n ${hostname} ]]; then
    x="$( hostname )"
    [[ ${x} == "(none)" || ${x} == "localhost" ]] && hostname "${hostname}"
fi

So if the DHCP client does not set hostname then we don't change it.
Also we only change it if the hostname is not set regardless of what the DHCP client wants.
Comment 12 Roy Marples (RETIRED) gentoo-dev 2006-04-21 04:47:09 UTC
Fixed in baselayout-1.12.0_pre17