Re: [chrony-dev] [PATCH v4 4/5] leapdb: support leap-seconds.list as second source |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: Re: [chrony-dev] [PATCH v4 4/5] leapdb: support leap-seconds.list as second source
- From: Patrick Oppenlander <patrick.oppenlander@xxxxxxxxx>
- Date: Thu, 8 Feb 2024 14:35:35 +1100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707363346; x=1707968146; darn=chrony.tuxfamily.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1/07oXhV4TgcayMhMNxkBJjaBoTx9KKnmo7SXOyzw0o=; b=XFCbB8aqqnGVm1obxAUiLCt/2qrk3dcHwT95Rye9dlOTeaQ3GmgrOtYhHKJWhQrTDB IobO3eKR91NR1owSzYF3dqbOb/g1ql84qdXtjMUEhDv+n3HI8waeB4V5vU9vxBnJnif/ jtERWHYk1vFlMDUs8t0MvaE70yXC2TxjNwkZkfwlRGE46kp9rlVmx8BP0tbSaF0VxViQ kNQE3wbt6xvrUcYsVymp9/2EV0Mght67SFEwPGgSfLQe0jbPaqBIgTi3kPhJ2fKBhTib NT1khJdXRSU5GLPI9eTOoKuvVFBSzHw6co+CFA9qkzQD/M1zA+6nj9d7NWODoQyp0PB/ 3zoQ==
On Wed, Feb 7, 2024 at 9:35 PM Miroslav Lichvar <mlichvar@xxxxxxxxxx> wrote:
>
> On Wed, Feb 07, 2024 at 04:29:43PM +1100, patrick.oppenlander@xxxxxxxxx wrote:
> > + while (fgets(line, sizeof line, f) > 0) {
> > + int64_t lsl_when;
> > + int lsl_tai_offset;
> > + char *p;
> > +
> > + /* Ignore blank lines */
> > + for (p = line; *p && isspace(*p); ++p);
> > + if (!*p)
> > + continue;
> > +
> > + if (*line == '#') {
> > + /* Update time line starts with #$ */
> > + if (line[1] == '$' && sscanf(line + 2, "%"SCNd64, &lsl_updated) != 1)
> > + goto error;
> > + /* Expiration time line starts with #@ */
> > + if (line[1] == '@' && sscanf(line + 2, "%"SCNd64, &lsl_expiry) != 1)
> > + goto error;
> > + /* Comment or a special comment we don't care about */
> > + continue;
> > + }
> > +
> > + /* Leap entry */
> > + if (sscanf(line, "%"SCNd64" %d", &lsl_when, &lsl_tai_offset) != 2)
> > + goto error;
> > +
> > + if (when == lsl_when) {
> > + if (lsl_tai_offset > prev_lsl_tai_offset)
> > + lsl_leap = LEAP_InsertSecond;
> > + else if (lsl_tai_offset < prev_lsl_tai_offset)
> > + lsl_leap = LEAP_DeleteSecond;
> > + /* When is rounded to the end of the day, so offset hasn't changed yet! */
> > + *tai_offset = prev_lsl_tai_offset;
> > + } else if (when > lsl_when)
> > + *tai_offset = lsl_tai_offset;
> > +
> > + prev_lsl_tai_offset = lsl_tai_offset;
> > + }
> > +
> > + /* Make sure the file looks sensible */
> > + if (!feof(f) || !lsl_updated || !lsl_expiry)
> > + goto error;
>
> The error path taken here and in the loop logs an error message, but
> the leap and TAI offset values can already be accepted at that point.
> I think either they should be saved to temporary variables, or the
> loop should stop when a matching entry is found, so the error message
> is not logged when the result is used.
Thanks for pointing that out. I'll go with temporary variables. I
think it's better not to use the values if the file looks bogus.
> Everything else looks good to me. Thanks for your work on this.
Thanks for spending the time to review it,
Patrick
> --
> Miroslav Lichvar
>
>
> --
> 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.