public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user]  Problem with gethostname() returning incorrect value
@ 2009-10-12 13:37 Lie Ryan
  2009-10-12 14:41 ` Xavier Parizet
  0 siblings, 1 reply; 4+ messages in thread
From: Lie Ryan @ 2009-10-12 13:37 UTC (permalink / raw
  To: gentoo-user

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>.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-14  8:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-12 13:37 [gentoo-user] Problem with gethostname() returning incorrect value Lie Ryan
2009-10-12 14:41 ` Xavier Parizet
2009-10-12 22:00   ` [gentoo-user] " Lie Ryan
2009-10-14  8:37     ` Lie Ryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox