summaryrefslogtreecommitdiffstats
path: root/sbin/adjkerntz
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1994-12-26 10:43:48 +0000
committerache <ache@FreeBSD.org>1994-12-26 10:43:48 +0000
commit6476aa24f141e28eac4c220933f71eea99c98905 (patch)
treeae268318e12644cbb3f21c47755798b26a376495 /sbin/adjkerntz
parent5091693941428b844b51abb7a1a41b5d9b9351fe (diff)
downloadFreeBSD-src-6476aa24f141e28eac4c220933f71eea99c98905.zip
FreeBSD-src-6476aa24f141e28eac4c220933f71eea99c98905.tar.gz
Use timelocal() instead of mktime() hack
Diffstat (limited to 'sbin/adjkerntz')
-rw-r--r--sbin/adjkerntz/adjkerntz.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/sbin/adjkerntz/adjkerntz.c b/sbin/adjkerntz/adjkerntz.c
index 0a0d4a3..d2f6739 100644
--- a/sbin/adjkerntz/adjkerntz.c
+++ b/sbin/adjkerntz/adjkerntz.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1993 by Andrew A. Chernov, Moscow, Russia.
+ * Copyright (C) 1993, 1994 by Andrew A. Chernov, Moscow, Russia.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -53,6 +53,7 @@ char copyright[] =
#include "pathnames.h"
+/*#define DEBUG*/
#define REPORT_PERIOD (30*60)
void fake() {}
@@ -129,13 +130,11 @@ again:
initial_sec = tv.tv_sec;
local = *localtime(&initial_sec);
utc = *gmtime(&initial_sec);
- utc.tm_isdst = local.tm_isdst; /* Use current timezone for mktime(), */
- /* because it assumed local time */
/* calculate local CMOS diff from GMT */
- utcsec = mktime(&utc);
- localsec = mktime(&local);
+ utcsec = timelocal(&utc);
+ localsec = timelocal(&local);
if (utcsec == -1 || localsec == -1) {
/*
* XXX user can only control local time, and it is
@@ -150,6 +149,9 @@ again:
goto again;
}
offset = utcsec - localsec;
+#ifdef DEBUG
+ fprintf(stderr, "Initial offset: %ld secs\n", offset);
+#endif
mib[0] = CTL_MACHDEP;
mib[1] = CPU_ADJKERNTZ;
@@ -168,7 +170,9 @@ again:
diff = offset - tz.tz_minuteswest * 60 - kern_offset;
if (diff != 0) {
-
+#ifdef DEBUG
+ fprintf(stderr, "Initial diff: %ld secs\n", diff);
+#endif
/* Yet one step for final time */
final_sec = tv.tv_sec + diff;
@@ -176,11 +180,9 @@ again:
/* 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);
+ utcsec = timelocal(&utc);
+ localsec = timelocal(&local);
if (utcsec == -1 || localsec == -1) {
/*
* XXX as above. The user has even less control,
@@ -194,6 +196,9 @@ again:
goto again;
}
offset = utcsec - localsec;
+#ifdef DEBUG
+ fprintf(stderr, "Final offset: %ld secs\n", offset);
+#endif
/* correct the kerneltime for this diffs */
/* subtract kernel offset, if present, old offset too */
@@ -201,6 +206,9 @@ again:
diff = offset - tz.tz_minuteswest * 60 - kern_offset;
if (diff != 0) {
+#ifdef DEBUG
+ fprintf(stderr, "Final diff: %ld secs\n", diff);
+#endif
tv.tv_sec += diff;
tv.tv_usec = 0; /* we are restarting here... */
stv = &tv;
OpenPOWER on IntegriCloud