]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
CUPS now reinitializes the DNS resolver on failures (STR #2920)
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Sat, 6 Sep 2008 00:25:17 +0000 (00:25 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Sat, 6 Sep 2008 00:25:17 +0000 (00:25 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@7910 7a7537e8-13f0-0310-91df-b6672ffda945

CHANGES-1.3.txt
backend/Dependencies
config-scripts/cups-network.m4
config.h.in
cups/Dependencies
cups/globals.h
cups/http-addr.c
cups/http-addrlist.c
notifier/Dependencies

index d5a6fcb3080b1e77b74c6eb7efd379bcefaa11a4..df639869dec93e9e1444806d92a4a4225acc7324 100644 (file)
@@ -4,6 +4,8 @@ CHANGES-1.3.txt
 CHANGES IN CUPS V1.3.9
 
        - Documentation updates (STR #2904)
+       - CUPS now reinitializes the DNS resolver on failures
+         (STR #2920)
        - The CUPS desktop menu item was broken (STR #2924)
        - The PPD parser was too strict about missing keyword
          values in "relaxed" mode.
index ecd5b130f679043ec36d27589e40d51a96db90cf..9051be05c3d90cf1d7ee81413977ddcefa7e3fef 100644 (file)
@@ -12,12 +12,12 @@ lpd.o: ../cups/backend.h ../cups/sidechannel.h ../cups/ppd-private.h
 lpd.o: ../cups/cups.h ../cups/ppd.h ../cups/array.h ../cups/file.h
 lpd.o: ../cups/language.h ../cups/debug.h ../cups/i18n.h ../cups/transcode.h
 lpd.o: ../cups/snmp-private.h ../cups/string.h
-mdns.o: backend-private.h ../cups/backend.h ../cups/versioning.h
-mdns.o: ../cups/sidechannel.h ../cups/ppd-private.h ../cups/cups.h
-mdns.o: ../cups/ipp.h ../cups/http.h ../cups/ppd.h ../cups/array.h
-mdns.o: ../cups/file.h ../cups/language.h ../cups/debug.h ../cups/i18n.h
-mdns.o: ../cups/transcode.h ../cups/snmp-private.h ../cups/string.h
-mdns.o: ../config.h ../cups/array.h
+dnssd.o: backend-private.h ../cups/backend.h ../cups/versioning.h
+dnssd.o: ../cups/sidechannel.h ../cups/ppd-private.h ../cups/cups.h
+dnssd.o: ../cups/ipp.h ../cups/http.h ../cups/ppd.h ../cups/array.h
+dnssd.o: ../cups/file.h ../cups/language.h ../cups/debug.h ../cups/i18n.h
+dnssd.o: ../cups/transcode.h ../cups/snmp-private.h ../cups/string.h
+dnssd.o: ../config.h ../cups/array.h
 pap.o: ../config.h ../cups/cups.h ../cups/ipp.h ../cups/http.h
 pap.o: ../cups/versioning.h ../cups/ppd.h ../cups/array.h ../cups/file.h
 pap.o: ../cups/language.h ../cups/backend.h ../cups/sidechannel.h
@@ -68,7 +68,9 @@ testsupplies.o: ../cups/ipp.h ../cups/http.h ../cups/ppd.h ../cups/array.h
 testsupplies.o: ../cups/file.h ../cups/language.h ../cups/debug.h
 testsupplies.o: ../cups/i18n.h ../cups/transcode.h ../cups/snmp-private.h
 testsupplies.o: ../cups/string.h ../config.h
-usb.o: ../cups/backend.h ../cups/versioning.h ../cups/cups.h ../cups/ipp.h
-usb.o: ../cups/http.h ../cups/ppd.h ../cups/array.h ../cups/file.h
-usb.o: ../cups/language.h ../cups/string.h ../config.h ../cups/i18n.h
-usb.o: ../cups/transcode.h
+usb.o: backend-private.h ../cups/backend.h ../cups/versioning.h
+usb.o: ../cups/sidechannel.h ../cups/ppd-private.h ../cups/cups.h
+usb.o: ../cups/ipp.h ../cups/http.h ../cups/ppd.h ../cups/array.h
+usb.o: ../cups/file.h ../cups/language.h ../cups/debug.h ../cups/i18n.h
+usb.o: ../cups/transcode.h ../cups/snmp-private.h ../cups/string.h
+usb.o: ../config.h
index 818abcef6c6764c6175e931d225490d74937c98e..2788d99efa9e3381123aefde3f843a4a8e8b52a0 100644 (file)
@@ -3,7 +3,7 @@ dnl "$Id$"
 dnl
 dnl   Networking stuff for the Common UNIX Printing System (CUPS).
 dnl
-dnl   Copyright 2007 by Apple Inc.
+dnl   Copyright 2007-2008 by Apple Inc.
 dnl   Copyright 1997-2005 by Easy Software Products, all rights reserved.
 dnl
 dnl   These coded instructions, statements, and computer programs are the
@@ -13,11 +13,14 @@ dnl   which should have been included with this file.  If this file is
 dnl   file is missing or damaged, see the license at "http://www.cups.org/".
 dnl
 
+AC_CHECK_HEADER(resolv.h,AC_DEFINE(HAVE_RESOLV_H))
 AC_SEARCH_LIBS(socket, socket)
 AC_SEARCH_LIBS(gethostbyaddr, nsl)
 AC_SEARCH_LIBS(getifaddrs, nsl, AC_DEFINE(HAVE_GETIFADDRS))
 AC_SEARCH_LIBS(hstrerror, nsl socket resolv, AC_DEFINE(HAVE_HSTRERROR))
 AC_SEARCH_LIBS(rresvport_af, nsl, AC_DEFINE(HAVE_RRESVPORT_AF))
+AC_SEARCH_LIBS(res_init, resolv bind, AC_DEFINE(HAVE_RES_INIT),
+       AC_SEARCH_LIBS(__res_init, resolv bind, AC_DEFINE(HAVE_RES_INIT)))
 
 # Tru64 5.1b leaks file descriptors with these functions; disable until
 # we can come up with a test for this...
index d9d41164d53ad71d1a1672f58708453b9bc550f3..7b4c4b54759ad6890603f0c7571962ab092fb158 100644 (file)
 #undef HAVE_HSTRERROR
 
 
+/*
+ * Do we have res_init()?
+ */
+
+#undef HAVE_RES_INIT
+
+
+/*
+ * Do we have <resolv.h>
+ */
+
+#undef HAVE_RESOLV_H
+
+
 /*
  * Do we have the <sys/sockio.h> header file?
  */
index 7a32226fb15e6ea0327613126a24643e47262c01..b1336d501f6d53bf9e2faca68544c10347a9620a 100644 (file)
@@ -46,8 +46,8 @@ globals.o: i18n.h transcode.h
 http.o: http-private.h ../config.h http.h versioning.h md5.h ipp-private.h
 http.o: ipp.h globals.h string.h cups.h ppd.h array.h file.h language.h
 http.o: i18n.h transcode.h debug.h
-http-addr.o: globals.h string.h ../config.h http-private.h http.h
-http-addr.o: versioning.h md5.h ipp-private.h ipp.h cups.h ppd.h array.h
+http-addr.o: http-private.h ../config.h http.h versioning.h md5.h
+http-addr.o: ipp-private.h ipp.h globals.h string.h cups.h ppd.h array.h
 http-addr.o: file.h language.h i18n.h transcode.h debug.h
 http-addrlist.o: http-private.h ../config.h http.h versioning.h md5.h
 http-addrlist.o: ipp-private.h ipp.h globals.h string.h cups.h ppd.h array.h
@@ -109,6 +109,8 @@ testadmin.o: adminutil.h cups.h ipp.h http.h versioning.h ppd.h array.h
 testadmin.o: file.h language.h string.h ../config.h
 testarray.o: ../cups/string.h ../config.h string.h array.h versioning.h dir.h
 testarray.o: debug.h
+testconflicts.o: cups.h ipp.h http.h versioning.h ppd.h array.h file.h
+testconflicts.o: language.h string.h ../config.h
 testcups.o: cups.h ipp.h http.h versioning.h ppd.h array.h file.h language.h
 testfile.o: string.h ../config.h file.h versioning.h debug.h
 testhttp.o: http-private.h ../config.h http.h versioning.h md5.h
@@ -172,8 +174,8 @@ globals.32.o: globals.c  i18n.h transcode.h
 http.32.o: http.c  http-private.h ../config.h http.h versioning.h md5.h ipp-private.h
 http.32.o: http.c  ipp.h globals.h string.h cups.h ppd.h array.h file.h language.h
 http.32.o: http.c  i18n.h transcode.h debug.h
-http-addr.32.o: http-addr.c  globals.h string.h ../config.h http-private.h http.h
-http-addr.32.o: http-addr.c  versioning.h md5.h ipp-private.h ipp.h cups.h ppd.h array.h
+http-addr.32.o: http-addr.c  http-private.h ../config.h http.h versioning.h md5.h
+http-addr.32.o: http-addr.c  ipp-private.h ipp.h globals.h string.h cups.h ppd.h array.h
 http-addr.32.o: http-addr.c  file.h language.h i18n.h transcode.h debug.h
 http-addrlist.32.o: http-addrlist.c  http-private.h ../config.h http.h versioning.h md5.h
 http-addrlist.32.o: http-addrlist.c  ipp-private.h ipp.h globals.h string.h cups.h ppd.h array.h
@@ -235,6 +237,8 @@ testadmin.32.o: testadmin.c  adminutil.h cups.h ipp.h http.h versioning.h ppd.h
 testadmin.32.o: testadmin.c  file.h language.h string.h ../config.h
 testarray.32.o: testarray.c  ../cups/string.h ../config.h string.h array.h versioning.h dir.h
 testarray.32.o: testarray.c  debug.h
+testconflicts.32.o: testconflicts.c  cups.h ipp.h http.h versioning.h ppd.h array.h file.h
+testconflicts.32.o: testconflicts.c  language.h string.h ../config.h
 testcups.32.o: testcups.c  cups.h ipp.h http.h versioning.h ppd.h array.h file.h language.h
 testfile.32.o: testfile.c  string.h ../config.h file.h versioning.h debug.h
 testhttp.32.o: testhttp.c  http-private.h ../config.h http.h versioning.h md5.h
@@ -298,8 +302,8 @@ globals.64.o: globals.c  i18n.h transcode.h
 http.64.o: http.c  http-private.h ../config.h http.h versioning.h md5.h ipp-private.h
 http.64.o: http.c  ipp.h globals.h string.h cups.h ppd.h array.h file.h language.h
 http.64.o: http.c  i18n.h transcode.h debug.h
-http-addr.64.o: http-addr.c  globals.h string.h ../config.h http-private.h http.h
-http-addr.64.o: http-addr.c  versioning.h md5.h ipp-private.h ipp.h cups.h ppd.h array.h
+http-addr.64.o: http-addr.c  http-private.h ../config.h http.h versioning.h md5.h
+http-addr.64.o: http-addr.c  ipp-private.h ipp.h globals.h string.h cups.h ppd.h array.h
 http-addr.64.o: http-addr.c  file.h language.h i18n.h transcode.h debug.h
 http-addrlist.64.o: http-addrlist.c  http-private.h ../config.h http.h versioning.h md5.h
 http-addrlist.64.o: http-addrlist.c  ipp-private.h ipp.h globals.h string.h cups.h ppd.h array.h
@@ -361,6 +365,8 @@ testadmin.64.o: testadmin.c  adminutil.h cups.h ipp.h http.h versioning.h ppd.h
 testadmin.64.o: testadmin.c  file.h language.h string.h ../config.h
 testarray.64.o: testarray.c  ../cups/string.h ../config.h string.h array.h versioning.h dir.h
 testarray.64.o: testarray.c  debug.h
+testconflicts.64.o: testconflicts.c  cups.h ipp.h http.h versioning.h ppd.h array.h file.h
+testconflicts.64.o: testconflicts.c  language.h string.h ../config.h
 testcups.64.o: testcups.c  cups.h ipp.h http.h versioning.h ppd.h array.h file.h language.h
 testfile.64.o: testfile.c  string.h ../config.h file.h versioning.h debug.h
 testhttp.64.o: testhttp.c  http-private.h ../config.h http.h versioning.h md5.h
index 03b0fa940313fa86c9dbb03d576423a284635b77..a13bc7cfec598da0e46ae244f274c8833d3b9c22 100644 (file)
@@ -81,6 +81,7 @@ typedef struct _cups_globals_s                /**** CUPS global state data ****/
 #  ifdef HAVE_GETADDRINFO
   char                 hostname[1024]; /* Hostname */
 #  endif /* HAVE_GETADDRINFO */
+  int                  need_res_init;  /* Need to reinitialize resolver? */
 
   /* ipp.c */
   ipp_uchar_t          ipp_date[11];   /* RFC-1903 date/time data */
index c02263ff909cb8f02d6626ea914cbadd2abdf36a..633a66f02be94a18c5d9ecbb146abefb7bf33098 100644 (file)
  * Include necessary headers...
  */
 
+#include "http-private.h"
 #include "globals.h"
 #include "debug.h"
 #include <stdlib.h>
 #include <stddef.h>
+#ifdef HAVE_RESOLV_H
+#  include <resolv.h>
+#endif /* HAVE_RESOLV_H */
 
 
 /*
@@ -176,6 +180,10 @@ httpAddrLookup(
     char              *name,           /* I - Host name buffer */
     int               namelen)         /* I - Size of name buffer */
 {
+  _cups_globals_t      *cg = _cupsGlobals();
+                                       /* Global data */
+
+
   DEBUG_printf(("httpAddrLookup(addr=%p, name=%p, namelen=%d)\n",
                 addr, name, namelen));
 
@@ -193,9 +201,33 @@ httpAddrLookup(
 
 #ifdef AF_LOCAL
   if (addr->addr.sa_family == AF_LOCAL)
+  {
     strlcpy(name, addr->un.sun_path, namelen);
-  else
+    return (name);
+  }
 #endif /* AF_LOCAL */
+
+#ifdef HAVE_RES_INIT
+ /*
+  * STR #2920: Initialize resolver after failure in cups-polld
+  *
+  * If the previous lookup failed, re-initialize the resolver to prevent
+  * temporary network errors from persisting.  This *should* be handled by
+  * the resolver libraries, but apparently the glibc folks do not agree.
+  *
+  * We set a flag at the end of this function if we encounter an error that
+  * requires reinitialization of the resolver functions.  We then call
+  * res_init() if the flag is set on the next call here or in httpAddrLookup().
+  */
+
+  if (cg->need_res_init)
+  {
+    res_init();
+
+    cg->need_res_init = 0;
+  }
+#endif /* HAVE_RES_INIT */
+
 #ifdef HAVE_GETNAMEINFO
   {
    /*
@@ -206,9 +238,16 @@ httpAddrLookup(
     * do...
     */
 
-    if (getnameinfo(&addr->addr, httpAddrLength(addr), name, namelen,
-                   NULL, 0, 0))
+    int error = getnameinfo(&addr->addr, httpAddrLength(addr), name, namelen,
+                           NULL, 0, 0);
+
+    if (error)
+    {
+      if (error == EAI_FAIL)
+        cg->need_res_init = 1;
+
       return (httpAddrString(addr, name, namelen));
+    }
   }
 #else
   {
@@ -230,8 +269,10 @@ httpAddrLookup(
       * No hostname, so return the raw address...
       */
 
-      httpAddrString(addr, name, namelen);
-      return (NULL);
+      if (h_errno == NO_RECOVERY)
+        cg->need_res_init = 1;
+
+      return (httpAddrString(addr, name, namelen));
     }
 
     strlcpy(name, host->h_name, namelen);
index 900727f3b55c71d365af5dc4a4f122c2bb9f82f3..28fdb16dfd3dbf20220a87cab6895b1cff4ac5cd 100644 (file)
@@ -28,6 +28,9 @@
 #include "debug.h"
 #include <stdlib.h>
 #include <errno.h>
+#ifdef HAVE_RESOLV_H
+#  include <resolv.h>
+#endif /* HAVE_RESOLV_H */
 
 
 /*
@@ -201,6 +204,8 @@ httpAddrGetList(const char *hostname,       /* I - Hostname, IP address, or NULL for p
   http_addrlist_t      *first,         /* First address in list */
                        *addr,          /* Current address in list */
                        *temp;          /* New address */
+  _cups_globals_t      *cg = _cupsGlobals();
+                                       /* Global data */
 
 
 #ifdef DEBUG
@@ -217,6 +222,28 @@ httpAddrGetList(const char *hostname,      /* I - Hostname, IP address, or NULL for p
                         family == AF_INET ? "INET" : "???", service);
 #endif /* DEBUG */
 
+#ifdef HAVE_RES_INIT
+ /*
+  * STR #2920: Initialize resolver after failure in cups-polld
+  *
+  * If the previous lookup failed, re-initialize the resolver to prevent
+  * temporary network errors from persisting.  This *should* be handled by
+  * the resolver libraries, but apparently the glibc folks do not agree.
+  *
+  * We set a flag at the end of this function if we encounter an error that
+  * requires reinitialization of the resolver functions.  We then call
+  * res_init() if the flag is set on the next call here or in httpAddrLookup().
+  */
+
+  if (cg->need_res_init)
+  {
+    res_init();
+
+    cg->need_res_init = 0;
+  }
+#endif /* HAVE_RES_INIT */
+
+
  /*
   * Lookup the address the best way we can...
   */
@@ -246,6 +273,8 @@ httpAddrGetList(const char *hostname,       /* I - Hostname, IP address, or NULL for p
     char               ipv6[1024],     /* IPv6 address */
                        *ipv6zone;      /* Pointer to zone separator */
     int                        ipv6len;        /* Length of IPv6 address */
+    int                        error;          /* getaddrinfo() error */
+
 
    /*
     * Lookup the address as needed...
@@ -297,7 +326,7 @@ httpAddrGetList(const char *hostname,       /* I - Hostname, IP address, or NULL for p
       }
     }
 
-    if (!getaddrinfo(hostname, service, &hints, &results))
+    if ((error = getaddrinfo(hostname, service, &hints, &results)) == 0)
     {
      /*
       * Copy the results to our own address list structure...
@@ -343,6 +372,9 @@ httpAddrGetList(const char *hostname,       /* I - Hostname, IP address, or NULL for p
 
       freeaddrinfo(results);
     }
+    else if (error == EAI_FAIL)
+      cg->need_res_init = 1;
+
 #else
     if (hostname)
     {
@@ -459,6 +491,8 @@ httpAddrGetList(const char *hostname,       /* I - Hostname, IP address, or NULL for p
          addr = temp;
        }
       }
+      else if (h_errno == NO_RECOVERY)
+        cg->need_res_init = 1;
     }
 #endif /* HAVE_GETADDRINFO */
   }
index a27cdfea42af5891a8c9518248ffd6def699bc8d..8f5cfed1d4321eafd6b74b9e439949ba597f9fc4 100644 (file)
@@ -1,5 +1,8 @@
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
+dbus.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/versioning.h
+dbus.o: ../cups/ppd.h ../cups/array.h ../cups/file.h ../cups/language.h
+dbus.o: ../cups/string.h ../config.h
 mailto.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/versioning.h
 mailto.o: ../cups/ppd.h ../cups/array.h ../cups/file.h ../cups/language.h
 mailto.o: ../cups/i18n.h ../cups/transcode.h ../cups/string.h ../config.h