From 162c2794ea6b1b821b57facc923e5a861db9069b Mon Sep 17 00:00:00 2001 From: Robert Ricci Date: Wed, 2 Apr 2003 23:14:17 +0000 Subject: [PATCH] Change the way we handle the localhost alias - it's unqualified in the hosts files that we put on free nodes. For reserved nodes, we start a new hosts file from scrath, and qualify localhost with the domain found from the hostname command. --- tmcd/common/libsetup.pm | 30 +++++++++++++++++++++--------- tmcd/freebsd/hosts | 2 +- tmcd/libsetup.pm | 30 +++++++++++++++++++++--------- tmcd/linux/hosts | 2 +- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/tmcd/common/libsetup.pm b/tmcd/common/libsetup.pm index 7cdcaa0d8..82a455406 100644 --- a/tmcd/common/libsetup.pm +++ b/tmcd/common/libsetup.pm @@ -991,19 +991,31 @@ sub dohostnames () my $TM; # - # Start with fresh copy, since the hosts files is potentially updated - # after the node boots via the update command. - # - if (system($CP, "-f", TMHOSTS, HOSTSFILE) != 0) { - printf STDERR "Could not copy default %s into place: $!\n", HOSTSFILE; - return 1; - } - + # Note, we no longer start with the 'prototype' file here, because we have + # to make up a localhost line that's properly qualified. + # + $TM = OPENTMCC(TMCCCMD_HOSTS); - open(HOSTS, ">>" . HOSTSFILE) + open(HOSTS, ">" . HOSTSFILE) or die("Could not open $HOSTSFILE: $!"); + my $localaliases = "loghost"; + + # + # Find out our domain name, so that we can qualify the localhost entry + # + my $hostname = `hostname`; + if ($hostname =~ /[^.]+\.(.+)/) { + $localaliases .= " localhost.$1"; + } + + # + # First, write a localhost line into the hosts file - we have to know the + # domain to use here + # + print HOSTS os_etchosts_line("localhost", "127.0.0.1", $localaliases), "\n"; + # # Now convert each hostname into hosts file representation and write # it to the hosts file. Note that ALIASES is for backwards compat. diff --git a/tmcd/freebsd/hosts b/tmcd/freebsd/hosts index 57eae2e96..ee6c1c0b2 100644 --- a/tmcd/freebsd/hosts +++ b/tmcd/freebsd/hosts @@ -7,5 +7,5 @@ # not be consulted at all; see /etc/host.conf for the resolution order. # # -127.0.0.1 localhost localhost.emulab.net loghost +127.0.0.1 localhost loghost diff --git a/tmcd/libsetup.pm b/tmcd/libsetup.pm index 7cdcaa0d8..82a455406 100644 --- a/tmcd/libsetup.pm +++ b/tmcd/libsetup.pm @@ -991,19 +991,31 @@ sub dohostnames () my $TM; # - # Start with fresh copy, since the hosts files is potentially updated - # after the node boots via the update command. - # - if (system($CP, "-f", TMHOSTS, HOSTSFILE) != 0) { - printf STDERR "Could not copy default %s into place: $!\n", HOSTSFILE; - return 1; - } - + # Note, we no longer start with the 'prototype' file here, because we have + # to make up a localhost line that's properly qualified. + # + $TM = OPENTMCC(TMCCCMD_HOSTS); - open(HOSTS, ">>" . HOSTSFILE) + open(HOSTS, ">" . HOSTSFILE) or die("Could not open $HOSTSFILE: $!"); + my $localaliases = "loghost"; + + # + # Find out our domain name, so that we can qualify the localhost entry + # + my $hostname = `hostname`; + if ($hostname =~ /[^.]+\.(.+)/) { + $localaliases .= " localhost.$1"; + } + + # + # First, write a localhost line into the hosts file - we have to know the + # domain to use here + # + print HOSTS os_etchosts_line("localhost", "127.0.0.1", $localaliases), "\n"; + # # Now convert each hostname into hosts file representation and write # it to the hosts file. Note that ALIASES is for backwards compat. diff --git a/tmcd/linux/hosts b/tmcd/linux/hosts index 84bf5c146..943b36ace 100644 --- a/tmcd/linux/hosts +++ b/tmcd/linux/hosts @@ -1,5 +1,5 @@ # # Hosts Database. # -127.0.0.1 localhost localhost.emulab.net loghost +127.0.0.1 localhost loghost -- GitLab