public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Lie Ryan <lie.1296@gmail.com>
To: gentoo-user@lists.gentoo.org
Subject: [gentoo-user]  Problem with gethostname() returning incorrect value
Date: Tue, 13 Oct 2009 00:37:04 +1100	[thread overview]
Message-ID: <havbe8$hj6$1@ger.gmane.org> (raw)

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




             reply	other threads:[~2009-10-12 14:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-12 13:37 Lie Ryan [this message]
2009-10-12 14:41 ` [gentoo-user] Problem with gethostname() returning incorrect value Xavier Parizet
2009-10-12 22:00   ` [gentoo-user] " Lie Ryan
2009-10-14  8:37     ` Lie Ryan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='havbe8$hj6$1@ger.gmane.org' \
    --to=lie.1296@gmail.com \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox