[pkg-dhcp-devel] Bug#609851: incorrect variables used to set hostname in dhclient-script
Ben Hartshorne
ben at hartshorne.net
Thu Jan 13 03:03:21 UTC 2011
Package: isc-dhcp-client
Version: 4.1.1-P1-15
The logic to set the hostname on boot when that hostname is supplied via
dhcp is not working. Looking at the code in dhclient-script, it appears
flawed. Testing reveals unexpected content in the variables.
My environment: the dhcp server is sending 'option host-name' to send the
hostname to the client. Examining /var/lib/dhcp/dhclient.eth0.leases shows
that the hostname is present. The same environment successfully hands out a
hostname when the system is booted with Lenny; it fails when the system is
booted with Squeeze. Note that I removed /etc/hostname to force it to get
the hostname from dhcp. The hostname is being handed out by a system
running Debian Etch and dhcp3-server 3.0.4-13+etch2
The code that sets the hostname on lenny is as follows:
/sbin/dhclient-script from dhcp3-client version 3.1.1-6+lenny4, lines 102 to
107
set_hostname() {
local current_hostname=$(hostname)
if [ -z "$current_hostname" -o "$current_hostname" = "(none)" ]; then
hostname "$new_host_name"
fi
}
The code that sets the hostname on squeeze is as follows:
/sbin/dhclient-script from isc-dhcp-client version 4.1.1-P1-15, lines 155 to
158
if [ -n "$old_host_name" -a -n "$host_name" -a \
"$host_name" != "$old_host_name" ]; then
hostname "$new_host_name"
fi
The first thing that I believe is a bug is that the if clause tests against
$old_host_name and $host_name, but the hostname is set to $new_host_name.
I put some print statements around this clause to show the contents of the
three variables.
On boot, $old_host_name is empty, $host_name is empty, and $new_host_name
has the hostname given to the machine from dhcp. Since this if clause tests
that both $old_host_name and $host_name are non-empty, the statement to set
the hostname is not executed.
If, after the system has booted, I run '/etc/init.d/networking restart', the
contents of the variables are $old_host_name = the host name assigned by
dhcp, $host_name is empty, and $new_host_name is the hostname assigned by
dhcp. Since $host_name is empty, the statement to set the hostname is not
executed. Note that even though $old_host_name contains the hostname given
out by dhcp, the hosts' name (as shown by running 'hostname') is "(none)".
$old_host_name seems to be incorrectly populated.
I believe the previous behavior of setting current_hostname=$(hostname) and
testing it against "(none)" will cause the system to behave as I expect. I
don't understand why the previous hostname must have content in order for
the new hostname to be set, and it seems as though testing $host_name
instead of $new_host_name is a typo.
Thank you,
-ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/pkg-dhcp-devel/attachments/20110112/e40b4593/attachment.htm>
More information about the pkg-dhcp-devel
mailing list