ref: 06718c365e048eda20380c45bc7f9eb821ad8a85
parent: 8da4e2782515f03f38a2b4e5a6ad6727ad16be15
author: cinap_lenrek <cinap_lenrek@localhost>
date: Wed Jun 15 17:15:22 EDT 2011
timesync: let timesync set the rtc with respect to gmtdelta
--- a/rc/bin/fshalt
+++ b/rc/bin/fshalt
@@ -15,8 +15,6 @@
path=(/bin)
builtin cd /
-setrtc
-
unmount /mnt/consoles >[2]/dev/null
kill consolefs | rc # don't compete with /mnt/consoles
sleep 1
--- a/rc/bin/setrtc
+++ /dev/null
@@ -1,4 +1,0 @@
-#!/bin/rc
-# setrtc - set real-time clock to current system time
-if (test -e '#r/rtc')
- awk '{print $1}' /dev/time >'#r/rtc'--- a/sys/src/cmd/aux/timesync.c
+++ b/sys/src/cmd/aux/timesync.c
@@ -118,6 +118,7 @@
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 @@
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 @@
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 @@
case 'r':
type = Rtc;
stratum = 0;
+ syncrtc = 0;
break;
case 'U':
type = Utc;
@@ -440,6 +444,10 @@
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);
@@ -1231,6 +1239,21 @@
break;
}
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;
+ }
}
--
⑨