aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>1993-12-20 01:53:27 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>1993-12-20 01:53:27 +0000
commit0b2318d8437d734354a3cb1c758a6b4829433a20 (patch)
treed6a8d86d72804928f49074601cc62013a9db0bbe /sbin
parent990ac0b7cb3d9fab22b1471d9cc0e0b726879b71 (diff)
downloadsrc-0b2318d8437d734354a3cb1c758a6b4829433a20.tar.gz
src-0b2318d8437d734354a3cb1c758a6b4829433a20.zip
Fix sign of offset diff.
Use Bruce initial/final hour scheme to avoid critical hours.
Notes
Notes: svn path=/head/; revision=882
Diffstat (limited to 'sbin')
-rw-r--r--sbin/adjkerntz/adjkerntz.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/sbin/adjkerntz/adjkerntz.c b/sbin/adjkerntz/adjkerntz.c
index 8cb885cc52b6..f0dbc07e7dd3 100644
--- a/sbin/adjkerntz/adjkerntz.c
+++ b/sbin/adjkerntz/adjkerntz.c
@@ -31,7 +31,7 @@ char copyright[] =
#endif /* not lint */
/*
- * Andrew A. Chernov <ache@astral.msk.su> Dec 15 1993
+ * Andrew A. Chernov <ache@astral.msk.su> Dec 20 1993
*
* Fix kernel time value if machine run wall CMOS clock
* (and /etc/wall_cmos_clock file present)
@@ -59,6 +59,7 @@ int main(argc, argv)
struct timezone tz, *stz;
/* Avoid time_t here, can be unsigned long */
long offset, oldoffset, utcsec, localsec, diff;
+ time_t final_sec;
int ch, init = -1, verbose = 0;
FILE *f;
@@ -125,7 +126,7 @@ int main(argc, argv)
utcsec = mktime(&utc);
localsec = mktime(&local);
if (utcsec == -1 || localsec == -1) {
- fprintf(stderr, "Wrong hour to call\n");
+ fprintf(stderr, "Wrong initial hour to call\n");
return 1;
}
offset = utcsec - localsec;
@@ -133,11 +134,40 @@ int main(argc, argv)
/* correct the kerneltime for this diffs */
/* subtract kernel offset, if present, old offset too */
- diff = oldoffset + tz.tz_minuteswest * 60 - offset;
+ diff = offset - tz.tz_minuteswest * 60 - oldoffset;
+
if (diff != 0) {
- tv.tv_sec += diff;
- tv.tv_usec = 0; /* we are restarting here... */
- stv = &tv;
+
+ /* Yet one step for final time */
+
+ final_sec = tv.tv_sec + diff;
+
+ /* get the actual local timezone difference */
+ local = *localtime(&final_sec);
+ utc = *gmtime(&final_sec);
+ utc.tm_isdst = local.tm_isdst; /* Use current timezone for mktime(), */
+ /* because it assumed local time */
+
+ utcsec = mktime(&utc);
+ localsec = mktime(&local);
+ if (utcsec == -1 || localsec == -1) {
+ fprintf(stderr, "Wrong final hour to call\n");
+ return 1;
+ }
+ offset = utcsec - localsec;
+
+ /* correct the kerneltime for this diffs */
+ /* subtract kernel offset, if present, old offset too */
+
+ diff = offset - tz.tz_minuteswest * 60 - oldoffset;
+
+ if (diff != 0) {
+ tv.tv_sec += diff;
+ tv.tv_usec = 0; /* we are restarting here... */
+ stv = &tv;
+ }
+ else
+ stv = NULL;
}
else
stv = NULL;