mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 00:15:07 -05:00
rtc: avoid printing and scanning time_t
With the latest glibc it's now possible to define _TIME_BITS=64 to get 64-bit time_t on 32-bit Linux systems. This breaks the %ld printf/scanf modifier used with the RTC drift timestamp. Process it as a double.
This commit is contained in:
@@ -434,6 +434,7 @@ setup_config(void)
|
|||||||
static void
|
static void
|
||||||
read_coefs_from_file(void)
|
read_coefs_from_file(void)
|
||||||
{
|
{
|
||||||
|
double ref_time;
|
||||||
FILE *in;
|
FILE *in;
|
||||||
|
|
||||||
if (!tried_to_load_coefs) {
|
if (!tried_to_load_coefs) {
|
||||||
@@ -444,11 +445,12 @@ read_coefs_from_file(void)
|
|||||||
|
|
||||||
if (coefs_file_name &&
|
if (coefs_file_name &&
|
||||||
(in = UTI_OpenFile(NULL, coefs_file_name, NULL, 'r', 0))) {
|
(in = UTI_OpenFile(NULL, coefs_file_name, NULL, 'r', 0))) {
|
||||||
if (fscanf(in, "%d%ld%lf%lf",
|
if (fscanf(in, "%d%lf%lf%lf",
|
||||||
&valid_coefs_from_file,
|
&valid_coefs_from_file,
|
||||||
&file_ref_time,
|
&ref_time,
|
||||||
&file_ref_offset,
|
&file_ref_offset,
|
||||||
&file_rate_ppm) == 4) {
|
&file_rate_ppm) == 4) {
|
||||||
|
file_ref_time = ref_time;
|
||||||
} else {
|
} else {
|
||||||
LOG(LOGS_WARN, "Could not read coefficients from %s", coefs_file_name);
|
LOG(LOGS_WARN, "Could not read coefficients from %s", coefs_file_name);
|
||||||
}
|
}
|
||||||
@@ -472,7 +474,7 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate)
|
|||||||
return RTC_ST_BADFILE;
|
return RTC_ST_BADFILE;
|
||||||
|
|
||||||
/* Gain rate is written out in ppm */
|
/* Gain rate is written out in ppm */
|
||||||
fprintf(out, "%1d %ld %.6f %.3f\n", valid, ref_time, offset, 1.0e6 * rate);
|
fprintf(out, "%1d %.0f %.6f %.3f\n", valid, (double)ref_time, offset, 1.0e6 * rate);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
|
||||||
/* Rename the temporary file to the correct location */
|
/* Rename the temporary file to the correct location */
|
||||||
|
|||||||
Reference in New Issue
Block a user