From owner-dev-commits-src-all@freebsd.org Tue Sep 14 15:36:21 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9489066B7BA; Tue, 14 Sep 2021 15:36:21 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from omta001.cacentral1.a.cloudfilter.net (omta001.cacentral1.a.cloudfilter.net [3.97.99.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H86rh2Grdz4VhC; Tue, 14 Sep 2021 15:36:20 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from shw-obgw-4004a.ext.cloudfilter.net ([10.228.9.227]) by cmsmtp with ESMTP id Q5AkmMHjIczbLQATrmmjsd; Tue, 14 Sep 2021 15:36:19 +0000 Received: from spqr.komquats.com ([70.66.148.124]) by cmsmtp with ESMTPA id QATqmAr9KdCHGQATrmJIhA; Tue, 14 Sep 2021 15:36:19 +0000 X-Authority-Analysis: v=2.4 cv=SdyUytdu c=1 sm=1 tr=0 ts=6140c173 a=Cwc3rblV8FOMdVN/wOAqyQ==:117 a=Cwc3rblV8FOMdVN/wOAqyQ==:17 a=kj9zAlcOel0A:10 a=7QKq2e-ADPsA:10 a=6I5d2MoRAAAA:8 a=YxBL1-UpAAAA:8 a=EkcXrb_YAAAA:8 a=a6Yr_-BYhy3xce3D-50A:9 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22 a=Ia-lj3WSrqcvXOmTRaiG:22 a=LK5xJRSDVpKd5WXXoEvA:22 Received: from slippy.cwsent.com (slippy [10.1.1.91]) by spqr.komquats.com (Postfix) with ESMTPS id 9DDDA15A; Tue, 14 Sep 2021 06:53:27 +0000 () Received: from slippy (localhost [127.0.0.1]) by slippy.cwsent.com (8.16.1/8.16.1) with ESMTP id 18EDrPqq022951; Tue, 14 Sep 2021 13:53:26 GMT (envelope-from Cy.Schubert@cschubert.com) Message-Id: <202109141353.18EDrPqq022951@slippy.cwsent.com> X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.7.1 Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Edward Tomasz Napierala cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: ddedf2a11eb2 - main - tzcode: Implement timezone change detection In-reply-to: <202109131442.18DEgDIn043709@gitrepo.freebsd.org> References: <202109131442.18DEgDIn043709@gitrepo.freebsd.org> Comments: In-reply-to Edward Tomasz Napierala message dated "Mon, 13 Sep 2021 14:42:13 +0000." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 14 Sep 2021 13:53:25 +0000 X-CMAE-Envelope: MS4xfHRkrkHXn0gdukaD75BkwOrZcxz5gLe0LVuC0k+VJkJQFiOJNKA5TiGGszk7VJ0WspqShQuAOjvLqwMy8JN4re7OQR+MJgg/T5xmS+uFXX2H75XCRKIw MgaDEtg4/xqLWLuzviY/UzU40sGkbMeTvlQbLd4jC43E4cLhWvpEbx8Nr1V2QK5yku2uClaG7X9ZnGpYJvIRhmrC3bdOJe0HgobZAEr0sDccRfazxN4SN3G5 6FHO/AaotyY5YFH8G9OAMGbZdAyAuqCF+xwpWIAho87RdQ6Y/GeYzoGPqxID+UYTz+UykIRSiT6/G2m8tWijGSKAQDKVd88WlnsJQ1cqXc8= X-Rspamd-Queue-Id: 4H86rh2Grdz4VhC X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of cy.schubert@cschubert.com has no SPF policy when checking 3.97.99.32) smtp.mailfrom=cy.schubert@cschubert.com X-Spamd-Result: default: False [-1.60 / 15.00]; HAS_REPLYTO(0.00)[Cy.Schubert@cschubert.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:16509, ipnet:3.96.0.0/15, country:US]; RCVD_TLS_LAST(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[70.66.148.124:received]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; RCVD_COUNT_FIVE(0.00)[5]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[cschubert.com: no valid DMARC record]; AUTH_NA(1.00)[]; RCVD_IN_DNSWL_NONE(0.00)[3.97.99.32:from]; R_SPF_NA(0.00)[no SPF record]; RWL_MAILSPIKE_VERYGOOD(0.00)[3.97.99.32:from]; MAILMAN_DEST(0.00)[dev-commits-src-main,dev-commits-src-all] X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Sep 2021 15:36:21 -0000 In message <202109131442.18DEgDIn043709@gitrepo.freebsd.org>, Edward Tomasz Nap ierala writes: > The branch main has been updated by trasz: > > URL: https://cgit.FreeBSD.org/src/commit/?id=ddedf2a11eb20af1ee52cb3da70a57c2 > 1904af8f > > commit ddedf2a11eb20af1ee52cb3da70a57c21904af8f > Author: Edward Tomasz Napierala > AuthorDate: 2021-09-12 03:07:26 +0000 > Commit: Edward Tomasz Napierala > CommitDate: 2021-09-12 03:07:58 +0000 > > tzcode: Implement timezone change detection > > Implement optional timezone change detection for local time libc > functions. This is disabled by default; set WITH_DETECT_TZ_CHANGES > to build it. > > Reviewed By: imp > Sponsored by: NetApp, Inc. > Sponsored by: Klara, Inc. > X-NetApp-PR: #47 > Differential Revision: https://reviews.freebsd.org/D30183 > --- > contrib/tzcode/stdtime/localtime.c | 89 ++++++++++++++++++++++++++++ > +- > lib/libc/stdtime/Makefile.inc | 4 ++ > share/mk/src.opts.mk | 1 + > tools/build/options/WITH_DETECT_TZ_CHANGES | 2 + > 4 files changed, 95 insertions(+), 1 deletion(-) > > diff --git a/contrib/tzcode/stdtime/localtime.c b/contrib/tzcode/stdtime/loca > ltime.c > index e221c1fa3964..926b24470e19 100644 > --- a/contrib/tzcode/stdtime/localtime.c > +++ b/contrib/tzcode/stdtime/localtime.c > @@ -354,6 +354,45 @@ settzname(void) > } > } > > +#ifdef DETECT_TZ_CHANGES > +/* > + * Determine if there's a change in the timezone since the last time we chec > ked. > + * Returns: -1 on error > + * 0 if the timezone has not changed > + * 1 if the timezone has changed > + */ > +static int > +change_in_tz(const char *name) > +{ > + static char old_name[PATH_MAX]; > + static struct stat old_sb; > + struct stat sb; > + int error; > + > + error = stat(name, &sb); > + if (error != 0) > + return -1; > + > + if (strcmp(name, old_name) != 0) { > + strlcpy(old_name, name, sizeof(old_name)); > + old_sb = sb; > + return 1; > + } > + > + if (sb.st_dev != old_sb.st_dev || > + sb.st_ino != old_sb.st_ino || > + sb.st_ctime != old_sb.st_ctime || > + sb.st_mtime != old_sb.st_mtime) { > + old_sb = sb; > + return 1; > + } > + > + return 0; > +} > +#else /* !DETECT_TZ_CHANGES */ > +#define change_in_tz(X) 0 > +#endif /* !DETECT_TZ_CHANGES */ > + > static int > differ_by_repeat(const time_t t1, const time_t t0) > { > @@ -379,6 +418,7 @@ register const int doextend; > int stored; > int nread; > int res; > + int ret; > union { > struct tzhead tzhead; > char buf[2 * sizeof(struct tzhead) + > @@ -427,6 +467,22 @@ register const int doextend; > (void) strcat(fullname, name); > name = fullname; > } > + if (doextend == TRUE) { > + /* > + * Detect if the timezone file has changed. Check > + * 'doextend' to ignore TZDEFRULES; the change_in_tz() > + * function can only keep state for a single file. > + */ > + ret = change_in_tz(name); > + if (ret <= 0) { > + /* > + * Returns -1 if there was an error, > + * and 0 if the timezone had not changed. > + */ > + free(fullname); > + return ret; > + } > + } > if ((fid = _open(name, OPEN_MODE)) == -1) { > free(fullname); > return -1; > @@ -1209,12 +1265,43 @@ gmtload(struct state *const sp) > (void) tzparse(gmt, sp, TRUE); > } > > +#ifdef DETECT_TZ_CHANGES > +static int > +recheck_tzdata() > +{ > + static time_t last_checked; > + struct timespec now; > + time_t current_time; > + int error; > + > + /* > + * We want to recheck the timezone file every 61 sec. > + */ > + error = clock_gettime(CLOCK_MONOTONIC, &now); > + if (error <= 0) { > + /* XXX: Can we somehow report this? */ > + return 0; > + } > + > + current_time = now.tv_sec; > + if ((current_time - last_checked > 61) || > + (last_checked > current_time)) { > + last_checked = current_time; > + return 1; > + } > + > + return 0; > +} > +#else /* !DETECT_TZ_CHANGES */ > +#define recheck_tzdata() 0 > +#endif /* !DETECT_TZ_CHANGES */ > + > static void > tzsetwall_basic(int rdlocked) > { > if (!rdlocked) > _RWLOCK_RDLOCK(&lcl_rwlock); > - if (lcl_is_set < 0) { > + if (lcl_is_set < 0 && recheck_tzdata() == 0) { > if (!rdlocked) > _RWLOCK_UNLOCK(&lcl_rwlock); > return; > diff --git a/lib/libc/stdtime/Makefile.inc b/lib/libc/stdtime/Makefile.inc > index fb0d2b934148..3d483469bc97 100644 > --- a/lib/libc/stdtime/Makefile.inc > +++ b/lib/libc/stdtime/Makefile.inc > @@ -12,6 +12,10 @@ CFLAGS+= -I${SRCTOP}/contrib/tzcode/stdtime -I${LIBC_SRCTO > P}/stdtime > > CFLAGS.localtime.c= -fwrapv > > +.if ${MK_DETECT_TZ_CHANGES} != "no" > +CFLAGS+= -DDETECT_TZ_CHANGES > +.endif > + > MAN+= ctime.3 strftime.3 strptime.3 time2posix.3 > MAN+= tzfile.5 > > diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk > index 28e18260affd..ff894d3b3517 100644 > --- a/share/mk/src.opts.mk > +++ b/share/mk/src.opts.mk > @@ -196,6 +196,7 @@ __DEFAULT_NO_OPTIONS = \ > BHYVE_SNAPSHOT \ > CLANG_EXTRAS \ > CLANG_FORMAT \ > + DETECT_TZ_CHANGES \ > DTRACE_TESTS \ > EXPERIMENTAL \ > HESIOD \ > diff --git a/tools/build/options/WITH_DETECT_TZ_CHANGES b/tools/build/options > /WITH_DETECT_TZ_CHANGES > new file mode 100644 > index 000000000000..6a2d18473892 > --- /dev/null > +++ b/tools/build/options/WITH_DETECT_TZ_CHANGES > @@ -0,0 +1,2 @@ > +.\" $FreeBSD$ > +Make the time handling code detect changes to the timezone files. > Hi, This patch caused all of the machines on my network to display UTC. After reboot everything was ok. However moments ago my screen locked while typing on my laptop. The time is now UTC instead of PDT. TZ is still set to America/Vancouver. Changing the TZ makes no difference. -- Cheers, Cy Schubert FreeBSD UNIX: Web: https://FreeBSD.org NTP: Web: https://nwtime.org The need of the many outweighs the greed of the few.