61eac5
diff -up cups-2.1.4/cups/auth.c.resolv_reload cups-2.1.4/cups/auth.c
61eac5
--- cups-2.1.4/cups/auth.c.resolv_reload	2016-06-14 19:45:32.000000000 +0200
2b1684
+++ cups-2.1.4/cups/auth.c	2017-04-05 17:36:21.812611389 +0200
61eac5
@@ -522,6 +522,16 @@ cups_gss_getname(
61eac5
   DEBUG_printf(("7cups_gss_getname(http=%p, service_name=\"%s\")", http,
61eac5
                 service_name));
61eac5
 
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+ /*
61eac5
+  * Check if /etc/resolv.conf is modified.
61eac5
+  * If so, reload resolver.
61eac5
+  */
61eac5
+
61eac5
+  http_resolv_check_t status;
61eac5
+
61eac5
+  status = httpCheckResolv();
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
 
61eac5
  /*
61eac5
   * Get the hostname...
61eac5
diff -up cups-2.1.4/cups/http-addr.c.resolv_reload cups-2.1.4/cups/http-addr.c
2b1684
--- cups-2.1.4/cups/http-addr.c.resolv_reload	2017-04-05 17:36:21.798611527 +0200
2b1684
+++ cups-2.1.4/cups/http-addr.c	2017-04-05 17:36:21.812611389 +0200
61eac5
@@ -364,6 +364,17 @@ httpAddrLookup(
61eac5
 
61eac5
 #ifdef HAVE_RES_INIT
61eac5
  /*
61eac5
+  * Check if /etc/resolv.conf is modified.
61eac5
+  * If so, reload resolver and set need_res_init to 0.
61eac5
+  */
61eac5
+
61eac5
+  http_resolv_check_t status;
61eac5
+
61eac5
+  status = httpCheckResolv();
61eac5
+
61eac5
+  if (status == HTTP_RESOLV_CHECK_RELOADED && cg->need_res_init == 1)
61eac5
+    cg->need_res_init = 0;
61eac5
+ /*
61eac5
   * STR #2920: Initialize resolver after failure in cups-polld
61eac5
   *
61eac5
   * If the previous lookup failed, re-initialize the resolver to prevent
61eac5
diff -up cups-2.1.4/cups/http-addrlist.c.resolv_reload cups-2.1.4/cups/http-addrlist.c
2b1684
--- cups-2.1.4/cups/http-addrlist.c.resolv_reload	2017-04-05 17:36:21.781611694 +0200
2b1684
+++ cups-2.1.4/cups/http-addrlist.c	2017-04-05 17:36:21.813611379 +0200
61eac5
@@ -414,6 +414,17 @@ httpAddrGetList(const char *hostname,	/*
61eac5
 
61eac5
 #ifdef HAVE_RES_INIT
61eac5
  /*
61eac5
+  * Check if /etc/resolv.conf is modified.
61eac5
+  * If so, reload resolver and set cg->need_res_init to 0
61eac5
+  */
61eac5
+
61eac5
+  http_resolv_check_t status;
61eac5
+
61eac5
+  status = httpCheckResolv();
61eac5
+
61eac5
+  if (status == HTTP_RESOLV_CHECK_RELOADED && cg->need_res_init == 1)
61eac5
+    cg->need_res_init = 0;
61eac5
+ /*
61eac5
   * STR #2920: Initialize resolver after failure in cups-polld
61eac5
   *
61eac5
   * If the previous lookup failed, re-initialize the resolver to prevent
61eac5
diff -up cups-2.1.4/cups/http.c.resolv_reload cups-2.1.4/cups/http.c
2b1684
--- cups-2.1.4/cups/http.c.resolv_reload	2016-06-14 19:45:32.000000000 +0200
2b1684
+++ cups-2.1.4/cups/http.c	2017-04-05 17:53:16.856712660 +0200
61eac5
@@ -109,6 +109,9 @@ static const char * const http_fields[]
61eac5
 			  "Allow",
61eac5
 			  "Server"
61eac5
 			};
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+time_t resolv_conf_modtime = 0;
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
 
61eac5
 
61eac5
 /*
2b1684
@@ -4848,6 +4851,45 @@ http_write_chunk(http_t     *http,	/* I
61eac5
   return (bytes);
61eac5
 }
61eac5
 
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+/*
61eac5
+ * Function to check modification time of resolv.conf. 
2b1684
+ * If time is changed, it reloads resolver. 
2b1684
+ * If /etc/resolv.conf doesn't exist, it tries to reload local resolver.
2b1684
+ * If even reloading local resolver doesn't work, it ends with error.
61eac5
+ */
61eac5
+
61eac5
+http_resolv_check_t
61eac5
+httpCheckResolv()
61eac5
+{
61eac5
+  http_resolv_check_t status = HTTP_RESOLV_CHECK_OK;
61eac5
+  struct stat resolv_conf_status;
61eac5
+
61eac5
+  status = stat(HTTP_RESOLV_CONF_PATH, &resolv_conf_status);
61eac5
+
2b1684
+  /* /etc/resolv.conf couldn't be stated because it doesn't exist, try resolver on localhost */
2b1684
+  if (status == HTTP_RESOLV_CHECK_ERROR && errno == ENOENT)
2b1684
+  {
2b1684
+    status = res_init();
2b1684
+    return(status);
2b1684
+  }
2b1684
+
2b1684
+  /* If stat ends with different errno, return status */
61eac5
+  if (status == HTTP_RESOLV_CHECK_ERROR)
61eac5
+    return (status);
61eac5
+
61eac5
+  if (resolv_conf_modtime != 0 && resolv_conf_status.st_mtime != resolv_conf_modtime)
61eac5
+  {
61eac5
+    res_init();
61eac5
+
61eac5
+    status = HTTP_RESOLV_CHECK_RELOADED;
61eac5
+  }
61eac5
+
61eac5
+  resolv_conf_modtime = resolv_conf_status.st_mtime;
61eac5
+
61eac5
+  return (status);
61eac5
+}
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
 
61eac5
 /*
61eac5
  * End of "$Id: http.c 12970 2015-11-13 20:02:51Z msweet $".
61eac5
diff -up cups-2.1.4/cups/http.h.resolv_reload cups-2.1.4/cups/http.h
61eac5
--- cups-2.1.4/cups/http.h.resolv_reload	2016-06-14 19:45:32.000000000 +0200
2b1684
+++ cups-2.1.4/cups/http.h	2017-04-05 17:36:21.814611369 +0200
61eac5
@@ -57,6 +57,12 @@ typedef off_t ssize_t;			/* @private@ */
61eac5
 #      define SO_PEERCRED LOCAL_PEERCRED
61eac5
 #    endif /* LOCAL_PEERCRED && !SO_PEERCRED */
61eac5
 #  endif /* WIN32 */
61eac5
+#  ifdef HAVE_RES_INIT
61eac5
+#    include <sys stat.h="">
61eac5
+#    include <unistd.h>
61eac5
+#    include <arpa nameser.h="">
61eac5
+#    include <resolv.h>
61eac5
+#  endif /* HAVE_RES_INIT */
61eac5
 
61eac5
 
61eac5
 /*
61eac5
@@ -97,6 +103,13 @@ extern "C" {
61eac5
 #endif /* AF_INET6 && !s6_addr32 */
61eac5
 
61eac5
 
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+/*
61eac5
+ * Global variable for storing old modification time of resolv.conf 
61eac5
+ */
61eac5
+  extern time_t resolv_conf_modtime;
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
+
61eac5
 /*
61eac5
  * Limits...
61eac5
  */
61eac5
@@ -105,6 +118,9 @@ extern "C" {
61eac5
 #  define HTTP_MAX_HOST		256	/* Max length of hostname string */
61eac5
 #  define HTTP_MAX_BUFFER	2048	/* Max length of data buffer */
61eac5
 #  define HTTP_MAX_VALUE	256	/* Max header field value length */
61eac5
+#  ifdef HAVE_RES_INIT
61eac5
+#    define HTTP_RESOLV_CONF_PATH	"/etc/resolv.conf" /* Path to resolv.conf */
61eac5
+#  endif /* HAVE_RES_INIT */
61eac5
 
61eac5
 
61eac5
 /*
61eac5
@@ -408,6 +424,15 @@ typedef enum http_version_e		/**** HTTP
61eac5
 #  endif /* !_CUPS_NO_DEPRECATED */
61eac5
 } http_version_t;
61eac5
 
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+typedef enum http_resolv_check_e
61eac5
+{
61eac5
+  HTTP_RESOLV_CHECK_ERROR = -1,
61eac5
+  HTTP_RESOLV_CHECK_OK = 0,
61eac5
+  HTTP_RESOLV_CHECK_RELOADED = 1
61eac5
+} http_resolv_check_t;
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
+
61eac5
 typedef union _http_addr_u		/**** Socket address union, which
61eac5
 					 **** makes using IPv6 and other
61eac5
 					 **** address types easier and
61eac5
@@ -646,6 +671,11 @@ extern void		httpShutdown(http_t *http)
61eac5
 extern const char	*httpStateString(http_state_t state) _CUPS_API_2_0;
61eac5
 extern const char	*httpURIStatusString(http_uri_status_t status) _CUPS_API_2_0;
61eac5
 
61eac5
+/**** Prototype of function to check modification time of /etc/resolv.conf ****/
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+extern http_resolv_check_t	httpCheckResolv();
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
+
61eac5
 /*
61eac5
  * C++ magic...
61eac5
  */
61eac5
diff -up cups-2.1.4/cups/http-support.c.resolv_reload cups-2.1.4/cups/http-support.c
2b1684
--- cups-2.1.4/cups/http-support.c.resolv_reload	2017-04-05 17:36:21.795611556 +0200
2b1684
+++ cups-2.1.4/cups/http-support.c	2017-04-05 17:36:21.814611369 +0200
61eac5
@@ -2266,6 +2266,16 @@ http_resolve_cb(
61eac5
     http_addrlist_t	*addrlist,	/* List of addresses */
61eac5
 			*addr;		/* Current address */
61eac5
 
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+   /*
61eac5
+	* Check if resolv.conf is modified, if so, reload resolver
61eac5
+	*/
61eac5
+
61eac5
+    http_resolv_check_t status;
61eac5
+
61eac5
+	status = httpCheckResolv();
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
+
61eac5
     DEBUG_printf(("8http_resolve_cb: Looking up \"%s\".", hostTarget));
61eac5
 
61eac5
     snprintf(fqdn, sizeof(fqdn), "%d", ntohs(port));
61eac5
diff -up cups-2.1.4/scheduler/conf.c.resolv_reload cups-2.1.4/scheduler/conf.c
2b1684
--- cups-2.1.4/scheduler/conf.c.resolv_reload	2017-04-05 17:36:21.810611409 +0200
2b1684
+++ cups-2.1.4/scheduler/conf.c	2017-04-05 17:36:21.815611359 +0200
61eac5
@@ -939,6 +939,12 @@ cupsdReadConfiguration(void)
61eac5
   if (!RemotePort)
61eac5
     BrowseLocalProtocols = 0;		/* Disable sharing - no remote access */
61eac5
 
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+  http_resolv_check_t res_status;	/* Return status of httpCheckResolv() */
61eac5
+
61eac5
+  res_status = httpCheckResolv();
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
+
61eac5
  /*
61eac5
   * See if the ServerName is an IP address...
61eac5
   */
61eac5
diff -up cups-2.1.4/scheduler/main.c.resolv_reload cups-2.1.4/scheduler/main.c
2b1684
--- cups-2.1.4/scheduler/main.c.resolv_reload	2017-04-05 17:36:21.805611458 +0200
2b1684
+++ cups-2.1.4/scheduler/main.c	2017-04-05 17:39:05.278005085 +0200
2b1684
@@ -141,6 +141,14 @@ main(int  argc,				/* I - Number of comm
61eac5
 #endif /* HAVE_AVAHI */
61eac5
 
61eac5
 
61eac5
+#ifdef HAVE_RES_INIT
61eac5
+  http_resolv_check_t status;	/* Return status from httpCheckResolv() */
61eac5
+
61eac5
+  status = httpCheckResolv();
61eac5
+  if (status == HTTP_RESOLV_CHECK_ERROR)
2b1684
+    fputs("cupsd: Cannot reload a resolver, using old configuration now.\n", stderr);
61eac5
+#endif /* HAVE_RES_INIT */
61eac5
+
61eac5
 #ifdef HAVE_GETEUID
61eac5
  /*
61eac5
   * Check for setuid invocation, which we do not support!