Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Mar 2001 10:14:37 -0800 (PST)
From:      David Wolfskill <david@catwhisker.org>
To:        mobile@freebsd.org
Subject:   Indeterminate hostnames, XFree86-4, & xdm -- (finally!) works for me
Message-ID:  <200103201814.f2KIEba90498@bunrab.catwhisker.org>

next in thread | raw e-mail | index | archive | help
As noted in the recent past, I've been pretty happy with the laptop I'm
using (very similar to a Dell Inspiron 5000e, for reference); since it
uses the (oddball) screen size of 1400x1050 with an ATI Rage 128 Mobility
video "card", I installed the XFree96-4 port, which was 4.0.2.  And I
recently noted that the port had been updated, so I did a re-install, and
it now reports 4.0.3.

And things work pretty well... except I was having a problem in those
(admittedly rare) cases when I have no network connection.  But I solved
it, so I thought I'd send this note out in case anyone else found the
information of use or interest.

Since the machine migrates from one environment to another, it is set up
as a DHCP client.  Although I gather that I could set it up to "lay
claim" to some hostname of my choice, I prefer to let the DHCP server
make the choice.  (I'm really lousy at naming things.)

And this was working fine at home (where the DHCP server is the one
bundled in with Solaris 2.6), but rather less well at work (a customized
one based on the ISC DHCP server), where the DHCP server is set up to
use whatever hostname the client requests (but, apparently, not for the
DHCP server to select one if the client doesn't express a preference).

So I hacked up a bit of code (mostly extracted out of
/sbin/dhclient-script), and called it /etc/dhclient-exit-hooks:


#! /bin/sh

if [ -x /usr/bin/logger ]; then
        LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
else
        LOGGER=echo
fi
  
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
   [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
  current_hostname=`/bin/hostname`
  if [ x$current_hostname = x ]; then
    new_host_name=`host $new_ip_address | sed -e 's/^.*domain name pointer //'`
    $LOGGER "New Hostname: $new_host_name"
    hostname $new_host_name
  fi
fi

exit 0


And this (hack though it is) -- mostly -- works just fine.

When it fails is when (for whatever reason) I don't have a network
connection.  (Confession:  I use Cisco/Aironet 802.11 stuff both at work
and at home, so I suppose I'm "spoiled".)  But since I usually do have
access to a network, this has been more of an annoyance than a real
problem.

But I thought I understood X well enough that I should be able to figure
out what the cause of the'"Xlib: connection to ":0.0" refused by server'
message was, and fix it.

It turns out that the problem is the lack of a hostname.  Since I wanted
the laptop to use whatever hostname it got, I didn't define one in
/etc/rc.conf.  By defining the hostname as "localhost", the no-network
case was solved.

Of course, that breaks the dhclient-exit-hooks hack, so I hacked that
hack to (now) read:


#! /bin/sh

if [ -x /usr/bin/logger ]; then
        LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
else
        LOGGER=echo
fi
  
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
   [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
  current_hostname=`/bin/hostname`
  if [ x$current_hostname = x ] || [ x$current_hostname = xlocalhost ]; then
    new_host_name=`host $new_ip_address | sed -e 's/^.*domain name pointer //'`
    $LOGGER "New Hostname: $new_host_name"
    hostname $new_host_name
  fi
fi

exit 0


That is, replace the hostname if we don't have one or if it is just
"localhost".  (I *did* admit that it's a hack, folks...)

And now, it uses the hostname assigned by the DHCP server if that's
available, and falls back to "localhost" otherwise.  Since "localhost"
is defined in /etc/hosts (using the loopback IP address), the X11
connection works just fine.

Well, I did find it helpful to stick a 15-second delay in
/usr/local/etc/rc.d/apache.sh.  :-}  [My niece thinks it's weird to run
a Web server on a laptop....]

I do rather wonder, though, if it might be a Good Thing to have hostname
default to "localhost" rather than an empty string....  :-}

Cheers,
david
-- 
David H. Wolfskill				david@catwhisker.org
As a computing professional, I believe it would be unethical for me to
advise, recommend, or support the use (save possibly for personal
amusement) of any product that is or depends on any Microsoft product.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-mobile" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103201814.f2KIEba90498>