From 7a758347d4f16abc6bc6a443d6e3eb4f34602cc3 Mon Sep 17 00:00:00 2001 From: vangyzen Date: Mon, 14 Dec 2015 17:21:06 +0000 Subject: 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 --- lib/libc/resolv/res_init.c | 26 +++++++++++--------------- lib/libc/resolv/res_private.h | 5 +++++ lib/libc/resolv/res_state.c | 18 +++++++++++++----- 3 files changed, 29 insertions(+), 20 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c index 087e6a8..8d59eba 100644 --- a/lib/libc/resolv/res_init.c +++ b/lib/libc/resolv/res_init.c @@ -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; + 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; + } } - } else { - statp->conf_mtim.tv_sec = 0; - statp->conf_mtim.tv_nsec = 0; - statp->conf_stat = 0; } /* read the config file */ @@ -599,9 +595,7 @@ res_setoptions(res_state statp, const char *options, const char *source) { 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 char *options, const char *source) 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)) { diff --git a/lib/libc/resolv/res_private.h b/lib/libc/resolv/res_private.h index 4e98157..a986e95 100644 --- a/lib/libc/resolv/res_private.h +++ b/lib/libc/resolv/res_private.h @@ -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 diff --git a/lib/libc/resolv/res_state.c b/lib/libc/resolv/res_state.c index 87643422..6d31d92 100644 --- a/lib/libc/resolv/res_state.c +++ b/lib/libc/resolv/res_state.c @@ -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; } -- cgit v1.1 From fea0add70e97d3866543fe397202ecc6d1413e65 Mon Sep 17 00:00:00 2001 From: jhb Date: Tue, 15 Dec 2015 00:05:07 +0000 Subject: Start on a new library (libsysdecode) that provides routines for decoding system call information such as system call arguments. Initially this will consist of pulling duplicated code out of truss and kdump though it may prove useful for other utilities in the future. This commit moves the shared utrace(2) record parser out of kdump into the library and updates kdump and truss to use it. One difference from the previous version is that the library version treats unknown events that start with the "RTLD" signature as unknown events. This simplifies the interface and allows the consumer to decide how to handle all non-recognized events. Instead, this function only generates a string description for known malloc() and RTLD records. Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D4537 --- lib/libc/sys/utrace.2 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/sys/utrace.2 b/lib/libc/sys/utrace.2 index 345c1fd..9f48ca9 100644 --- a/lib/libc/sys/utrace.2 +++ b/lib/libc/sys/utrace.2 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 5, 2015 +.Dd December 11, 2015 .Dt UTRACE 2 .Os .Sh NAME @@ -71,7 +71,8 @@ support .Xr kdump 1 , .Xr ktrace 1 , .Xr ktrace 2 , -.Xr truss 1 +.Xr truss 1 , +.Xr sysdecode_utrace 3 .Sh HISTORY The .Fn utrace -- cgit v1.1 From a91f621c6e2380a9a23b0e3c8fcf784c09f5971c Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 15 Dec 2015 05:37:09 +0000 Subject: Allow users override `DEBUG` on the command line via DEBUG_FLAGS="-DDEBUG" with lib/libc/resolv by conditionalizing its definition MFC after: 3 days Reviewed by: ume, vangyzen Differential Revision: https://reviews.freebsd.org/D4519 --- lib/libc/resolv/res_init.c | 4 +++- lib/libc/resolv/res_mkquery.c | 4 +++- lib/libc/resolv/res_mkupdate.c | 4 +++- lib/libc/resolv/res_query.c | 4 +++- lib/libc/resolv/res_send.c | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c index 8d59eba..8832342 100644 --- a/lib/libc/resolv/res_init.c +++ b/lib/libc/resolv/res_init.c @@ -116,7 +116,9 @@ __FBSDID("$FreeBSD$"); /*% Options. Should all be left alone. */ #define RESOLVSORT -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif #ifdef SOLARIS2 #include diff --git a/lib/libc/resolv/res_mkquery.c b/lib/libc/resolv/res_mkquery.c index b60d8f5..0d45e34 100644 --- a/lib/libc/resolv/res_mkquery.c +++ b/lib/libc/resolv/res_mkquery.c @@ -83,7 +83,9 @@ __FBSDID("$FreeBSD$"); #include "port_after.h" /* Options. Leave them on. */ -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif extern const char *_res_opcodes[]; diff --git a/lib/libc/resolv/res_mkupdate.c b/lib/libc/resolv/res_mkupdate.c index d4981a5..c076c1e5 100644 --- a/lib/libc/resolv/res_mkupdate.c +++ b/lib/libc/resolv/res_mkupdate.c @@ -54,7 +54,9 @@ __FBSDID("$FreeBSD$"); #include "port_after.h" /* Options. Leave them on. */ -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif #define MAXPORT 1024 static int getnum_str(u_char **, u_char *); diff --git a/lib/libc/resolv/res_query.c b/lib/libc/resolv/res_query.c index 4ae97f6..5992edd 100644 --- a/lib/libc/resolv/res_query.c +++ b/lib/libc/resolv/res_query.c @@ -88,7 +88,9 @@ __FBSDID("$FreeBSD$"); #include "port_after.h" /* Options. Leave them on. */ -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif #if PACKETSZ > 1024 #define MAXPACKET PACKETSZ diff --git a/lib/libc/resolv/res_send.c b/lib/libc/resolv/res_send.c index 5690491..c127c3b 100644 --- a/lib/libc/resolv/res_send.c +++ b/lib/libc/resolv/res_send.c @@ -119,7 +119,9 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" /* Options. Leave them on. */ -#define DEBUG +#ifndef DEBUG +#define DEBUG +#endif #include "res_debug.h" #include "res_private.h" -- cgit v1.1 From becefd57da16caf58e6bcc09dc3d60723810ebc6 Mon Sep 17 00:00:00 2001 From: kevlo Date: Tue, 15 Dec 2015 15:08:29 +0000 Subject: Remove sys/types.h due to STANDARDS and unistd.h also includes sys/types.h. Reviewed by: bde --- lib/libc/sys/getuid.2 | 3 +-- lib/libc/sys/setuid.2 | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/sys/getuid.2 b/lib/libc/sys/getuid.2 index eae0b23..4145356 100644 --- a/lib/libc/sys/getuid.2 +++ b/lib/libc/sys/getuid.2 @@ -28,7 +28,7 @@ .\" @(#)getuid.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd December 15, 2015 .Dt GETUID 2 .Os .Sh NAME @@ -39,7 +39,6 @@ .Lb libc .Sh SYNOPSIS .In unistd.h -.In sys/types.h .Ft uid_t .Fn getuid void .Ft uid_t diff --git a/lib/libc/sys/setuid.2 b/lib/libc/sys/setuid.2 index 54d89bc..949d936 100644 --- a/lib/libc/sys/setuid.2 +++ b/lib/libc/sys/setuid.2 @@ -28,7 +28,7 @@ .\" @(#)setuid.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd September 13, 2015 +.Dd December 15, 2015 .Dt SETUID 2 .Os .Sh NAME @@ -40,7 +40,6 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/types.h .In unistd.h .Ft int .Fn setuid "uid_t uid" -- cgit v1.1 From 635cc4fb3bf7e0488a778b15d9576c1aac4cc197 Mon Sep 17 00:00:00 2001 From: kevlo Date: Tue, 15 Dec 2015 15:19:06 +0000 Subject: Remove sys/types.h due to STANDARDS and unistd.h also includes sys/types.h. --- lib/libc/sys/brk.2 | 3 +-- lib/libc/sys/getgid.2 | 3 +-- lib/libc/sys/getpid.2 | 3 +-- lib/libc/sys/read.2 | 3 +-- lib/libc/sys/write.2 | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/sys/brk.2 b/lib/libc/sys/brk.2 index 31dea32..0a529ee 100644 --- a/lib/libc/sys/brk.2 +++ b/lib/libc/sys/brk.2 @@ -28,7 +28,7 @@ .\" @(#)brk.2 8.4 (Berkeley) 5/1/95 .\" $FreeBSD$ .\" -.Dd July 12, 1999 +.Dd December 15, 2015 .Dt BRK 2 .Os .Sh NAME @@ -38,7 +38,6 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/types.h .In unistd.h .Ft int .Fn brk "const void *addr" diff --git a/lib/libc/sys/getgid.2 b/lib/libc/sys/getgid.2 index b03040b..5bd2a94 100644 --- a/lib/libc/sys/getgid.2 +++ b/lib/libc/sys/getgid.2 @@ -28,7 +28,7 @@ .\" @(#)getgid.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd December 15, 2015 .Dt GETGID 2 .Os .Sh NAME @@ -38,7 +38,6 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/types.h .In unistd.h .Ft gid_t .Fn getgid void diff --git a/lib/libc/sys/getpid.2 b/lib/libc/sys/getpid.2 index aefa770..ab69f71 100644 --- a/lib/libc/sys/getpid.2 +++ b/lib/libc/sys/getpid.2 @@ -28,7 +28,7 @@ .\" @(#)getpid.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd November 2, 2006 +.Dd December 15, 2015 .Dt GETPID 2 .Os .Sh NAME @@ -38,7 +38,6 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/types.h .In unistd.h .Ft pid_t .Fn getpid void diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2 index e99665f..a0a7be8 100644 --- a/lib/libc/sys/read.2 +++ b/lib/libc/sys/read.2 @@ -28,7 +28,7 @@ .\" @(#)read.2 8.4 (Berkeley) 2/26/94 .\" $FreeBSD$ .\" -.Dd September 11, 2013 +.Dd December 15, 2015 .Dt READ 2 .Os .Sh NAME @@ -40,7 +40,6 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/types.h .In unistd.h .Ft ssize_t .Fn read "int fd" "void *buf" "size_t nbytes" diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2 index a06e7c9..0bfe565 100644 --- a/lib/libc/sys/write.2 +++ b/lib/libc/sys/write.2 @@ -28,7 +28,7 @@ .\" @(#)write.2 8.5 (Berkeley) 4/2/94 .\" $FreeBSD$ .\" -.Dd September 11, 2013 +.Dd December 15, 2015 .Dt WRITE 2 .Os .Sh NAME @@ -40,7 +40,6 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/types.h .In unistd.h .Ft ssize_t .Fn write "int fd" "const void *buf" "size_t nbytes" -- cgit v1.1