From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: make-network-process's gethostbyname usage Date: Sat, 25 Aug 2007 15:06:10 -0400 Message-ID: <87d4xb304d.fsf@stupidchicken.com> References: <87hcmueg90.fsf@myxomop.com> <87veb8orkl.fsf@kfs-lx.testafd.dk> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1188069081 15023 80.91.229.12 (25 Aug 2007 19:11:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 25 Aug 2007 19:11:21 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org To: storm@cua.dk (Kim F. Storm) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Aug 25 21:11:18 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IP12S-0002TZ-Mw for ged-emacs-devel@m.gmane.org; Sat, 25 Aug 2007 21:11:16 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IP12R-0000zy-Pi for ged-emacs-devel@m.gmane.org; Sat, 25 Aug 2007 15:11:15 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IP12N-0000z4-4h for emacs-devel@gnu.org; Sat, 25 Aug 2007 15:11:11 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IP12M-0000yi-Hw for emacs-devel@gnu.org; Sat, 25 Aug 2007 15:11:10 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IP12M-0000yd-Bs for emacs-devel@gnu.org; Sat, 25 Aug 2007 15:11:10 -0400 Original-Received: from cyd.mit.edu ([18.115.2.24]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IP12I-0006jG-Di; Sat, 25 Aug 2007 15:11:06 -0400 Original-Received: by cyd.mit.edu (Postfix, from userid 1000) id BE9D94E36B; Sat, 25 Aug 2007 15:06:10 -0400 (EDT) In-Reply-To: <87veb8orkl.fsf@kfs-lx.testafd.dk> (Kim F. Storm's message of "Wed\, 22 Aug 2007 11\:18\:34 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) X-Detected-Kernel: Linux 2.6 (newer, 1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:77134 Archived-At: storm@cua.dk (Kim F. Storm) writes: > Richard Stallman writes: > >> make-network-process calles gethostbyname, but never calls >> res_init. The problem, which appears is: if contents of >> /etc/resolv.conf was changed old dns servers are unavailable, >> gethostbyname still tries them, not new ones. So this bug is pretty >> much the same as http://bugs.debian.org/438680 (which has a patch). >> >> Would someone please DTRT about this, then ack? >> It needs to be fixed in Emacs 22. > > I don't know what to do about this. > > configure already has a check for res_init, but on my system (GNU/Linux), > HAVE_RES_INIT is undefined, indicating that it doesn't exist. > > However, I believe that it does exist, but only if -lresolv is specified. > > So how can we fix configure to DTRT? See the attached patch. Strangely enough, even though autoconf needs -lresolv to detect res_init(), it doesn't seem as though we need to add -lresolv when compiling Emacs itself. I don't know why this should be the case. Does anyone have an idea? *** emacs/configure.in.~1.444.2.2.~ 2007-08-22 17:50:31.000000000 -0400 --- emacs/configure.in 2007-08-25 14:34:43.000000000 -0400 *************** *** 2580,2586 **** AC_CHECK_FUNCS(gethostname getdomainname dup2 \ rename closedir mkdir rmdir sysinfo getrusage get_current_dir_name \ ! random lrand48 bcopy bcmp logb frexp fmod rint cbrt ftime res_init setsid \ strerror fpathconf select mktime euidaccess getpagesize tzset setlocale \ utimes setrlimit setpgid getcwd getwd shutdown getaddrinfo \ __fpending mblen mbrlen mbsinit strsignal setitimer ualarm index rindex \ --- 2580,2586 ---- AC_CHECK_FUNCS(gethostname getdomainname dup2 \ rename closedir mkdir rmdir sysinfo getrusage get_current_dir_name \ ! random lrand48 bcopy bcmp logb frexp fmod rint cbrt ftime setsid \ strerror fpathconf select mktime euidaccess getpagesize tzset setlocale \ utimes setrlimit setpgid getcwd getwd shutdown getaddrinfo \ __fpending mblen mbrlen mbsinit strsignal setitimer ualarm index rindex \ *************** *** 2624,2640 **** # than to expect to find it in ncurses. AC_CHECK_LIB(ncurses, tparm) # Do we need the Hesiod library to provide the support routines? if test "$with_hesiod" = yes ; then # Don't set $LIBS here -- see comments above. - resolv=no AC_CHECK_FUNC(res_send, , [AC_CHECK_FUNC(__res_send, , [AC_CHECK_LIB(resolv, res_send, resolv=yes, [AC_CHECK_LIB(resolv, __res_send, resolv=yes)])])]) if test "$resolv" = yes ; then RESOLVLIB=-lresolv - AC_DEFINE(HAVE_LIBRESOLV, 1, - [Define to 1 if you have the resolv library (-lresolv).]) else RESOLVLIB= fi --- 2624,2662 ---- # than to expect to find it in ncurses. AC_CHECK_LIB(ncurses, tparm) + resolv=no + + # Do we have res_init, for detecting changes in /etc/resolv.conf? + + AC_CHECK_FUNC(res_init, have_res_init=yes, have_res_init=no) + if test "$have_res_init" = no; then + OLIBS="$LIBS" + LIBS="$LIBS -lresolv" + AC_MSG_CHECKING(for res_init with -lresolv) + AC_TRY_LINK([#include + #include + #include ], + [res_init();], + have_res_init=yes, have_res_init=no) + AC_MSG_RESULT($have_res_init) + if test "$have_res_init" = yes ; then + resolv=yes + fi + LIBS="$OLIBS" + fi + + if test "$have_res_init" = yes; then + AC_DEFINE(HAVE_RES_INIT, 1, [Define to 1 if res_init is available.]) + fi + # Do we need the Hesiod library to provide the support routines? if test "$with_hesiod" = yes ; then # Don't set $LIBS here -- see comments above. AC_CHECK_FUNC(res_send, , [AC_CHECK_FUNC(__res_send, , [AC_CHECK_LIB(resolv, res_send, resolv=yes, [AC_CHECK_LIB(resolv, __res_send, resolv=yes)])])]) if test "$resolv" = yes ; then RESOLVLIB=-lresolv else RESOLVLIB= fi *************** *** 2644,2649 **** --- 2666,2677 ---- :, $RESOLVLIB)]) fi + # Do we need libresolv (due to res_init or Hesiod)? + if test "$resolv" = yes ; then + AC_DEFINE(HAVE_LIBRESOLV, 1, + [Define to 1 if you have the resolv library (-lresolv).]) + fi + # These tell us which Kerberos-related libraries to use. if test "${with_kerberos+set}" = set; then AC_CHECK_LIB(com_err, com_err) *** emacs/src/process.c.~1.512.2.4.~ 2007-08-08 14:07:26.000000000 -0400 --- emacs/src/process.c 2007-08-25 14:56:59.000000000 -0400 *************** *** 129,134 **** --- 129,140 ---- # endif #endif + #ifdef HAVE_RES_INIT + #include + #include + #include + #endif + #include "lisp.h" #include "systime.h" #include "systty.h" *************** *** 3082,3087 **** --- 3088,3098 ---- hints.ai_family = family; hints.ai_socktype = socktype; hints.ai_protocol = 0; + + #ifdef HAVE_RES_INIT + res_init (); + #endif + ret = getaddrinfo (SDATA (host), portstring, &hints, &res); if (ret) #ifdef HAVE_GAI_STRERROR *************** *** 3127,3132 **** --- 3138,3148 ---- as it may `hang' Emacs for a very long time. */ immediate_quit = 1; QUIT; + + #ifdef HAVE_RES_INIT + res_init (); + #endif + host_info_ptr = gethostbyname (SDATA (host)); immediate_quit = 0;