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: Miroslav Lichvar <mlichvar@xxxxxxxxxx>
- Date: Wed, 7 Feb 2024 11:35:19 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707302122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2xXZZ3PJbEQmRMe1TLxqAD7z8Nf+9cX58w2yxg8927I=; b=bOy+iRTTyHahq8D+No40hCGqJvhHGDsRNkKO5xFmHkrRep8uIRUDCZPDMeRY9G1yRK7EDu RQ1KmstUhyRdHIKFipu0JFXy/XR3Jy3ywYQC9C9Vj0Ph6U2g13g9FEXaBiNWPJReoRfk1T qrseZrvpD1omrznVq3uh6+3GR4wF3Es=
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.
Everything else looks good to me. Thanks for your work on this.
--
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.