gethostbyname() and resolv.conf updates
sgallagh at redhat.com
Fri Jun 18 12:23:20 UTC 2010
On 06/17/2010 05:41 PM, Bernie Innocenti wrote:
> xchat in Fedora needs to be restarted after switching to a different
> nameserver or it fails to resolve.
> The xchat developers say that all xchat does is call gethostbyname(). A
> Debian user told me that Debian carries a glibc patch to make processes
> notice resolv.conf updates and reload it.
> Is there any chance we could apply the same patch in Fedora too? I don't
> know all the details, but I guess there might be a good reason why this
> patch wasn't upstreamed yet.
This is the entire purpose of the res_init() function in glibc. If your
application needs to be aware of a change in resolv.conf, you should be
monitoring it with inotify and calling res_init() anytime the file is
I disagree that this is necessarily a bug in glibc, as it allows the
application writer to decide for themselves whether to trust a change to
The easy fix in xchat would be to simply call res_init() immediately
before calling gethostbyname(). It would add a small amount of overhead
to hostname lookups, but it would always work. Monitoring resolv.conf
for changes would be an optimization, of course.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
More information about the devel