timezone variable not set correctly, bug blocking LSB Conformance
Package: libc6
Version: 2.3.2.ds1-22sarge3
Problem: after calling the C method "ctime" the global variable
"timezone" is not set correctly with certain TZ environment variables.
With TZ=JKL3:10PNM4:40 set, the value of "timezone" is expected to be
11400, but has a nonsense value of 18000.
For a demonstration please see the attched file test.c
This is a libc bug (already in libc Bugzilla (see
http://sourceware.org/bugzilla/show_bug.cgi?id=2865 )), but can be fixed
in Debian.
This would be important for LSB compliance (LSB Runtime tests LSB
runtime tests T.ctime_X 1, T.localtim_X 1, T.mktime_X 1).
LSB test failure message:
with TZ=JKL3:10PNM4:40 ctime() did not set timezone correctly
value of timezone was 18000, expected 11400
A patch for sarge is attached.
Kernel on tested system: 2.6.14-2-686-smp
libc version: 2.3.2.ds1-22sarge3
--
Martin Dittmar Linux Information Systems AG
Fon +49 (0)30 72 62 38-15 Ehrenbergstr 19
mdittmar@linux-ag.com D-10245 Berlin
The Migration Company. _______________________________ www.linux-ag.com
#! /bin/sh -e
# DP: Make __tzfile_default reset __use_tzfile = 0 before returning to tzset_internal
if [ $# -ne 2 ]; then
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
exit 1
fi
case "$1" in
-patch) patch -d "$2" -f --no-backup-if-mismatch -p1 < $0;;
-unpatch) patch -d "$2" -f --no-backup-if-mismatch -R -p1 < $0;;
*)
echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
exit 1
esac
exit 0
--- glibc-2.3.2/time/tzfile.c.dist 2006-06-23 17:32:49.946051496 +0200
+++ glibc-2.3.2/time/tzfile.c 2006-06-23 17:36:12.606973832 +0200
@@ -439,6 +439,10 @@
/* Set the timezone. */
__timezone = -types[0].offset;
+ /* since the user specified a hand-made timezone we dont claim to
+ * use tzfile further on */
+ __use_tzfile = 0;
+
compute_tzname_max (stdlen + dstlen);
}
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
extern int tz;
int set_tz(tzval) char *tzval; {
char *tz;
static char buf[100];
(void) strcpy(buf, "TZ=");
(void) strcat(buf, tzval);
putenv(buf);
tz = getenv("TZ");
if (tz == NULL || strcmp(tz, tzval) != 0)
{
printf("Error setting TZ!");
}
}
int main() {
printf("timezone at start of program:%ld \n",timezone);
printf("running ctime with \"586185855L\" as time \n");
time_t mytime = 586185855L;
char * c = ctime(&mytime);
printf("timezone:%ld\n",timezone);
set_tz("JKL3:10");
ctime(&mytime);
printf("timezone with TZ=JKL3:10 : %ld \n",timezone);
set_tz("PNM4:40");
ctime(&mytime);
printf("timezone with TZ=PNM4:40 : %ld \n",timezone);
set_tz("JKL3:10PNM4:40");
ctime(&mytime);
printf("timezone with TZ=JKL3:10PNM4:40 (!!! expected 11400 !!!): %ld\n",timezone);
}
Reply to: