|
|
| Next: GCC problem |
| Author |
Message |
dbansal External

Since: Jul 18, 2007 Posts: 3
|
Posted: Wed Jul 18, 2007 12:22 pm Post subject: How to set timezone Archived from groups: comp>os>linux>development>system (more info?) |
|
|
Hi all,
Can somebody help me in setting timezone in Linux kernel using C
programming. I am able to set time value but not timezone.
Thanks in advance,
-- dbansal |
|
| Back to top |
|
 |
Bill Marcum External

Since: Dec 18, 2006 Posts: 293
|
Posted: Wed Jul 18, 2007 2:04 pm Post subject: Re: How to set timezone [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
On Wed, 18 Jul 2007 12:22:48 -0000, dbansal
<bansal.dk RemoveThis @gmail.com> wrote:
>
>
> Hi all,
>
> Can somebody help me in setting timezone in Linux kernel using C
> programming. I am able to set time value but not timezone.
>
Write it to /etc/timezone or set the environment variable TZ. On an
IBM-compatible system, you might also need to set UTC depending whether
the CMOS clock is set to UTC or local time. On Debian systems UTC is
set in /etc/default/rcS.
--
"Pascal is Pascal is Pascal is dog meat."
-- M. Devine and P. Larson, Computer Science 340 |
|
| Back to top |
|
 |
Tim Southerwood External

Since: Apr 23, 2007 Posts: 113
|
Posted: Wed Jul 18, 2007 4:35 pm Post subject: Re: How to set timezone [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
dbansal wrote:
> Hi all,
>
> Can somebody help me in setting timezone in Linux kernel using C
> programming. I am able to set time value but not timezone.
>
> Thanks in advance,
> -- dbansal
Hi
You don't set it in the kernel, it's handled in userspace by glibc
or whatever libc library you have. glibc refers to /etc/localtime on my
Ubuntu 7.04 system, so I guess you will need to locate the correct file to
update and modify that, which may be a different config file followed by
running a utility program.
Can be very distribution dependant - which distro are you running?
Cheers
Tim |
|
| Back to top |
|
 |
ellis External

Since: Apr 02, 2004 Posts: 193
|
Posted: Thu Jul 19, 2007 8:48 am Post subject: Re: How to set timezone [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
In article <1184761368.517903.128880.TakeThisOut@m37g2000prh.googlegroups.com>,
dbansal <bansal.dk.TakeThisOut@gmail.com> wrote:
>Can somebody help me in setting timezone in Linux kernel using C
Why would the kernel care cabout the timezone?
--
http://www.spinics.net/lists/kernel/ |
|
| Back to top |
|
 |
David Schwartz External

Since: Jun 01, 2007 Posts: 87
|
Posted: Sat Jul 21, 2007 6:18 am Post subject: Re: How to set timezone [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
On Jul 19, 1:48 am, el... DeleteThis @no.spam () wrote:
> In article <1184761368.517903.128... DeleteThis @m37g2000prh.googlegroups.com>,
>
> dbansal <bansal... DeleteThis @gmail.com> wrote:
> >Can somebody help me in setting timezone in Linux kernel using C
>
> Why would the kernel care cabout the timezone?
Because some filesystems track times in local time and the kernel's
main time reference is in UTC. So to generate and understand those
times, the kernel needs to know the current offset between local time
and UTC time.
DS |
|
| Back to top |
|
 |
David Schwartz External

Since: Jun 01, 2007 Posts: 87
|
Posted: Wed Aug 01, 2007 10:20 pm Post subject: Re: How to set timezone [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
On Aug 1, 4:51 pm, LEE Sau Dan <dan... DeleteThis @informatik.uni-freiburg.de>
wrote:
> >>>>> "David" == David Schwartz <dav... DeleteThis @webmaster.com> writes:
>
> >> Why would the kernel care cabout the timezone?
>
> David> Because some filesystems track times in local time and the
> David> kernel's main time reference is in UTC.
>
> No. The filesystems keep timestamps in UTC, too. They're parts of
> the kernel. So, like the kernel, they don't care what the local time
> is.
You have no idea what you are talking about. Here's some code from the
Linux kernel:
static inline time_t local_to_gmt(struct super_block *s, time32_t t)
{
extern struct timezone sys_tz;
return t + sys_tz.tz_minuteswest * 60 + hpfs_sb(s)-
>sb_timeshift;
}
static inline time32_t gmt_to_local(struct super_block *s, time_t t)
{
extern struct timezone sys_tz;
return t - sys_tz.tz_minuteswest * 60 - hpfs_sb(s)-
>sb_timeshift;
}
And here's some more:
/* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1
70). */
int date_dos2unix(unsigned short time, unsigned short date)
{
int month, year, secs;
/*
* first subtract and mask after that... Otherwise, if
* date == 0, bad things happen
*/
month = ((date >> 5) - 1) & 15;
year = date >> 9;
secs = (time & 31)*2+60*((time >> 5) & 63)+(time >>
11)*3600+86400*
((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3)
== 0 &&
month < 2 ? 1 : 0)+3653);
/* days since 1.1.70 plus 80's leap day */
secs += sys_tz.tz_minuteswest*60;
return secs;
}
And from kernel/time.c:
asmlinkage long sys_gettimeofday(struct timeval __user *tv, struct
timezone __user *tz)
{
if (likely(tv != NULL)) {
struct timeval ktv;
do_gettimeofday(&ktv);
if (copy_to_user(tv, &ktv, sizeof(ktv)))
return -EFAULT;
}
if (unlikely(tz != NULL)) {
if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
return -EFAULT;
}
return 0;
}
Notice the 'sys_tz' variable that holds the *kernel's* time zone?
> Unix is a multiple concurrent user system. Different users may have
> different timezone settings at once. It is not uncommon for a unix
> system to have users simultaneously logged in from different parts of
> the globe, with very different time zones. How do you think the
> kernel and filesystems are handling that, without conflicts and mixing
> up timestamps?
I'm not sure why you care how I think the kernel and filesystems
handle that. It's simple enough to look at the code. The basic get and
set time functions allow you to set and get the system time zone. Some
filesystems simply use the system time zone. Some have a filesystem
time zone that can be set in the superblock of the filesystem.
> Try to open a shell and then "export TZ=GMT" and then do an "ls -l".
> Do you notice that the timestamps shown seem to be different now?
I'm not sure what you think that has to do with anything. This is all
user-space code and tells us nothing about how the kernel's internal
timekeeping works. The kernel could keep all internal times in local
time and convert to GMT to export them to user space (which can then
modify them based on the TZ variable), and this would work exactly the
same. This is basically what Windows does.
> David> So to generate and understand those times, the kernel needs
> David> to know the current offset between local time and UTC time.
> That's a user-interface issue. So, it's delegated to glibc. The
> kernel doesn't care about local time.
No, it's not. Are you reading what I'm writing? What about filesystems
whose on-disk data format uses a local time? Linux supports AmigaFS,
HFS, FAT, and several other filesystems that require local times
internally.
DS |
|
| Back to top |
|
 |
LEE Sau Dan External

Since: Oct 19, 2006 Posts: 78
|
Posted: Thu Aug 02, 2007 2:11 am Post subject: Re: How to set timezone [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
>>>>> "David" == David Schwartz <davids RemoveThis @webmaster.com> writes:
>> Why would the kernel care cabout the timezone?
David> Because some filesystems track times in local time and the
David> kernel's main time reference is in UTC.
No. The filesystems keep timestamps in UTC, too. They're parts of
the kernel. So, like the kernel, they don't care what the local time
is.
Unix is a multiple concurrent user system. Different users may have
different timezone settings at once. It is not uncommon for a unix
system to have users simultaneously logged in from different parts of
the globe, with very different time zones. How do you think the
kernel and filesystems are handling that, without conflicts and mixing
up timestamps?
Try to open a shell and then "export TZ=GMT" and then do an "ls -l".
Do you notice that the timestamps shown seem to be different now?
David> So to generate and understand those times, the kernel needs
David> to know the current offset between local time and UTC time.
That's a user-interface issue. So, it's delegated to glibc. The
kernel doesn't care about local time.
--
Lee Sau Dan §õ¦u´° ~{@nJX6X~}
E-mail: danlee RemoveThis @informatik.uni-freiburg.de
Home page: http://www.informatik.uni-freiburg.de/~danlee |
|
| Back to top |
|
 |
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
| |
|
|