cURL / Mailing Lists / curl-library / Single Mail


Re: curl/c-ares problem with a chroot'ed program

From: Dan Fandrich <>
Date: Wed, 4 Feb 2004 16:04:09 -0800

On Wed, Feb 04, 2004 at 06:32:18PM -0500, codemastr wrote:
> Ok here's the problem. libcurl calls ares_init() in Curl_addrinfo().
> Curl_addrinfo() is called for each download. Here is the problem,
> ares_init() loads /etc/resolv.conf. Once my program does chroot(),
> /etc/resolv.conf is now "outside the root" and therefore inaccessible. As a
> result, c-ares and libcurl can no longer determine my nameserver info.
> There is a solution I've come up with that is the best I can think of.
> (maybe someone can come up with a better method of implementation).
> CURL_GLOBAL_ARES. If this is set in curl_global_init, then curl will call
> ares_init, store the results in a global var (could result in threading
> issues, though this global var should never be modified, only read therefore
> I can't forsee any...), then Curl_addrinfo() will no longer call
> ares_init(), instead, it will simply use this global var.
> If CURL_GLOBAL_ARES is _not_ specified then everything works as it currently
> does.
> This should solve the problem since as long as I call curl_global_init
> before chroot(), curl will store the resolv.conf info and it will work. This
> also serves to make things faster since it doesn't have to read a file (or
> on win look in the registry) each time a DNS query is to be made...
> Suggestions/comments?

This proposed solution will have a problem with long-running apps on
hosts with DHCP-assigned IP addressies or portable hosts. If a new DNS
address is configured in /etc/resolv.conf due to a DHCP lease expiring or a
laptop user moving into a new WiFi hotspot (for example) then libcurl could
stop resolving hosts. There has to be some way to check for changes in
/etc/resolv.conf at run time. It doesn't necessarily have to be on every
lookup; it may be good enough in practise to reload it just when a lookup

>>> Dan

--              The web change of address service
          Let webmasters know that your web site has moved
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
Received on 2004-02-05