Bug 461933

Summary: Anaconda sets hostname to localhost.localdomain
Product: [Fedora] Fedora Reporter: Orion Poplawski <orion>
Component: NetworkManagerAssignee: Dan Williams <dcbw>
Status: CLOSED NEXTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: dcbw, dchapman, wtogami
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-10-21 18:44:13 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Orion Poplawski 2008-09-11 14:37:39 UTC
Description of problem:

I do pxeboot/ks installs with fixed addresses handed out by dhcp.  In the past, the hostname of the installed system has be set properly.  Now it is set to "localhost.localdomain".

Version-Release number of selected component (if applicable):
11.4.1.3

Some log snippets:

14:01:43 INFO    : moving (1) to step preinstallconfig
14:01:43 DEBUG   : isys.py:mount()- going to mount /selinux on /mnt/sysimage/selinux with options defaults
14:01:43 WARNING : no dev package, going to bind mount /dev
14:01:43 DEBUG   : isys.py:mount()- going to mount /dev on /mnt/sysimage/dev with options defaults,bind
14:01:43 INFO    : self.hostname = localhost.localdomain
14:01:43 INFO    : moving (1) to step installpackages

....

18:16:30 INFO    : Writing main configuration
18:16:47 INFO    : self.hostname = localhost.localdomain
18:16:57 INFO    : moving (1) to step firstboot

Comment 1 David Cantrell 2008-09-19 04:50:02 UTC
This is fixed in the git repo and will be in the next build of anaconda.

Comment 2 Orion Poplawski 2008-09-26 21:38:02 UTC
Still there with 11.4.1.40:

12:13:53 INFO    : moving (1) to step preinstallconfig
12:13:53 DEBUG   : isys.py:mount()- going to mount /selinux on /mnt/sysimage/selinux with options defaults
12:13:53 WARNING : no dev package, going to bind mount /dev
12:13:53 DEBUG   : isys.py:mount()- going to mount /dev on /mnt/sysimage/dev with options defaults,bind
12:13:53 INFO    : self.hostname = localhost.localdomain
12:13:53 INFO    : moving (1) to step installpackages

15:08:49 INFO    : Writing main configuration
15:08:53 INFO    : self.hostname = localhost.localdomain
15:08:57 INFO    : moving (1) to step firstboot

Probably another side affect of moving to NM as NM doesn't set the hostname.

Comment 3 David Cantrell 2008-10-07 03:28:29 UTC
Tested with latest rawhide and this appears to be working now.  So long as you are doing a network-based install, the network connection will come up early and anaconda can figure out your hostname by either asking NetworkManager or trying a DNS lookup on your address.

Comment 4 Orion Poplawski 2008-10-16 22:21:17 UTC
Doesn't work with 11.4.1.49:

08:34:29 DEBUG   : isys.py:mount()- going to mount /dev on /mnt/sysimage/dev with options defaults,bind
08:34:29 INFO    : self.hostname = localhost.localdomain
08:34:29 INFO    : moving (1) to step installpackages
08:34:29 INFO    : Preparing to install packages
09:12:40 WARNING : /usr/lib/anaconda/iw/progress_gui.py:55: GtkWarning: gtk_progress_set_percentage: assertion `percentage >= 0 && percentage <= 1.0' failed
  self.progress.set_fraction(pct)

09:13:06 INFO    : moving (1) to step postinstallconfig
09:13:06 INFO    : moving (1) to step writeconfig
09:13:06 INFO    : Writing main configuration
09:13:10 INFO    : self.hostname = localhost.localdomain
09:13:12 INFO    : moving (1) to step firstboot

NM (which happens all before the above - this is PXE boot/netowrk ks):

<29>Oct 16 08:22:40 NetworkManager: <info>  Setting system hostname to 'test' (from DHCP)
<28>Oct 16 08:22:40 NetworkManager: <WARN>  update_etc_hosts(): update_etc_hosts: couldn'tread /etc/hosts: (4) Failed to open file '/etc/hosts': No such file or directory
<28>Oct 16 08:22:40 NetworkManager: <WARN>  update_etc_hosts(): update_etc_hosts: couldn'tupdate /etc/hosts: (4) Failed to open file '/etc/hosts': No such file or directory
<29>Oct 16 08:22:40 NetworkManager: <info>  Setting system hostname to 'localhost.localdomain' (error updating /etc/hosts)

Comment 5 David Cantrell 2008-10-20 22:23:31 UTC
This looks like a bug in update_etc_hosts() in src/NetworkManagerPolicy.c in NetworkManager.  The call to g_file_set_contents() fails, which causes set_system_hostname() to revert back to localhost.localdomain.

Not sure why g_file_set_contents() is failing.  Reading update_etc_hosts() in NetworkManager, it looks like that function will create /etc/hosts if it doesn't exist, which is what we want.

Comment 6 Dan Williams 2008-10-21 12:54:34 UTC
Any chance we could get the warning message that NM prints out when the g_set_file_contents() call fails?  That'll tell us what's probably going wrong.

Comment 7 Orion Poplawski 2008-10-21 15:57:53 UTC
The problem is that you are not clearing error from the previous g_file_get_contents call that fails.  You probably want:

--- NetworkManager-0.7.0/src/NetworkManagerPolicy.c.error       2008-10-11 12:05:54.000000000 -0600
+++ NetworkManager-0.7.0/src/NetworkManagerPolicy.c     2008-10-21 09:53:53.000000000 -0600
@@ -266,6 +266,7 @@
                nm_warning ("%s: couldn't read " SYSCONFDIR "/hosts: (%d) %s",
                            __func__, error ? error->code : 0,
                            (error && error->message) ? error->message : "(unknown)");
+               g_error_free (error);
        } else {
                lines = g_strsplit_set (contents, "\n\r", 0);
                g_free (contents);
@@ -316,6 +317,7 @@
                nm_warning ("%s: couldn't update " SYSCONFDIR "/hosts: (%d) %s",
                            __func__, error ? error->code : 0,
                            (error && error->message) ? error->message : "(unknown)");
+               g_error_free (error);
        } else
                success = TRUE;

Don't know if you also need to set error to NULL or if g_error_free does that for you.

If run under --no-daemon you see the Glib error:

NetworkManager: <info>  Setting system hostname to 'test' (from DHCP)
NetworkManager: <WARN>  update_etc_hosts(): update_etc_hosts: couldn't read /etc/hosts: (4) Failed to open file '/etc/hosts': No such file or directory
(NetworkManager:3539): GLib-CRITICAL **: g_file_set_contents: assertion `error == NULL || *error == NULL' failed
NetworkManager: <WARN>  update_etc_hosts(): update_etc_hosts: couldn't update /etc/hosts: (4) Failed to open file '/etc/hosts': No such file or directory
NetworkManager: <info>  Setting system hostname to 'localhost.localdomain' (error updating/etc/hosts)

Comment 8 Dan Williams 2008-10-21 17:59:47 UTC
good catch, there probably isn't an /etc/hosts, thus the g_file_get_contents() call fails, and the fact that the error doesn't get reset causes the g_file_set_contents() to fail.

Fixed upstream in svn r4201.

Comment 10 David Cantrell 2008-10-25 02:18:10 UTC
*** Bug 468445 has been marked as a duplicate of this bug. ***

Comment 11 Fedora Update System 2008-11-23 23:04:49 UTC
NetworkManager-0.7.0-0.12.svn4326.fc9,NetworkManager-vpnc-0.7.0-0.11.svn4326.fc9,NetworkManager-openvpn-0.7.0-16.svn4326.fc9,NetworkManager-pptp-0.7.0-0.12.svn4326.fc9 has been submitted as an update for Fedora 9.
http://admin.fedoraproject.org/updates/NetworkManager-0.7.0-0.12.svn4326.fc9,NetworkManager-vpnc-0.7.0-0.11.svn4326.fc9,NetworkManager-openvpn-0.7.0-16.svn4326.fc9,NetworkManager-pptp-0.7.0-0.12.svn4326.fc9

Comment 12 Fedora Update System 2008-11-23 23:07:49 UTC
NetworkManager-0.7.0-0.12.svn4326.fc8,NetworkManager-vpnc-0.7.0-0.11.svn4326.fc8,NetworkManager-openvpn-0.7.0-16.svn4326.fc8,NetworkManager-pptp-0.7.0-0.12.svn4326.fc8 has been submitted as an update for Fedora 8.
http://admin.fedoraproject.org/updates/NetworkManager-0.7.0-0.12.svn4326.fc8,NetworkManager-vpnc-0.7.0-0.11.svn4326.fc8,NetworkManager-openvpn-0.7.0-16.svn4326.fc8,NetworkManager-pptp-0.7.0-0.12.svn4326.fc8

Comment 13 Fedora Update System 2008-12-21 23:37:22 UTC
NetworkManager-0.7.0-0.12.svn4326.fc9, NetworkManager-vpnc-0.7.0-0.11.svn4326.fc9, NetworkManager-openvpn-0.7.0-16.svn4326.fc9, NetworkManager-pptp-0.7.0-0.12.svn4326.fc9 has been pushed to the Fedora 9 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 14 Fedora Update System 2008-12-21 23:43:02 UTC
NetworkManager-0.7.0-0.12.svn4326.fc8, NetworkManager-vpnc-0.7.0-0.11.svn4326.fc8, NetworkManager-openvpn-0.7.0-16.svn4326.fc8, NetworkManager-pptp-0.7.0-0.12.svn4326.fc8 has been pushed to the Fedora 8 stable repository.  If problems still persist, please make note of it in this bug report.