summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorKevin Steves <stevesk@cvs.openbsd.org>2007-12-23 22:40:01 +0000
committerKevin Steves <stevesk@cvs.openbsd.org>2007-12-23 22:40:01 +0000
commit3e4084f067c27441f52d3af43c436b82b9cc26d2 (patch)
tree353818c90903d4e2be52dae797b1b3a595cd7ce4 /usr.sbin
parent08faa60e2216333f188c7fcfc778d9f8b2b9c774 (diff)
log a warning one time when we can't open or write the drift file;
also add "(no drift file)" to the adjfreq log message on failure; ok henning@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ntpd/ntpd.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c
index 4c7df9eae62..c9eb586db47 100644
--- a/usr.sbin/ntpd/ntpd.c
+++ b/usr.sbin/ntpd/ntpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.c,v 1.56 2007/12/22 18:26:21 stevesk Exp $ */
+/* $OpenBSD: ntpd.c,v 1.57 2007/12/23 22:40:00 stevesk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -42,7 +42,7 @@ int ntpd_adjtime(double);
void ntpd_adjfreq(double, int);
void ntpd_settime(double);
void readfreq(void);
-void writefreq(double);
+int writefreq(double);
volatile sig_atomic_t quit = 0;
volatile sig_atomic_t reconfig = 0;
@@ -375,6 +375,7 @@ void
ntpd_adjfreq(double relfreq, int wrlog)
{
int64_t curfreq;
+ int r;
if (adjfreq(NULL, &curfreq) == -1) {
log_warn("adjfreq failed");
@@ -386,13 +387,14 @@ ntpd_adjfreq(double relfreq, int wrlog)
* that unit before adding. We log values in part per million.
*/
curfreq += relfreq * 1e9 * (1LL << 32);
+ r = writefreq(curfreq / 1e9 / (1LL << 32));
if (wrlog)
- log_info("adjusting clock frequency by %f to %fppm",
- relfreq * 1e6, curfreq / 1e3 / (1LL << 32));
+ log_info("adjusting clock frequency by %f to %fppm%s",
+ relfreq * 1e6, curfreq / 1e3 / (1LL << 32),
+ r ? "" : " (no drift file)");
if (adjfreq(&curfreq, NULL) == -1)
log_warn("adjfreq failed");
- writefreq(curfreq / 1e9 / (1LL << 32));
}
void
@@ -451,18 +453,31 @@ readfreq(void)
fclose(fp);
}
-void
+int
writefreq(double d)
{
int r;
FILE *fp;
+ static int warnonce = 1;
fp = fopen(DRIFTFILE, "w");
- if (fp == NULL)
- return;
+ if (fp == NULL) {
+ if (warnonce) {
+ log_warn("can't open %s", DRIFTFILE);
+ warnonce = 0;
+ }
+ return 0;
+ }
fprintf(fp, "%e\n", d);
r = ferror(fp);
- if (fclose(fp) != 0 || r != 0)
+ if (fclose(fp) != 0 || r != 0) {
+ if (warnonce) {
+ log_warnx("can't write %s", DRIFTFILE);
+ warnonce = 0;
+ }
unlink(DRIFTFILE);
+ return 0;
+ }
+ return 1;
}