emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make-network-process's gethostbyname usage


From: Chong Yidong
Subject: Re: make-network-process's gethostbyname usage
Date: Sat, 25 Aug 2007 15:06:10 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

address@hidden (Kim F. Storm) writes:

> Richard Stallman <address@hidden> 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 <netinet/in.h>
+ #include <arpa/nameser.h>
+ #include <resolv.h> ],
+     [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 <netinet/in.h>
+ #include <arpa/nameser.h>
+ #include <resolv.h>
+ #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;
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]