Re: [chrony-dev] [PATCH v3 2/5] leapdb: make twice per day check logic common

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


On Thu, Dec 7, 2023 at 1:24 PM Bill Unruh <unruh@xxxxxxxxxxxxxx> wrote:
>
> Why twice per day? Leapseconds occur at most twice per year (and recently 0
> times per year for the past 7 years). So, if you want, do it at UTC 00:00 on
> Jun 30 and Dec 31.

Hi Bill,

I've added chrony-dev to CC.

This patch just reorganises the existing code and (hopefully)
maintains the current behaviour. I've been careful to try not to
change existing behaviour in this area in an attempt to avoid
introducing bugs.

I believe the original intention is to detect updates to the system
timezone database, although, as you correctly point out, the check
could potentially be more infrequent.

As it stands, doing it twice a day seems pretty harmless to me.

Patrick

> William G. Unruh __| Canadian Institute for|____ Tel: +1(604)822-3273
> Physics&Astronomy _|___ Advanced Research _|____ Fax: +1(604)822-5324
> UBC, Vancouver,BC _|_ Program in Cosmology |____ unruh@xxxxxxxxxxxxxx
> Canada V6T 1Z1 ____|____ and Gravity ______|_    theory.physics.ubc.ca/
>
> On Thu, 7 Dec 2023, patrick.oppenlander@xxxxxxxxx wrote:
>
> > [CAUTION: Non-UBC Email]
> >
> > From: Patrick Oppenlander <patrick.oppenlander@xxxxxxxxx>
> >
> > We want to do the twice per day check regardless of the data source.
> > Move the check up one level from get_tz_leap() into LDB_GetLeap().
> > ---
> > leapdb.c | 41 ++++++++++++++++++++---------------------
> > 1 file changed, 20 insertions(+), 21 deletions(-)
> >
> > diff --git a/leapdb.c b/leapdb.c
> > index 676a0d5..32f753a 100644
> > --- a/leapdb.c
> > +++ b/leapdb.c
> > @@ -41,24 +41,10 @@ static char *leap_tzname;
> > static NTP_Leap
> > get_tz_leap(time_t when, int *tai_offset)
> > {
> > -  static time_t last_tz_leap_check;
> > -  static NTP_Leap tz_leap;
> > -  static int tz_tai_offset;
> > -
> >   struct tm stm, *tm;
> >   time_t t;
> >   char *tz_env, tz_orig[128];
> > -
> > -  *tai_offset = tz_tai_offset;
> > -
> > -  /* Do this check at most twice a day */
> > -  when = when / (12 * 3600) * (12 * 3600);
> > -  if (last_tz_leap_check == when)
> > -      return tz_leap;
> > -
> > -  last_tz_leap_check = when;
> > -  tz_leap = LEAP_Normal;
> > -  tz_tai_offset = 0;
> > +  NTP_Leap tz_leap = LEAP_Normal;
> >
> >   tm = gmtime(&when);
> >   if (!tm)
> > @@ -79,7 +65,7 @@ get_tz_leap(time_t when, int *tai_offset)
> >   /* Get the TAI-UTC offset, which started at the epoch at 10 seconds */
> >   t = mktime(&stm);
> >   if (t != -1)
> > -    tz_tai_offset = t - when + 10;
> > +    *tai_offset = t - when + 10;
> >
> >   /* Set the time to 23:59:60 and see how it overflows in mktime() */
> >   stm.tm_sec = 60;
> > @@ -102,8 +88,6 @@ get_tz_leap(time_t when, int *tai_offset)
> >   else if (stm.tm_sec == 1)
> >     tz_leap = LEAP_DeleteSecond;
> >
> > -  *tai_offset = tz_tai_offset;
> > -
> >   return tz_leap;
> > }
> >
> > @@ -132,10 +116,25 @@ LDB_Initialise(void)
> > NTP_Leap
> > LDB_GetLeap(time_t when, int *tai_offset)
> > {
> > -  *tai_offset = 0;
> > +  static time_t last_ldb_leap_check;
> > +  static NTP_Leap ldb_leap;
> > +  static int ldb_tai_offset;
> > +
> > +  /* Do this check at most twice a day */
> > +  when = when / (12 * 3600) * (12 * 3600);
> > +  if (last_ldb_leap_check == when)
> > +    goto out;
> > +
> > +  last_ldb_leap_check = when;
> > +  ldb_leap = LEAP_Normal;
> > +  ldb_tai_offset = 0;
> > +
> >   if (leap_tzname)
> > -    return get_tz_leap(when, tai_offset);
> > -  return LEAP_Normal;
> > +    ldb_leap = get_tz_leap(when, &ldb_tai_offset);
> > +
> > +out:
> > +  *tai_offset = ldb_tai_offset;
> > +  return ldb_leap;
> > }
> >
> > /* ================================================== */
> > --
> > 2.43.0
> >
> >
> > --
> > To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
> > For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
> > Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.
> >
> >

--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/