Help!

[gentoo-user] Problem with gethostname() returning incorre..

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> User RSS
Next:  Bug#550720: Fails to launch, with runtime error a..  
Author Message
Lie Ryan
External


Since: Oct 12, 2009
Posts: 3



PostPosted: Mon Oct 12, 2009 11:10 am    Post subject: [gentoo-user] Problem with gethostname() returning incorrect value
Archived from groups: linux>gentoo>user (more info?)

Hi,

First, sorry if this is not the correct list.

Second, the background story...

I was tracking a problem that I have always ignored when updating python
on my Gentoo laptop. The problem is that emerge-ing python always fail
when FEATURES="test" is on. Usually, I would just turn FEATURES="test"
off when updating python, but today I set up to search for the source of
the failure.

After downloading the latest svn version from python and a few hours of
debugging python's test suite; I isolated the problem to this:

lieryan@lieryan ~/Desktop/pythontrunk/trunk $ ./python
Python 2.7a0 (trunk:75376M, Oct 12 2009, 22:17:57)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostname()
'lieryan'
>>> socket.gethostbyname(socket.gethostname())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
>>> socket.gethostbyname('localhost')
'127.0.0.1'

From that, I see that socket.gethostname() returned 'lieryan' which is
my user name; instead of 'localhost' which is the correct local
machine's name.

Tracking the interpreter's source code, it seems that
socket.gethostname() simply returns what the libc's gethostname()
returns; which "man gethostname" says "The GNU C Library ... implements
gethostname() as a library function that calls uname(2)..."

So running "uname -a":
lieryan@lieryan ~/Desktop/pythontrunk/trunk $ uname -a
Linux lieryan 2.6.28-gentoo-r5-LR-15 #14 SMP Tue Oct 6 18:12:23 EST 2009
x86_64 AMD Turion(tm) 64 X2 AuthenticAMD GNU/Linux

So clearly this is an environmental issue.

=============================


It appears that gethostname() returns 'lieryan'; which is my user name
instead of 'localhost' which, I believe, should be the correct hostname
for the machine I'm currently in.

Now I know where the source of the problem is; but I don't know how to
fix it.

Anyone got any idea what I should do to change the return value of
gethostname()?

Googling gethostname() only returned various versions of "gethostname()"
man page. The man pages also mentioned about another libc's function
sethostname() but this system call is not available in python and even
if I write a C script to call sethostname() with the correct value; I
doubt this will really fix the real root cause of the problem.

Anyone got any lead?


Extra information:

lieryan@lieryan ~/Desktop/pythontrunk/trunk $ /lib/libc.so.6
GNU C Library stable release version 2.9, by Roland McGrath et al.
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.3.2.
Compiled on a Linux >>2.6.28-gentoo-r5-LR-12<< system on 2009-07-05.
Available extensions:
C stubs add-on version 2.1.2
crypt add-on version 2.1 by Michael Glad and others
Gentoo snapshot 20081201
Gentoo patchset 5
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
Support for some architectures added on, not maintained in glibc core.
BIND-8.2.3-T5B
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
Back to top
Lie Ryan
External


Since: Oct 12, 2009
Posts: 3



PostPosted: Mon Oct 12, 2009 7:10 pm    Post subject: [gentoo-user] Re: Problem with gethostname() returning incorrect value [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Xavier Parizet wrote:
> Lie Ryan a écrit :
>> Hi,
>>
>> [SNIP]
>>
>> Extra information:
>>
>> lieryan@lieryan ~/Desktop/pythontrunk/trunk $ /lib/libc.so.6
>
> Here the output is clear : lieryan is your machine hostname as well as your
> username... So check your /etc/hosts and either edit the line containing
> 127.0.0.1 like this:
> 127.0.0.1 lieryan.<your dns domain name> lieryan localhost
> or set HOSTNAME variable in /etc/conf.d/hostname to localhost, put the error
> returned by python seems to indicate that you forgot to edit /etc/hosts to put
> the definition of lieryan hostname ip address.
>

Thanks, redirecting 'lieryan' to 127.0.0.1 solves the problem.

Though I'd have preferred not to have my username redirects to the local
machine, changing HOSTNAME in /etc/conf.d/hostname seems to result in
some unwanted side effects[1] to X. I can live with the redirection
though, so problem solved for now.

[1] for some reason, after setting HOSTNAME to localhost I can't start
new GUI program/create new window after NetworkManager/nm-applet is
running. I suspect there is some NetworkManager settings lying around
somewhere that resets the name to lieryan and the change confused X.
Back to top
Lie Ryan
External


Since: Oct 12, 2009
Posts: 3



PostPosted: Thu Oct 15, 2009 8:10 pm    Post subject: [gentoo-user] Re: Problem with gethostname() returning incorrect value [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Lie Ryan wrote:
> [1] for some reason, after setting HOSTNAME to localhost I can't start
> new GUI program/create new window after NetworkManager/nm-applet is
> running. I suspect there is some NetworkManager settings lying around
> somewhere that resets the name to lieryan and the change confused X.

btw, in any case someone in the future is wondering; the
NetworkManager's hostname settings are stored in /etc/dhcp/dhclient.conf

on these line:
send host-name "HOSTNAME";
supersede host-name "HOSTNAME";

after changing both this and the one in /etc/conf.d/hostname the
computer's hostname is changed for good with none of the side effect.
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> User All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum