aef9bcc
diff -up cups-2.2.0/cups/auth.c.resolv_reload cups-2.2.0/cups/auth.c
aef9bcc
--- cups-2.2.0/cups/auth.c.resolv_reload	2016-09-14 01:39:47.000000000 +0200
aef9bcc
+++ cups-2.2.0/cups/auth.c	2017-03-30 13:08:06.436258996 +0200
aef9bcc
@@ -519,6 +519,16 @@ cups_gss_getname(
61eac51
   DEBUG_printf(("7cups_gss_getname(http=%p, service_name=\"%s\")", http,
61eac51
                 service_name));
61eac51
 
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+ /*
61eac51
+  * Check if /etc/resolv.conf is modified.
61eac51
+  * If so, reload resolver.
61eac51
+  */
61eac51
+
61eac51
+  http_resolv_check_t status;
61eac51
+
61eac51
+  status = httpCheckResolv();
61eac51
+#endif /* HAVE_RES_INIT */
61eac51
 
61eac51
  /*
61eac51
   * Get the hostname...
aef9bcc
diff -up cups-2.2.0/cups/http-addr.c.resolv_reload cups-2.2.0/cups/http-addr.c
aef9bcc
--- cups-2.2.0/cups/http-addr.c.resolv_reload	2017-03-30 13:08:06.422259148 +0200
aef9bcc
+++ cups-2.2.0/cups/http-addr.c	2017-03-30 13:08:06.436258996 +0200
aef9bcc
@@ -361,6 +361,17 @@ httpAddrLookup(
61eac51
 
61eac51
 #ifdef HAVE_RES_INIT
61eac51
  /*
61eac51
+  * Check if /etc/resolv.conf is modified.
61eac51
+  * If so, reload resolver and set need_res_init to 0.
61eac51
+  */
61eac51
+
61eac51
+  http_resolv_check_t status;
61eac51
+
61eac51
+  status = httpCheckResolv();
61eac51
+
61eac51
+  if (status == HTTP_RESOLV_CHECK_RELOADED && cg->need_res_init == 1)
61eac51
+    cg->need_res_init = 0;
61eac51
+ /*
61eac51
   * STR #2920: Initialize resolver after failure in cups-polld
61eac51
   *
61eac51
   * If the previous lookup failed, re-initialize the resolver to prevent
aef9bcc
diff -up cups-2.2.0/cups/http-addrlist.c.resolv_reload cups-2.2.0/cups/http-addrlist.c
aef9bcc
--- cups-2.2.0/cups/http-addrlist.c.resolv_reload	2017-03-30 13:08:06.434259017 +0200
aef9bcc
+++ cups-2.2.0/cups/http-addrlist.c	2017-03-30 13:08:06.436258996 +0200
aef9bcc
@@ -483,6 +483,17 @@ httpAddrGetList(const char *hostname,	/*
61eac51
 
61eac51
 #ifdef HAVE_RES_INIT
61eac51
  /*
61eac51
+  * Check if /etc/resolv.conf is modified.
61eac51
+  * If so, reload resolver and set cg->need_res_init to 0
61eac51
+  */
61eac51
+
61eac51
+  http_resolv_check_t status;
61eac51
+
61eac51
+  status = httpCheckResolv();
61eac51
+
61eac51
+  if (status == HTTP_RESOLV_CHECK_RELOADED && cg->need_res_init == 1)
61eac51
+    cg->need_res_init = 0;
61eac51
+ /*
61eac51
   * STR #2920: Initialize resolver after failure in cups-polld
61eac51
   *
61eac51
   * If the previous lookup failed, re-initialize the resolver to prevent
aef9bcc
diff -up cups-2.2.0/cups/http.c.resolv_reload cups-2.2.0/cups/http.c
aef9bcc
--- cups-2.2.0/cups/http.c.resolv_reload	2016-09-14 01:39:47.000000000 +0200
aef9bcc
+++ cups-2.2.0/cups/http.c	2017-03-30 13:12:38.411379288 +0200
aef9bcc
@@ -107,6 +107,9 @@ static const char * const http_fields[]
61eac51
 			  "Allow",
61eac51
 			  "Server"
61eac51
 			};
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+time_t resolv_conf_modtime = 0;
61eac51
+#endif /* HAVE_RES_INIT */
61eac51
 
61eac51
 
61eac51
 /*
aef9bcc
@@ -4811,3 +4814,34 @@ http_write_chunk(http_t     *http,	/* I
aef9bcc
 
61eac51
   return (bytes);
61eac51
 }
aef9bcc
+
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+/*
61eac51
+ * Function to check modification time of resolv.conf. 
61eac51
+ * If time is changed, it reloads resolver.
61eac51
+ */
61eac51
+
61eac51
+http_resolv_check_t
61eac51
+httpCheckResolv()
61eac51
+{
61eac51
+  http_resolv_check_t status = HTTP_RESOLV_CHECK_OK;
61eac51
+  struct stat resolv_conf_status;
61eac51
+
61eac51
+  status = stat(HTTP_RESOLV_CONF_PATH, &resolv_conf_status);
61eac51
+
61eac51
+  if (status == HTTP_RESOLV_CHECK_ERROR)
61eac51
+    return (status);
61eac51
+
61eac51
+  if (resolv_conf_modtime != 0 && resolv_conf_status.st_mtime != resolv_conf_modtime)
61eac51
+  {
61eac51
+    res_init();
61eac51
+
61eac51
+    status = HTTP_RESOLV_CHECK_RELOADED;
61eac51
+  }
61eac51
+
61eac51
+  resolv_conf_modtime = resolv_conf_status.st_mtime;
61eac51
+
61eac51
+  return (status);
61eac51
+}
61eac51
+#endif /* HAVE_RES_INIT */
aef9bcc
+
aef9bcc
diff -up cups-2.2.0/cups/http.h.resolv_reload cups-2.2.0/cups/http.h
aef9bcc
--- cups-2.2.0/cups/http.h.resolv_reload	2016-09-14 01:39:47.000000000 +0200
aef9bcc
+++ cups-2.2.0/cups/http.h	2017-03-30 13:08:06.437258985 +0200
aef9bcc
@@ -55,6 +55,12 @@ typedef off_t ssize_t;			/* @private@ */
61eac51
 #      define SO_PEERCRED LOCAL_PEERCRED
61eac51
 #    endif /* LOCAL_PEERCRED && !SO_PEERCRED */
61eac51
 #  endif /* WIN32 */
61eac51
+#  ifdef HAVE_RES_INIT
61eac51
+#    include <sys/stat.h>
61eac51
+#    include <unistd.h>
61eac51
+#    include <arpa/nameser.h>
61eac51
+#    include <resolv.h>
61eac51
+#  endif /* HAVE_RES_INIT */
61eac51
 
61eac51
 
61eac51
 /*
aef9bcc
@@ -95,6 +101,13 @@ extern "C" {
61eac51
 #endif /* AF_INET6 && !s6_addr32 */
61eac51
 
61eac51
 
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+/*
61eac51
+ * Global variable for storing old modification time of resolv.conf 
61eac51
+ */
61eac51
+  extern time_t resolv_conf_modtime;
61eac51
+#endif /* HAVE_RES_INIT */
61eac51
+
61eac51
 /*
61eac51
  * Limits...
61eac51
  */
aef9bcc
@@ -103,6 +116,9 @@ extern "C" {
61eac51
 #  define HTTP_MAX_HOST		256	/* Max length of hostname string */
61eac51
 #  define HTTP_MAX_BUFFER	2048	/* Max length of data buffer */
61eac51
 #  define HTTP_MAX_VALUE	256	/* Max header field value length */
61eac51
+#  ifdef HAVE_RES_INIT
61eac51
+#    define HTTP_RESOLV_CONF_PATH	"/etc/resolv.conf" /* Path to resolv.conf */
61eac51
+#  endif /* HAVE_RES_INIT */
61eac51
 
61eac51
 
61eac51
 /*
aef9bcc
@@ -406,6 +422,15 @@ typedef enum http_version_e		/**** HTTP
61eac51
 #  endif /* !_CUPS_NO_DEPRECATED */
61eac51
 } http_version_t;
61eac51
 
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+typedef enum http_resolv_check_e
61eac51
+{
61eac51
+  HTTP_RESOLV_CHECK_ERROR = -1,
61eac51
+  HTTP_RESOLV_CHECK_OK = 0,
61eac51
+  HTTP_RESOLV_CHECK_RELOADED = 1
61eac51
+} http_resolv_check_t;
61eac51
+#endif /* HAVE_RES_INIT */
61eac51
+
61eac51
 typedef union _http_addr_u		/**** Socket address union, which
61eac51
 					 **** makes using IPv6 and other
61eac51
 					 **** address types easier and
aef9bcc
@@ -644,6 +669,11 @@ extern void		httpShutdown(http_t *http)
61eac51
 extern const char	*httpStateString(http_state_t state) _CUPS_API_2_0;
61eac51
 extern const char	*httpURIStatusString(http_uri_status_t status) _CUPS_API_2_0;
61eac51
 
61eac51
+/**** Prototype of function to check modification time of /etc/resolv.conf ****/
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+extern http_resolv_check_t	httpCheckResolv();
61eac51
+#endif /* HAVE_RES_INIT */
61eac51
+
61eac51
 /*
61eac51
  * C++ magic...
61eac51
  */
aef9bcc
diff -up cups-2.2.0/cups/http-support.c.resolv_reload cups-2.2.0/cups/http-support.c
aef9bcc
--- cups-2.2.0/cups/http-support.c.resolv_reload	2017-03-30 13:08:06.437258985 +0200
aef9bcc
+++ cups-2.2.0/cups/http-support.c	2017-03-30 13:19:01.559533564 +0200
aef9bcc
@@ -2258,6 +2258,16 @@ http_resolve_cb(
61eac51
     http_addrlist_t	*addrlist,	/* List of addresses */
61eac51
 			*addr;		/* Current address */
61eac51
 
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+   /*
61eac51
+	* Check if resolv.conf is modified, if so, reload resolver
61eac51
+	*/
61eac51
+
61eac51
+    http_resolv_check_t status;
61eac51
+
61eac51
+	status = httpCheckResolv();
61eac51
+#endif /* HAVE_RES_INIT */
61eac51
+
aef9bcc
     DEBUG_printf(("5http_resolve_cb: Looking up \"%s\".", hostTarget));
61eac51
 
61eac51
     snprintf(fqdn, sizeof(fqdn), "%d", ntohs(port));
aef9bcc
diff -up cups-2.2.0/scheduler/conf.c.resolv_reload cups-2.2.0/scheduler/conf.c
aef9bcc
--- cups-2.2.0/scheduler/conf.c.resolv_reload	2017-03-30 13:08:06.433259028 +0200
aef9bcc
+++ cups-2.2.0/scheduler/conf.c	2017-03-30 13:08:06.439258963 +0200
aef9bcc
@@ -937,6 +937,12 @@ cupsdReadConfiguration(void)
61eac51
   if (!RemotePort)
61eac51
     BrowseLocalProtocols = 0;		/* Disable sharing - no remote access */
61eac51
 
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+  http_resolv_check_t res_status;	/* Return status of httpCheckResolv() */
61eac51
+
61eac51
+  res_status = httpCheckResolv();
61eac51
+#endif /* HAVE_RES_INIT */
61eac51
+
61eac51
  /*
61eac51
   * See if the ServerName is an IP address...
61eac51
   */
aef9bcc
diff -up cups-2.2.0/scheduler/main.c.resolv_reload cups-2.2.0/scheduler/main.c
aef9bcc
--- cups-2.2.0/scheduler/main.c.resolv_reload	2017-03-30 13:08:06.440258952 +0200
aef9bcc
+++ cups-2.2.0/scheduler/main.c	2017-03-30 13:23:38.886665663 +0200
aef9bcc
@@ -136,6 +136,17 @@ main(int  argc,				/* I - Number of comm
aef9bcc
   long			tmo_delay;	/* Time before it must be called */
61eac51
 #endif /* HAVE_AVAHI */
61eac51
 
61eac51
+#ifdef HAVE_RES_INIT
61eac51
+  http_resolv_check_t status;	/* Return status from httpCheckResolv() */
61eac51
+
61eac51
+  status = httpCheckResolv();
61eac51
+  if (status == HTTP_RESOLV_CHECK_ERROR)
61eac51
+  {
61eac51
+    fputs("cupsd: Cannot get a status of /etc/resolv.conf\n", stderr);
61eac51
+	return (1);
61eac51
+  }
61eac51
+#endif /* HAVE_RES_INIT */
61eac51
+
61eac51
 #ifdef HAVE_GETEUID
61eac51
  /*
61eac51
   * Check for setuid invocation, which we do not support!