|
@@ -31,6 +31,7 @@ int impotent;
|
|
|
int logging;
|
|
|
int type;
|
|
|
int gmtdelta; // rtc+gmtdelta = gmt
|
|
|
+uvlong avgerr;
|
|
|
|
|
|
// ntp server info
|
|
|
int stratum = 14;
|
|
@@ -95,6 +96,7 @@ enum
|
|
|
|
|
|
static void addntpserver(char *name);
|
|
|
static int adjustperiod(vlong diff, vlong accuracy, int secs);
|
|
|
+static void background(void);
|
|
|
static int caperror(vlong dhz, int tsecs, vlong taccuracy);
|
|
|
static long fstime(void);
|
|
|
static int gettime(vlong *nsec, uvlong *ticks, uvlong *hz); // returns time, ticks, hz
|
|
@@ -130,7 +132,7 @@ main(int argc, char **argv)
|
|
|
int t, fd;
|
|
|
Sample *s, *x, *first, **l;
|
|
|
vlong diff, accuracy, taccuracy;
|
|
|
- uvlong hz, minhz, maxhz, avgerr, period, nhz;
|
|
|
+ uvlong hz, minhz, maxhz, period, nhz;
|
|
|
char *servenet[4];
|
|
|
int nservenet;
|
|
|
char *a;
|
|
@@ -235,6 +237,10 @@ main(int argc, char **argv)
|
|
|
fmtinstall('V', eipfmt);
|
|
|
sysid = getenv("sysname");
|
|
|
|
|
|
+ // detach from the current namespace
|
|
|
+ if(debug)
|
|
|
+ rfork(RFNAMEG);
|
|
|
+
|
|
|
switch(type){
|
|
|
case Fs:
|
|
|
if(argc > 0)
|
|
@@ -254,23 +260,6 @@ main(int argc, char **argv)
|
|
|
|
|
|
setpriority();
|
|
|
|
|
|
- //
|
|
|
- // detach from the current namespace
|
|
|
- //
|
|
|
- if(debug)
|
|
|
- rfork(RFNAMEG);
|
|
|
- else {
|
|
|
- switch(rfork(RFPROC|RFFDG|RFNAMEG|RFNOTEG|RFNOWAIT)){
|
|
|
- case -1:
|
|
|
- sysfatal("forking: %r");
|
|
|
- break;
|
|
|
- case 0:
|
|
|
- break;
|
|
|
- default:
|
|
|
- exits(0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// figure out our time interface and initial frequency
|
|
|
inittime();
|
|
|
gettime(0, 0, &hz);
|
|
@@ -333,7 +322,7 @@ main(int argc, char **argv)
|
|
|
first = nil;
|
|
|
l = &first;
|
|
|
avgerr = accuracy>>1;
|
|
|
- for(;; sleep(tsecs*(1000))){
|
|
|
+ for(;; background(),sleep(tsecs*(1000))){
|
|
|
s = mallocz(sizeof(*s), 1);
|
|
|
diff = 0;
|
|
|
|
|
@@ -988,7 +977,9 @@ ntpsample(void)
|
|
|
x = tns->stratum;
|
|
|
x *= SEC;
|
|
|
x += (vabs(tns->rootdelay+tns->rtt)>>1) + tns->rootdisp + tns->rtt;
|
|
|
-if(debug) fprint(2, "ntp %s rootdelay %lld rootdisp %lld metric %lld\n", tns->name, tns->rootdelay, tns->rootdisp, x);
|
|
|
+ if(debug)
|
|
|
+ fprint(2, "ntp %s rootdelay %lld rootdisp %lld metric %lld\n",
|
|
|
+ tns->name, tns->rootdelay, tns->rootdisp, x);
|
|
|
if(x < metric){
|
|
|
metric = x;
|
|
|
ns = tns;
|
|
@@ -1000,14 +991,10 @@ if(debug) fprint(2, "ntp %s rootdelay %lld rootdisp %lld metric %lld\n", tns->na
|
|
|
|
|
|
// save data for our server
|
|
|
rootdisp = ns->rootdisp;
|
|
|
- rootdelay = ns->rootdelay;
|
|
|
+ rootdelay = ns->rootdelay+ns->rtt;
|
|
|
mydelay = ns->rtt;
|
|
|
x = vabs(ns->dt);
|
|
|
- if(ns->disp == 0LL)
|
|
|
- ns->disp = x;
|
|
|
- else
|
|
|
- ns->disp = (x+3LL*ns->disp)>>2;
|
|
|
- mydisp = ns->disp;
|
|
|
+ mydisp = ns->disp+avgerr;
|
|
|
if(ns->stratum == 0)
|
|
|
stratum = 0;
|
|
|
else
|
|
@@ -1277,3 +1264,25 @@ vabs(vlong x)
|
|
|
else
|
|
|
return (uvlong)x;
|
|
|
}
|
|
|
+
|
|
|
+static void
|
|
|
+background(void)
|
|
|
+{
|
|
|
+ static int inbackground;
|
|
|
+
|
|
|
+ if(inbackground)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if(!debug) {
|
|
|
+ switch(rfork(RFPROC|RFFDG|RFNAMEG|RFNOTEG|RFNOWAIT)){
|
|
|
+ case -1:
|
|
|
+ sysfatal("forking: %r");
|
|
|
+ break;
|
|
|
+ case 0:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ exits(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ inbackground = 1;
|
|
|
+}
|