Now uses sigsetjmp() and siglongjmp() to bail out from slow name lookups in

case a timeout is set. This seems to work. God knows if it is good enough
or what kind of side-effects we introduce here and now.

I'll close my eyes and cross my fingers. Hard.
This commit is contained in:
Daniel Stenberg 2002-06-11 15:10:18 +00:00
parent 4cfffd6c4a
commit 3c49b405de
3 changed files with 63 additions and 22 deletions

View File

@ -55,26 +55,6 @@ dnl The install stuff has already been taken care of by the automake stuff
dnl AC_PROG_INSTALL dnl AC_PROG_INSTALL
AC_PROG_MAKE_SET AC_PROG_MAKE_SET
dnl ************************************************************
dnl lame option to switch on debug options
dnl
AC_MSG_CHECKING([whether to enable debug options])
AC_ARG_ENABLE(debug,
[ --enable-debug Enable pedantic debug options
--disable-debug Disable debug options],
[ case "$enableval" in
no)
AC_MSG_RESULT(no)
;;
*) AC_MSG_RESULT(yes)
CPPFLAGS="$CPPFLAGS -DMALLOCDEBUG"
CFLAGS="-W -Wall -Wwrite-strings -pedantic -Wundef -Wpointer-arith -Wcast-align -Wnested-externs -g"
;;
esac ],
AC_MSG_RESULT(no)
)
dnl ************************************************************ dnl ************************************************************
dnl switch off particular protocols dnl switch off particular protocols
dnl dnl
@ -623,7 +603,8 @@ AC_CHECK_HEADERS( \
io.h \ io.h \
pwd.h \ pwd.h \
utime.h \ utime.h \
sys/utime.h sys/utime.h \
setjmp.h
) )
dnl Check for libz header dnl Check for libz header
@ -678,9 +659,23 @@ AC_CHECK_FUNCS( socket \
getpwuid \ getpwuid \
geteuid \ geteuid \
dlopen \ dlopen \
utime utime \
sigsetjmp
) )
dnl sigsetjmp() might be a macro and no function so if it isn't found already
dnl we make an extra check here!
if test "$ac_cv_func_sigsetjmp" != "yes"; then
AC_MSG_CHECKING([for sigsetjmp defined as macro])
AC_TRY_LINK( [#include <setjmp.h>],
[sigjmp_buf jmpenv;
sigsetjmp(jmpenv, 1);],
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_SIGSETJMP),
AC_MSG_RESULT(no)
)
fi
dnl removed 'getpass' check on October 26, 2000 dnl removed 'getpass' check on October 26, 2000
if test "$ac_cv_func_select" != "yes"; then if test "$ac_cv_func_select" != "yes"; then
@ -704,6 +699,26 @@ dnl AC_PATH_PROG( RANLIB, ranlib, /usr/bin/ranlib,
dnl $PATH:/usr/bin/:/usr/local/bin ) dnl $PATH:/usr/bin/:/usr/local/bin )
dnl AC_SUBST(RANLIB) dnl AC_SUBST(RANLIB)
dnl ************************************************************
dnl lame option to switch on debug options
dnl
AC_MSG_CHECKING([whether to enable debug options])
AC_ARG_ENABLE(debug,
[ --enable-debug Enable pedantic debug options
--disable-debug Disable debug options],
[ case "$enableval" in
no)
AC_MSG_RESULT(no)
;;
*) AC_MSG_RESULT(yes)
CPPFLAGS="$CPPFLAGS -DMALLOCDEBUG"
CFLAGS="-W -Wall -Wwrite-strings -pedantic -Wundef -Wpointer-arith -Wcast-align -Wnested-externs -g"
;;
esac ],
AC_MSG_RESULT(no)
)
AC_CONFIG_FILES([Makefile \ AC_CONFIG_FILES([Makefile \
docs/Makefile \ docs/Makefile \
docs/examples/Makefile \ docs/examples/Makefile \

View File

@ -56,6 +56,10 @@
#endif #endif
#endif #endif
#ifdef HAVE_SETJMP_H
#include <setjmp.h>
#endif
#include "urldata.h" #include "urldata.h"
#include "sendf.h" #include "sendf.h"
#include "hostip.h" #include "hostip.h"
@ -191,6 +195,11 @@ hostcache_prune(curl_hash *hostcache, int cache_timeout, int now)
return (__v); \ return (__v); \
} }
#ifdef HAVE_SIGSETJMP
/* Beware this is a global and unique instance */
sigjmp_buf curl_jmpenv;
#endif
Curl_addrinfo *Curl_resolv(struct SessionHandle *data, Curl_addrinfo *Curl_resolv(struct SessionHandle *data,
char *hostname, char *hostname,
int port) int port)
@ -201,6 +210,14 @@ Curl_addrinfo *Curl_resolv(struct SessionHandle *data,
time_t now; time_t now;
char *bufp; char *bufp;
#ifdef HAVE_SIGSETJMP
if(sigsetjmp(curl_jmpenv, 1) != 0) {
/* this is coming from a siglongjmp() */
failf(data, "name lookup time-outed");
return NULL;
}
#endif
/* If the host cache timeout is 0, we don't do DNS cach'ing /* If the host cache timeout is 0, we don't do DNS cach'ing
so fall through */ so fall through */
if (data->set.dns_cache_timeout == 0) { if (data->set.dns_cache_timeout == 0) {

View File

@ -72,6 +72,10 @@
#include <inet.h> #include <inet.h>
#endif #endif
#ifdef HAVE_SETJMP_H
#include <setjmp.h>
#endif
#ifndef HAVE_SELECT #ifndef HAVE_SELECT
#error "We can't compile without select() support!" #error "We can't compile without select() support!"
#endif #endif
@ -120,6 +124,7 @@
#ifdef KRB4 #ifdef KRB4
#include "security.h" #include "security.h"
#endif #endif
/* The last #include file should be: */ /* The last #include file should be: */
#ifdef MALLOCDEBUG #ifdef MALLOCDEBUG
#include "memdebug.h" #include "memdebug.h"
@ -143,6 +148,10 @@ RETSIGTYPE alarmfunc(int signal)
{ {
/* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */ /* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */
(void)signal; (void)signal;
#ifdef HAVE_SIGSETJMP
extern sigjmp_buf curl_jmpenv;
siglongjmp(curl_jmpenv, 1);
#endif
return; return;
} }
#endif #endif