Unix Programming - change timezone question

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2005 > change timezone question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author change timezone question
Zach

2005-06-22, 5:57 pm

I have a running daemon, which periodically writes a message with
timestamp to a log file. Then I change timezone by symbolic linking
/etc/localtime to different timezone file in /usr/share/zoninfo/. The
logged timestamps are still the old timezone time. My question is that
how can I notify the daemon the timezone change and let it log the
current timezone time? Following is the code of daemon program:

do
{
get_time(&time); // my function

if(!localtime_r(&time, &result)) break;

// log message with time to file
...
} while (1);

Thanks a lot!
Zach

Rich Teer

2005-06-22, 8:49 pm

On Wed, 22 Jun 2005, Zach wrote:

> I have a running daemon, which periodically writes a message with
> timestamp to a log file. Then I change timezone by symbolic linking
> /etc/localtime to different timezone file in /usr/share/zoninfo/. The


WHy are you changing timezones on the fly? would be my first question.

--
Rich Teer, SCNA, SCSA, OpenSolaris CAB member

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich
Chris Friesen

2005-06-22, 8:49 pm

Rich Teer wrote:

> WHy are you changing timezones on the fly? would be my first question.


One obvious possibility would be an embedded system that boots from
flash with a default, then gets the "real" timezone via the network.

I've had to deal with this one personally, and it was a pain. We ended
up putting a hook in glibc to re-read the timestamp on the timezone file
whenever it needed it to check if it had been changed, and re-reading
the timezone if needed.

Chris
Zach

2005-06-22, 8:49 pm

our product provides a functionality to let user change timezone. But
after that, I found that the log message time cannot reflect the new
change. Is there any solution or workaround to it?

David Schwartz

2005-06-22, 8:49 pm


"Zach" <chenzhao73@hotmail.com> wrote in message
news:1119484517.725181.296400@g47g2000cwa.googlegroups.com...

> our product provides a functionality to let user change timezone. But
> after that, I found that the log message time cannot reflect the new
> change. Is there any solution or workaround to it?


There are a lot of solutions, none of them pretty. One solution would be
to have a logging daemon that checks the timezone file and restarts itself
if the file is modified. The main daemon could communicate with the logging
daemon through a pipe or socket.

Another solution is to log in UTC time and have the log display program
convert the times. This has a lot of advantages.

DS


Zach

2005-06-22, 8:49 pm

after "re-reading the timezone", how did you change the daemon's
setting to the new timezone?

David Schwartz

2005-06-22, 8:49 pm


"Zach" <chenzhao73@hotmail.com> wrote in message
news:1119488562.673565.114950@g14g2000cwa.googlegroups.com...

> after "re-reading the timezone", how did you change the daemon's
> setting to the new timezone?


He is talking about inside the daemon in the first place. Once the
daemon re-reads the timezone, its settings have changed.

DS


Chris Friesen

2005-06-23, 2:48 am

Zach wrote:
> our product provides a functionality to let user change timezone. But
> after that, I found that the log message time cannot reflect the new
> change. Is there any solution or workaround to it?


Depends on your design. With a standard system, your only real option
is to restart syslogd (and any other program that cares about the
timezone) after you change the timezone.

If you control the entire system, a cleaner solution is to do everything
in UTC and convert to the user's timezone at viewing time, as David
suggested.

Alternately, you could put a hook in glibc so that it rechecks the
timestamp on the timezone before all conversions to human readable time.

Chris
James Antill

2005-06-23, 8:48 pm

On Wed, 22 Jun 2005 16:03:52 -0700, Zach wrote:

> I have a running daemon, which periodically writes a message with
> timestamp to a log file. Then I change timezone by symbolic linking
> /etc/localtime to different timezone file in /usr/share/zoninfo/. The
> logged timestamps are still the old timezone time. My question is that
> how can I notify the daemon the timezone change and let it log the
> current timezone time?


The easies option is to use a version of localtime() that will re-read
/etc/localtime if it changes, for instance glibc on Linux does this.
As David said, another good solution is to use UTC in log messages.

--
James Antill -- james@and.org
http://www.and.org/vstr/httpd

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com