Browse Source

Save the computed clock drift and use it on startup. ok deraadt@

henning@
OPENBSD_4_0
otto 18 years ago
parent
commit
041bde21e5
2 changed files with 47 additions and 2 deletions
  1. +45
    -1
      src/usr.sbin/ntpd/ntpd.c
  2. +2
    -1
      src/usr.sbin/ntpd/ntpd.h

+ 45
- 1
src/usr.sbin/ntpd/ntpd.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.c,v 1.44 2006/06/21 07:42:00 otto Exp $ */
/* $OpenBSD: ntpd.c,v 1.45 2006/06/22 11:11:25 otto Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -40,6 +40,8 @@ int dispatch_imsg(struct ntpd_conf *);
int ntpd_adjtime(double); int ntpd_adjtime(double);
void ntpd_adjfreq(double); void ntpd_adjfreq(double);
void ntpd_settime(double); void ntpd_settime(double);
void readfreq(void);
void writefreq(double);
volatile sig_atomic_t quit = 0; volatile sig_atomic_t quit = 0;
volatile sig_atomic_t reconfig = 0; volatile sig_atomic_t reconfig = 0;
@ -142,6 +144,7 @@ main(int argc, char *argv[])
chld_pid = ntp_main(pipe_chld, &conf); chld_pid = ntp_main(pipe_chld, &conf);
setproctitle("[priv]"); setproctitle("[priv]");
readfreq();
signal(SIGTERM, sighdlr); signal(SIGTERM, sighdlr);
signal(SIGINT, sighdlr); signal(SIGINT, sighdlr);
@ -362,6 +365,7 @@ ntpd_adjfreq(double relfreq)
if (adjfreq(&curfreq, NULL) == -1) if (adjfreq(&curfreq, NULL) == -1)
log_warn("adjfreq failed"); log_warn("adjfreq failed");
writefreq(curfreq / 1e9 / (1LL << 32));
} }
void void
@ -393,3 +397,43 @@ ntpd_settime(double d)
localtime(&tval)); localtime(&tval));
log_info("set local clock to %s (offset %fs)", buf, d); log_info("set local clock to %s (offset %fs)", buf, d);
} }
void
readfreq(void)
{
FILE *fp;
int64_t current;
double d;
/* if we're adjusting frequency already, don't override */
if (adjfreq(NULL, &current) == -1) {
log_warn("adjfreq failed");
return;
}
if (current != 0)
return;
fp = fopen(DRIFTFILE, "r");
if (fp == NULL)
return;
if (fscanf(fp, "%le", &d) == 1)
ntpd_adjfreq(d);
fclose(fp);
}
void
writefreq(double d)
{
int r;
FILE *fp;
fp = fopen(DRIFTFILE, "w");
if (fp == NULL)
return;
fprintf(fp, "%e\n", d);
r = ferror(fp);
if (fclose(fp) != 0 || r != 0)
unlink(DRIFTFILE);
}

+ 2
- 1
src/usr.sbin/ntpd/ntpd.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.73 2006/06/18 19:38:11 otto Exp $ */
/* $OpenBSD: ntpd.h,v 1.74 2006/06/22 11:11:25 otto Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -32,6 +32,7 @@
#define NTPD_USER "_ntp" #define NTPD_USER "_ntp"
#define CONFFILE "/etc/ntpd.conf" #define CONFFILE "/etc/ntpd.conf"
#define DRIFTFILE "/var/db/ntpd.drift"
#define READ_BUF_SIZE 4096 #define READ_BUF_SIZE 4096


Loading…
Cancel
Save