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 | |
parent | 7bdb1818129fff62aa1cce463153485a7eefe856 (diff) | |
download | plan9front-68befdff72202821477a6c2ee7ced18600f92786.tar.xz |
timesync: let timesync set the rtc with respect to gmtdelta
-rwxr-xr-x | rc/bin/fshalt | 2 | ||||
-rwxr-xr-x | rc/bin/setrtc | 4 | ||||
-rw-r--r-- | sys/src/cmd/aux/timesync.c | 23 |
3 files changed, 23 insertions, 6 deletions
diff --git a/rc/bin/fshalt b/rc/bin/fshalt index 6dbf51c13..ad3dc52c8 100755 --- a/rc/bin/fshalt +++ b/rc/bin/fshalt @@ -15,8 +15,6 @@ case * path=(/bin) builtin cd / -setrtc - unmount /mnt/consoles >[2]/dev/null kill consolefs | rc # don't compete with /mnt/consoles sleep 1 diff --git a/rc/bin/setrtc b/rc/bin/setrtc deleted file mode 100755 index 43ccdc09e..000000000 --- a/rc/bin/setrtc +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/rc -# setrtc - set real-time clock to current system time -if (test -e '#r/rtc') - awk '{print $1}' /dev/time >'#r/rtc' 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 |