diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-06-15 21:15:22 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-06-15 21:15:22 +0200 |
commit | 68befdff72202821477a6c2ee7ced18600f92786 (patch) | |
tree | f7795b31c5cc9d52bfa50eb4adbac9b2219189b3 /sys/src/cmd/aux/timesync.c | |
parent | 7bdb1818129fff62aa1cce463153485a7eefe856 (diff) |
timesync: let timesync set the rtc with respect to gmtdelta
Diffstat (limited to 'sys/src/cmd/aux/timesync.c')
-rw-r--r-- | sys/src/cmd/aux/timesync.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sys/src/cmd/aux/timesync.c b/sys/src/cmd/aux/timesync.c index 1926b0486..f45060dc2 100644 --- a/sys/src/cmd/aux/timesync.c +++ b/sys/src/cmd/aux/timesync.c @@ -118,6 +118,7 @@ static int ntptimediff(NTPserver *ns); static int openfreqfile(void); static vlong readfreqfile(int fd, vlong ohz, vlong minhz, vlong maxhz); static long rtctime(void); +static void setrtctime(long); static vlong sample(long (*get)(void)); static void setpriority(void); static void setrootid(char *d); @@ -145,6 +146,7 @@ main(int argc, char **argv) int i, t, fd, nservenet; int secs; /* sampling period */ int tsecs; /* temporary sampling period */ + int syncrtc; uvlong hz, minhz, maxhz, period, nhz; vlong diff, accuracy, taccuracy; char *servenet[4]; @@ -153,6 +155,7 @@ main(int argc, char **argv) type = Fs; /* by default, sync with the file system */ debug = 0; + syncrtc = 1; accuracy = 1000000LL; /* default accuracy is 1 millisecond */ nservenet = 0; tsecs = secs = MinSampleSecs; @@ -225,6 +228,7 @@ main(int argc, char **argv) case 'r': type = Rtc; stratum = 0; + syncrtc = 0; break; case 'U': type = Utc; @@ -440,6 +444,10 @@ main(int argc, char **argv) settime(-1, 0, diff, 4*secs); } + + if(syncrtc) + setrtctime(s->stime / SEC); + if(debug) fprint(2, "δ %lld avgδ %lld f %lld\n", diff, avgerr, hz); @@ -1233,6 +1241,21 @@ rtctime(void) return strtoul(b, 0, 10)+gmtdelta; } +static void +setrtctime(long t) +{ + static int f = -1; + + if(f < 0) + f = open("/dev/rtc", OWRITE|OCEXEC); + if(f < 0) + return; + if(seek(f, 0, 0) < 0 || fprint(f, "%ld", t-gmtdelta) < 0){ + close(f); + f = -1; + } +} + /* * Sample a clock. We wait for the clock to always |