Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Mar 1998 13:02:27 +0200 (MET DST)
From:      Wolfgang Helbig <helbig@Informatik.BA-Stuttgart.DE>
To:        ache@FreeBSD.ORG (Andrey A. Chernov)
Cc:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: bin/6164
Message-ID:  <199803301102.NAA22390@rvc1.informatik.ba-stuttgart.de>
In-Reply-To: <199803300920.BAA08095@freefall.freebsd.org> from "Andrey A. Chernov" at "Mar 30, 98 01:20:30 am"

next in thread | previous in thread | raw e-mail | index | archive | help
> Synopsis: adjkerntz failed
> 
> State-Changed-From-To: open-closed
> State-Changed-By: ache
> State-Changed-When: Mon Mar 30 01:18:05 PST 1998
> State-Changed-Why: 
> crontab changed to run adjkerntz -a at 05:01 too

Hmm. The reason for this warning message (``non existent UCT time'')
is an erraneous use of mktime(3): mktime(3) *always* assumes
that the passed tm structure (utc) holds *local* time, even if the
parameter is filled by gmtime(3). 
At March 29th 4:01 CEST gmtime() put 2:01 into utc, which is correct.
Then mktime(3) assumes March 29th 2:01 *local* time which does not exist.
(In Germany March 29th 1:59 CET is followed by March 29th 3:00 CEST)

A fix is to use local.tm_gmtoff to get UTC-time from local time, as in
this diff:
This works in FreeBSD 3.0 and FreeBSD 2.2.5:

Wolfgang
Index: adjkerntz.c
===================================================================
RCS file: /usr/cvsroot/src/sbin/adjkerntz/adjkerntz.c,v
retrieving revision 1.21
diff -u -r1.21 adjkerntz.c
--- adjkerntz.c	1998/02/25 09:40:21	1.21
+++ adjkerntz.c	1998/03/30 10:29:06
@@ -71,7 +71,7 @@
 	int argc;
 	char **argv;
 {
-	struct tm local, utc;
+	struct tm local;
 	struct timeval tv, *stv;
 	struct timezone tz, *stz;
 	int kern_offset, wall_clock, disrtcset;
@@ -161,13 +161,12 @@
 	local = *localtime(&initial_sec);
 	if (diff == 0)
 		initial_isdst = local.tm_isdst;
-	utc = *gmtime(&initial_sec);
-	local.tm_isdst = utc.tm_isdst = initial_isdst;
+	local.tm_isdst = initial_isdst;
 
 	/* calculate local CMOS diff from GMT */
 
-	utcsec = mktime(&utc);
 	localsec = mktime(&local);
+	utcsec = localsec - local.tm_gmtoff;
 	if (utcsec == -1 || localsec == -1) {
 		/*
 		 * XXX user can only control local time, and it is
@@ -217,11 +216,10 @@
 			initial_isdst = final_isdst;
 			goto recalculate;
 		}
-		utc = *gmtime(&final_sec);
-		local.tm_isdst = utc.tm_isdst = final_isdst;
+		local.tm_isdst =  final_isdst;
 
-		utcsec = mktime(&utc);
 		localsec = mktime(&local);
+		utcsec = localsec - local.tm_gmtoff;
 		if (utcsec == -1 || localsec == -1) {
 		bad_final:
 			/*

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803301102.NAA22390>