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

* Re: [gentoo-user]  Problem with gethostname() returning incorrect value
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Xavier Parizet @ 2009-10-12 14:41 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 722 bytes --]

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.

HTH.

> [SNIP]


-- 
      Xavier Parizet
YaGB :   http://gentooist.com
GPG  :    C7DC B10E FC21 63BE
B453 D239 F6E6 DF65 1569 91BF



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 261 bytes --]

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

* [gentoo-user]  Re: Problem with gethostname() returning incorrect   value
  2009-10-12 14:41 ` Xavier Parizet
@ 2009-10-12 22:00   ` Lie Ryan
  2009-10-14  8:37     ` Lie Ryan
  0 siblings, 1 reply; 4+ messages in thread
From: Lie Ryan @ 2009-10-12 22:00 UTC (permalink / raw
  To: gentoo-user

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.




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

* [gentoo-user]  Re: Problem with gethostname() returning incorrect   value
  2009-10-12 22:00   ` [gentoo-user] " Lie Ryan
@ 2009-10-14  8:37     ` Lie Ryan
  0 siblings, 0 replies; 4+ messages in thread
From: Lie Ryan @ 2009-10-14  8:37 UTC (permalink / raw
  To: gentoo-user

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.




^ 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