From owner-freebsd-questions@FreeBSD.ORG Fri Aug 7 19:20:25 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 64CF4106566C for ; Fri, 7 Aug 2009 19:20:25 +0000 (UTC) (envelope-from glarkin@FreeBSD.org) Received: from mail1.sourcehosting.net (113901-app1.sourcehosting.net [72.32.213.11]) by mx1.freebsd.org (Postfix) with ESMTP id 3F1C98FC08 for ; Fri, 7 Aug 2009 19:20:25 +0000 (UTC) Received: from 68-189-245-235.dhcp.oxfr.ma.charter.com ([68.189.245.235] helo=cube.entropy.prv) by mail1.sourcehosting.net with esmtp (Exim 4.69 (FreeBSD)) (envelope-from ) id 1MZUzF-000ETx-L4; Fri, 07 Aug 2009 15:20:23 -0400 Received: from [127.0.0.1] (fireball.entropy.prv [192.168.1.12]) by cube.entropy.prv (Postfix) with ESMTP id CEE1B32B6550; Fri, 7 Aug 2009 15:20:21 -0400 (EDT) Message-ID: <4A7C7E75.5000503@FreeBSD.org> Date: Fri, 07 Aug 2009 15:20:21 -0400 From: Greg Larkin Organization: The FreeBSD Project User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: Peter Steele References: <4A7C4007.9000506@FreeBSD.org> In-Reply-To: X-Enigmail-Version: 0.96.0 OpenPGP: id=1C940290 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) Cc: freebsd-questions@freebsd.org Subject: Re: How is time zone change signalled? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: glarkin@FreeBSD.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Aug 2009 19:20:25 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Peter Steele wrote: >> Did you try unsetting TZ and then calling tzset()? The man page > implies that doing so will force a reread of /etc/localtime >> (http://www.freebsd.org/cgi/man.cgi?query=tzset&sourceid=opensearch): >> >> "The tzset() function initializes time conversion information used by > the library routine localtime(3). The environment variable TZ specifies > how this is done. >> If TZ does not appear in the environment, the best available > approximation to local wall clock time, as specified by the > tzfile(5)-format file /etc/localtime is used." >> I haven't tested it, though, and I'm no timezone expert, so I may be > completely off-base! > > Yes, I've tried the tzset function. I'm basically doing the equivalent > of these steps after the Java app changes time zone and updates > /etc/localtime: > > time_t date = time(NULL); > unsetenv("TZ"); > tzset(); > printf("time zone is %s/%s", tzname[0], tzname[1]); > struct tm* locTime = localtime(&date); > printf("%02d:%02d:%02d", locTime->tm_hour, locTime->tm_min, > locTime->tm_sec); > > The time printed is still based on the old time zone though. The tzname > variable that is set by tzset() still shows for example EDT even if I > have just changed the time zone to PDT. If I stop and restart the C app, > the time is correct, and tzname is then PDT instead of EDT. > > I'm very puzzled on what I'm supposed to do to kick start the C time > zone. We do not want to have to restart our C apps for something as > trivial as this. > Hi Peter, Ok, just wanted to make sure you tried unsetting TZ before calling tzset(). I couldn't tell from your original message. In any case, the man page makes it sound like it should work. I'm really rusty on C programming, but I had a look in /usr/src/lib/libc/stdtime/localtime.c, and it appears that /etc/localtime should be reloaded, although this comment at the beginning of tzload() gives me pause: /* XXX The following is from OpenBSD, and I'm not sure it is correct */ I wonder if you'd get more insight by asking the question in -hackers. Perhaps there are some libc experts listening there. Cheers, Greg - -- Greg Larkin http://www.FreeBSD.org/ - The Power To Serve http://www.sourcehosting.net/ - Ready. Set. Code. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFKfH510sRouByUApARAjbKAJ9hjsl4X28JjVeZu/3RddR083/+ewCghkUY DF+xiTuRUKKnP1wlySTeMsc= =oZqF -----END PGP SIGNATURE-----