]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Fix writing of drift and RTC files
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 21 Jan 2014 17:18:04 +0000 (18:18 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 21 Jan 2014 17:23:12 +0000 (18:23 +0100)
Without sequence points the driftfile and RTC file could be closed
before new values were written.

reference.c
rtc_linux.c

index 12e6bebf2e0a1563d31b8c08c91f90d9136cb5b8..3a3af1e2160c487ec25a5bd96619d06be4f0dd1d 100644 (file)
@@ -290,6 +290,7 @@ update_drift_file(double freq_ppm, double skew)
   struct stat buf;
   char *temp_drift_file;
   FILE *out;
+  int r1, r2;
 
   /* Create a temporary file with a '.tmp' extension. */
 
@@ -311,8 +312,9 @@ update_drift_file(double freq_ppm, double skew)
   }
 
   /* Write the frequency and skew parameters in ppm */
-  if ((fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew) < 0) |
-      fclose(out)) {
+  r1 = fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew);
+  r2 = fclose(out);
+  if (r1 < 0 || r2) {
     Free(temp_drift_file);
     LOG(LOGS_WARN, LOGF_Reference, "Could not write to temporary driftfile %s.tmp",
         drift_file);
index 8eda9063210e52b9466359d87d71b1ffbed1c79a..91b0cacc90184e1bd1b56c29b2e3f69ceac76f82 100644 (file)
@@ -467,6 +467,7 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate)
   struct stat buf;
   char *temp_coefs_file_name;
   FILE *out;
+  int r1, r2;
 
   /* Create a temporary file with a '.tmp' extension. */
 
@@ -488,9 +489,10 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate)
   }
 
   /* Gain rate is written out in ppm */
-  if ((fprintf(out, "%1d %ld %.6f %.3f\n",
-          valid,ref_time, offset, 1.0e6 * rate) < 0) |
-      fclose(out)) {
+  r1 = fprintf(out, "%1d %ld %.6f %.3f\n",
+               valid, ref_time, offset, 1.0e6 * rate);
+  r2 = fclose(out);
+  if (r1 < 0 || r2) {
     Free(temp_coefs_file_name);
     LOG(LOGS_WARN, LOGF_RtcLinux, "Could not write to temporary RTC file %s.tmp",
         coefs_file_name);