From owner-svn-src-head@freebsd.org Mon Dec 14 17:21:08 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5D25CA44A12; Mon, 14 Dec 2015 17:21:08 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 35B781537; Mon, 14 Dec 2015 17:21:08 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBEHL7lt064683; Mon, 14 Dec 2015 17:21:07 GMT (envelope-from vangyzen@FreeBSD.org) Received: (from vangyzen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBEHL6jb064679; Mon, 14 Dec 2015 17:21:06 GMT (envelope-from vangyzen@FreeBSD.org) Message-Id: <201512141721.tBEHL6jb064679@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vangyzen set sender to vangyzen@FreeBSD.org using -f From: Eric van Gyzen Date: Mon, 14 Dec 2015 17:21:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292216 - in head: include lib/libc/resolv X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Dec 2015 17:21:08 -0000 Author: vangyzen Date: Mon Dec 14 17:21:06 2015 New Revision: 292216 URL: https://svnweb.freebsd.org/changeset/base/292216 Log: resolver: preserve binary compatibility; reduce header pollution In r289315, I added new fields to res_state. This broke binary backward compatibility. It also broke some ports (and possibly other code) by requiring the definition of time_t and struct timespec. Fix these problems by moving the new fields into __res_state_ext. Suggested by: ume Reviewed by: ume MFC after: 3 days Sponsored by: Dell Inc. Differential Revision: https://reviews.freebsd.org/D4472 Modified: head/include/resolv.h head/lib/libc/resolv/res_init.c head/lib/libc/resolv/res_private.h head/lib/libc/resolv/res_state.c Modified: head/include/resolv.h ============================================================================== --- head/include/resolv.h Mon Dec 14 17:08:40 2015 (r292215) +++ head/include/resolv.h Mon Dec 14 17:21:06 2015 (r292216) @@ -57,7 +57,6 @@ #include #include #include -#include #include #include @@ -177,8 +176,7 @@ struct __res_state { int res_h_errno; /*%< last one set for this context */ int _vcsock; /*%< PRIVATE: for res_send VC i/o */ u_int _flags; /*%< PRIVATE: see below */ - u_short reload_period; /*%< seconds between stat(resolv.conf)*/ - u_short _pad; /*%< make _u 64 bit aligned */ + u_int _pad; /*%< make _u 64 bit aligned */ union { /* On an 32-bit arch this means 512b total. */ char pad[72 - 4*sizeof (int) - 3*sizeof (void *)]; @@ -190,8 +188,6 @@ struct __res_state { } _ext; } _u; u_char *_rnd; /*%< PRIVATE: random state */ - struct timespec conf_mtim; /*%< mod time of loaded resolv.conf */ - time_t conf_stat; /*%< time of last stat(resolv.conf) */ }; typedef struct __res_state *res_state; Modified: head/lib/libc/resolv/res_init.c ============================================================================== --- head/lib/libc/resolv/res_init.c Mon Dec 14 17:08:40 2015 (r292215) +++ head/lib/libc/resolv/res_init.c Mon Dec 14 17:21:06 2015 (r292216) @@ -228,7 +228,6 @@ __res_vinit(res_state statp, int preinit statp->pfcode = 0; statp->_vcsock = -1; statp->_flags = 0; - statp->reload_period = 2; statp->qhook = NULL; statp->rhook = NULL; statp->_u._ext.nscount = 0; @@ -238,6 +237,7 @@ __res_vinit(res_state statp, int preinit statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa"); strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int"); + statp->_u._ext.ext->reload_period = 2; } else { /* * Historically res_init() rarely, if at all, failed. @@ -326,17 +326,13 @@ __res_vinit(res_state statp, int preinit struct stat sb; struct timespec now; - if (_fstat(fileno(fp), &sb) == 0) { - statp->conf_mtim = sb.st_mtim; - if (clock_gettime(CLOCK_MONOTONIC_FAST, &now) == 0) { - statp->conf_stat = now.tv_sec; - } else { - statp->conf_stat = 0; - } - } else { - statp->conf_mtim.tv_sec = 0; - statp->conf_mtim.tv_nsec = 0; - statp->conf_stat = 0; + if (statp->_u._ext.ext != NULL) { + if (_fstat(fileno(fp), &sb) == 0) { + statp->_u._ext.ext->conf_mtim = sb.st_mtim; + if (clock_gettime(CLOCK_MONOTONIC_FAST, &now) == 0) { + statp->_u._ext.ext->conf_stat = now.tv_sec; + } + } } /* read the config file */ @@ -599,9 +595,7 @@ res_setoptions(res_state statp, const ch { const char *cp = options; int i; -#ifndef _LIBC struct __res_state_ext *ext = statp->_u._ext.ext; -#endif #ifdef DEBUG if (statp->options & RES_DEBUG) @@ -686,8 +680,10 @@ res_setoptions(res_state statp, const ch statp->options |= RES_NOCHECKNAME; } else if (!strncmp(cp, "reload-period:", sizeof("reload-period:") - 1)) { - statp->reload_period = (u_short) - atoi(cp + sizeof("reload-period:") - 1); + if (ext != NULL) { + ext->reload_period = (u_short) + atoi(cp + sizeof("reload-period:") - 1); + } } #ifdef RES_USE_EDNS0 else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { Modified: head/lib/libc/resolv/res_private.h ============================================================================== --- head/lib/libc/resolv/res_private.h Mon Dec 14 17:08:40 2015 (r292215) +++ head/lib/libc/resolv/res_private.h Mon Dec 14 17:21:06 2015 (r292216) @@ -1,3 +1,5 @@ +/* $FreeBSD$ */ + #ifndef res_private_h #define res_private_h @@ -12,6 +14,9 @@ struct __res_state_ext { } sort_list[MAXRESOLVSORT]; char nsuffix[64]; char nsuffix2[64]; + struct timespec conf_mtim; /* mod time of loaded resolv.conf */ + time_t conf_stat; /* time of last stat(resolv.conf) */ + u_short reload_period; /* seconds between stat(resolv.conf) */ }; extern int Modified: head/lib/libc/resolv/res_state.c ============================================================================== --- head/lib/libc/resolv/res_state.c Mon Dec 14 17:08:40 2015 (r292215) +++ head/lib/libc/resolv/res_state.c Mon Dec 14 17:21:06 2015 (r292216) @@ -37,6 +37,8 @@ #include "reentrant.h" #include "un-namespace.h" +#include "res_private.h" + #undef _res struct __res_state _res; @@ -66,20 +68,26 @@ res_check_reload(res_state statp) { struct timespec now; struct stat sb; + struct __res_state_ext *ext; + + if ((statp->options & RES_INIT) == 0) { + return (statp); + } - if ((statp->options & RES_INIT) == 0 || statp->reload_period == 0) { + ext = statp->_u._ext.ext; + if (ext == NULL || ext->reload_period == 0) { return (statp); } if (clock_gettime(CLOCK_MONOTONIC_FAST, &now) != 0 || - (now.tv_sec - statp->conf_stat) < statp->reload_period) { + (now.tv_sec - ext->conf_stat) < ext->reload_period) { return (statp); } - statp->conf_stat = now.tv_sec; + ext->conf_stat = now.tv_sec; if (stat(_PATH_RESCONF, &sb) == 0 && - (sb.st_mtim.tv_sec != statp->conf_mtim.tv_sec || - sb.st_mtim.tv_nsec != statp->conf_mtim.tv_nsec)) { + (sb.st_mtim.tv_sec != ext->conf_mtim.tv_sec || + sb.st_mtim.tv_nsec != ext->conf_mtim.tv_nsec)) { statp->options &= ~RES_INIT; }