16.12.2013 06:29, Denys Vlasenko пишет:
> On Monday 09 December 2013 18:56, Michael Tokarev wrote:
>> There's no reason to call gethostbyname() on the value returned
>> by uname() when asked just for a short name of a host.  This may
>> also be wrong, when uname is set to one value, but in /etc/hosts
>> (or elsewhere) the "canonical" name is different.  This is often
>> the case for localhost entry in /etc/hosts:
>>
>>   127.0.0.1  localhost       myname
>>
>> With this content of /etc/hosts, and uname being set to myname,
>> busybox hostname -s will return localhost, while regular
>> hostname utility returns myname.
> 
> Can you send strace of regular hostname's run?
> I would like to see whether it does any name resolution...

Well. That's in fact *exactly* what I did here to find out why they
differ.

Here we go:

$ strace hostname
...
brk(0)                                  = 0x232b000
brk(0x234c000)                          = 0x234c000
uname({sys="Linux", node="gandalf", ...}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7fdd63c9a000
write(1, "gandalf\n", 8gandalf
)                = 8
exit_group(0)                           = ?

(it isn't interesting to see anything before the call to uname(2),
since it is the only way to get system name which might be processed
further using dns).

$ strace hostname -s
...
brk(0)                                  = 0x8ca000
brk(0x8eb000)                           = 0x8eb000
uname({sys="Linux", node="gandalf", ...}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f4f34853000
write(1, "gandalf\n", 8gandalf
)                = 8
exit_group(0)                           = ?


With a "long" hostname:

# hostname gandalf.local

$ strace hostname -s
...
brk(0)                                  = 0xe71000
brk(0xe92000)                           = 0xe92000
uname({sys="Linux", node="gandalf.local", ...}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f9364ec4000
write(1, "gandalf\n", 8gandalf
)                = 8
exit_group(0)                           = ?

$ strace hostname
...
brk(0)                                  = 0x25b1000
brk(0x25d2000)                          = 0x25d2000
uname({sys="Linux", node="gandalf.local", ...}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f2f185b8000
write(1, "gandalf.local\n", 14gandalf.local
)         = 14
exit_group(0)                           = ?


In other words, without -d (domain) or -f (fqdn), hostname just
does the string operations against the result of uname(2).

However, with -d or -f added (with or withot -s), it calls
gethostbyname(), and strace shows this too (not provided, it
is quite large).

Thanks,

/mjt
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to