]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Check for errors when writing new drift files
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 10 Sep 2012 14:44:19 +0000 (16:44 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 10 Sep 2012 15:31:56 +0000 (17:31 +0200)
reference.c
rtc_linux.c

index 863f5af27993226bda39ed5e4875cff2a31e5690..ad1f5dd45758093562c795067a084b12a070d776 100644 (file)
@@ -314,9 +314,12 @@ update_drift_file(double freq_ppm, double skew)
   }
 
   /* Write the frequency and skew parameters in ppm */
-  fprintf(out, "%20.4f %20.4f\n", freq_ppm, 1.0e6 * skew);
-
-  fclose(out);
+  if ((fprintf(out, "%20.4f %20.4f\n", freq_ppm, 1.0e6 * skew) < 0) |
+      fclose(out)) {
+    LOG(LOGS_WARN, LOGF_Reference, "Could not write to temporary driftfile %s.tmp",
+        drift_file);
+    return;
+  }
 
   /* Clone the file attributes from the existing file if there is one. */
 
index dc79574b58a342caf12da8f36b8d0db744090305..c1dc601e753ed039e8e987a67be0dc2a430858ed 100644 (file)
@@ -470,10 +470,13 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate)
   }
 
   /* Gain rate is written out in ppm */
-  fprintf(out, "%1d %ld %.6f %.3f\n",
-          valid,ref_time, offset, 1.0e6 * rate);
-
-  fclose(out);
+  if ((fprintf(out, "%1d %ld %.6f %.3f\n",
+          valid,ref_time, offset, 1.0e6 * rate) < 0) |
+      fclose(out)) {
+    LOG(LOGS_WARN, LOGF_RtcLinux, "Could not write to temporary RTC file %s.tmp",
+        coefs_file_name);
+    return RTC_ST_BADFILE;
+  }
 
   /* Clone the file attributes from the existing file if there is one. */