Re: Filesystem date 7 hours ahead of system clock

From: Jesse Pollard (pollard@tomcat.admin.navo.hpc.mil)
Date: Thu Jul 13 2000 - 17:52:35 EST


 Rick Stevens <rstevens@publichost.com>:
> This is weird. When I touch a file, the timestamp on the file is
> 7 hours ahead of the system time (I'm in the US/Pacific time zone,
> which is UTC -0700):
>
> [root@srv01 /root]# date
> Thu Jul 13 13:57:03 PDT 2000
> [root@srv01 /root]# touch fred
> [root@srv01 /root]# ls -l fred
> -rw-r--r-- 1 root root 0 Jul 13 20:57 fred
>
> Both the system and hardware clocks are set to the current local time
> and correct timezone (PDT).
>
> So, being the stupid person I am, I must ask a couple of questions.
> First, just how the devil does the filesystem forget about the date
> offset? And the second question: How do I fix it?
>
> I need an answer fairly quickly, so feel free to call/email directly.
> This is wreaking havoc with one of my customers' databases.

Ummmm This actually shouldn't be a problem (except for some backup
utilities...)

The system and file system are both running on GMT (or UTC...). Only
it appears the "ls" isn't applying the "proper" offset before displaying the
date. From the example the offset being used is +7 hours. This IS the
correct offset if the local time (as displayed by date) were actually GMT....

perhaps the TZ environment variable is incorrect? I don't easily see
how date would be using a different value than ls though.

Another possibility -

The hardware clock (supported by the BIOS) is running in local time.
The kernel thinks it is GMT/UTC - This would cause the kernel to subtract
the offset, making the display appear wrong. If someone then sets the
date (using local time) then the kernel would suddenly be 7 hours ahead.
When ls display the stored date (assuming it is GMT and applies the offset)
the displayed date now has an additional 7 hours added.

I think I'm overlooking something here.... that explaination doesn't
seem right.

A third, less likely assumes the the directory is actually mounted from
a disk server with an incorrect time clock. The touch creates a file, but
the date applied comes from the disk server. When "ls" lookes at the disk
file date, it recieves the GMT entry from the server and suddenly appears
to be in the future (which it is as far as the client can tell).

I've only seen this type of thing from the third expaination. What makes
this unlikely is that the directory appears to be /root, which should
always be a local filesystem.

I've never seen the kernel really have the wrong date, but I have seen
ls do some funny things when displaying dates.

The following perl script may help:
==================================== detail.p =====================
#!/usr/local/bin/perl

print $ARGV[0],"\n";
@v = stat($ARGV[0]);
printf("\t local time UTC time\n");
@t8 = localtime($v[8]);
printf("\tatime= %4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d",
                  $t8[5]+1900,$t8[4],$t8[3],$t8[2],$t8[1],$t8[0]);
@t8 = gmtime($v[8]);
printf("\t%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d\n",
                  $t8[5]+1900,$t8[4],$t8[3],$t8[2],$t8[1],$t8[0]);

@t9 = localtime($v[9]);
printf("\tmtime= %4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d",
                  $t9[5]+1900,$t9[4],$t9[3],$t9[2],$t9[1],$t9[0]);
@t9 = gmtime($v[9]);
printf("\t%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d\n",
                  $t9[5]+1900,$t9[4],$t9[3],$t9[2],$t9[1],$t9[0]);

@t10 = localtime($v[10]);
printf("\tctime= %4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d",
                  $t10[5]+1900,$t10[4],$t10[3],$t10[2],$t10[1],$t10[0]);
@t10 = gmtime($v[10]);
printf("\t%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d\n",
                 $t10[5]+1900,$t10[4],$t10[3],$t10[2],$t10[1],$t10[0])
====================================================

This script prints the file atime,mtime and ctime out in two columns,
the first is local time, the other is GMT/UTC.

The output I get (for the script) looks like:

merlin 75% ./detail.p detail.p
detail.p
                 local time UTC time
        atime= 2000/06/13 17:40:32 2000/06/13 22:40:32
        mtime= 2000/06/13 17:45:41 2000/06/13 22:45:41
        ctime= 2000/06/13 17:45:41 2000/06/13 22:45:41
merlin 76%

As can be seen, the local time is 5 hours behind the UTC time. That is
why I suspect ls of not using the local TZ environment variable for
some reason in your case. ls never does tell whether it is using
local or UTC, but by convention it is supposed to use local time.

You may not have a problem unless some shell/perl scripts are looking at
directory listings for dates.

Hope this helps.

-------------------------------------------------------------------------
Jesse I Pollard, II
Email: pollard@navo.hpc.mil

Any opinions expressed are solely my own.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:18 EST