This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ctime.stp timezone patch


I've decided not to check in this change after all. It does not take daylight savings time changes into account (which some of us experienced this weekend). Upon further review of the kernel code, I'm not convinced that sys_tz is always set. Certainly sys_tz.tz_dsttime doesn't appear to be adjusted automatically. I think a better approach is to let the script writer adjust for timezone if desired. Here's an example:

#!/bin/bash

tz=`date "+%z"`
tz_sign=`echo $tz | cut -c1`
tz_hours=`echo $tz | cut -c2-3`
tz_mins=`echo $tz | cut -c4-5`

# Variables preceded by 10# ensures those values are treated as
# decimal numbers. Necessary because bash assumes numbers with
# a leading 0 are octal.
TZ_ADJUST=$tz_sign$((10#$tz_hours*60*60+10#$tz_mins*60))

stap -e '
probe begin {
time = gettimeofday_s() + '$TZ_ADJUST'
printf("%s\n", ctime(time))
}
'


- Mike

Mike Mason wrote:
Given that no one has responded, I assume it's okay to check in this change. I'll do so today.

- Mike Mason

Mike Mason wrote:
The following patch adjusts the output of ctime() for the
system timezone. It works for me. Can anyone think of a reason why this patch should not be included? Worst case, if
sys_tz isn't set for some reason, the result will be GMT
as before.


- Mike Mason


--- src/tapset/ctime.stp 2006-05-11 08:58:41.000000000 -0700 +++ src.save2/tapset/ctime.stp 2006-10-21 08:29:44.000000000 -0700 @@ -13,8 +13,6 @@ * * Note that the real C library ctime() function puts a newline ('\n') * character at the end of the string that this function does not. - * Also note that since the kernel has no concept of timezones, the - * returned time is always in GMT. * * This code was adapted from the newlib mktm_r() and asctime_r() * functions. In newlib, mktm_r.c states that it was adapted from @@ -24,6 +22,10 @@ * Changes copyright (C) 2006 Red Hat Inc. */

+%{
+#include <linux/time.h>
+%}
+
function ctime:string(epochsecs:long)
%{

@@ -38,6 +40,8 @@
#define EPOCH_YEAR      1970
#define EPOCH_WDAY      4

+extern struct timezone sys_tz;
+
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)


    static const int mon_lengths[2][MONSPERYEAR] = {
@@ -71,7 +75,10 @@
    int tm_wday;        /* day of the week */

    lcltime = THIS->epochsecs;
-   +
+    /* adjust for timezone */
+    lcltime -= sys_tz.tz_minuteswest * 60;
+
    days = ((long)lcltime) / SECSPERDAY;
    rem = ((long)lcltime) % SECSPERDAY;
    while (rem < 0)




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]