also backup doc/pdf
[privoxy.git] / debian / patches / 18_dns_retry.dpatch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 18_dns_retry.dpatch by Fabian Keil <fk@fabiankeil.de>
3 ##
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Retries DNS queries 10 times before giving up.
6 ## DP: Extracted from http://www.fabiankeil.de/sourcecode/privoxy/
7
8 @DPATCH@
9 diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
10 --- privoxy~/jbsockets.c
11 +++ privoxy/jbsockets.c
12 @@ -780,6 +780,7 @@
13  {
14     struct sockaddr_in inaddr;
15     struct hostent *hostp;
16 +   unsigned int dns_retries = 0;
17  #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS) || defined(HAVE_GETHOSTBYNAME_R_5_ARGS) || defined(HAVE_GETHOSTBYNAME_R_3_ARGS)
18     struct hostent result;
19  #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS) || defined(HAVE_GETHOSTBYNAME_R_5_ARGS)
20 @@ -800,8 +801,13 @@
21     if ((inaddr.sin_addr.s_addr = inet_addr(host)) == -1)
22     {
23  #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS)
24 -      gethostbyname_r(host, &result, hbuf,
25 -                      HOSTENT_BUFFER_SIZE, &hostp, &thd_err);
26 +               while ( gethostbyname_r(host, &result, hbuf,
27 +                                                                               HOSTENT_BUFFER_SIZE, &hostp, &thd_err)
28 +                                 && (thd_err == TRY_AGAIN) && (dns_retries++ < 10) )
29 +               {   
30 +                 log_error(LOG_LEVEL_ERROR, "Timeout #%u while trying to resolve %s. Trying again.",
31 +                                               dns_retries, host);
32 +      }
33  #elif defined(HAVE_GETHOSTBYNAME_R_5_ARGS)
34        hostp = gethostbyname_r(host, &result, hbuf,
35                        HOSTENT_BUFFER_SIZE, &thd_err);
36 @@ -816,10 +822,20 @@
37        }
38  #elif OSX_DARWIN
39        pthread_mutex_lock(&gethostbyname_mutex);
40 -      hostp = gethostbyname(host);
41 +               while ( NULL == (hostp = gethostbyname(host))
42 +                                 && (h_errno == TRY_AGAIN) && (dns_retries++ < 10) )
43 +               {   
44 +                 log_error(LOG_LEVEL_ERROR, "Timeout #%u while trying to resolve %s. Trying again.",
45 +                                               dns_retries, host);
46 +      }
47        pthread_mutex_unlock(&gethostbyname_mutex);
48  #else
49 -      hostp = gethostbyname(host);
50 +      while ( NULL == (hostp = gethostbyname(host))
51 +            && (h_errno == TRY_AGAIN) && (dns_retries++ < 10) )
52 +      {
53 +         log_error(LOG_LEVEL_ERROR, "%u. timeout while trying to resolve %s. Trying again.",
54 +                                                dns_retries, host);
55 +      }
56  #endif /* def HAVE_GETHOSTBYNAME_R_(6|5|3)_ARGS */
57        /*
58         * On Mac OSX, if a domain exists but doesn't have a type A