Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #26136] localtime(3) calls tzset(3), but localtime_r(3) may not.

1 view
Skip to first unread message

perlbug-...@perl.org

unread,
Feb 7, 2004, 8:49:23 AM2/7/04
to bugs-bi...@netlabs.develooper.com
# New Ticket Created by sag...@sohgoh.net
# Please include the string: [perl #26136]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=26136 >


This is a bug report for perl from sag...@sohgoh.net,
generated with the help of perlbug 1.34 running under perl v5.8.2.


I use cygwin perl package (5.8.2-1) and localtime returns gmtime
as same as #24582.
( http://rt.perl.org/rt3/Ticket/Display.html?id=24582 ).
I noticed that Cygwin 5.8.2-1 package supports thread,
but 5.8.0-5 doesn't, and threaded perl calls localtime_r(3)
instead of localtime(3) as far as my reading.

In cygwin environment (and some other libc),
localtime(3) calls tzset(3), but localtime_r(3) does not.
I should write a patch that calls tzset(3) before localtime_r(3) under
ordinary circumstances, but I'm not familiar to perl sorce code,
thus I show this situation in short C.

#include <stdio.h>
#include <time.h>

int main(int argc, char *argv[]) {
time_t t;
struct tm lctime;

t = time(NULL);
printf("time_t: %d\n", t);
localtime_r(&t, &lctime);
printf("Local: %s", asctime(&lctime));
gmtime_r(&t, &lctime);
printf(" GMT : %s", asctime(&lctime));

printf("call tzset\n");
tzset();
localtime_r(&t, &lctime);
printf("Local: %s", asctime(&lctime));
gmtime_r(&t, &lctime);
printf(" GMT : %s", asctime(&lctime));

exit(0);
}

Local timezone is JST:GMT+09, and this short program shows:

Local: Sat Feb 7 13:47:25 2004 (wrong -- GMT)
GMT : Sat Feb 7 13:47:25 2004
call tzset
Local: Sat Feb 7 22:47:25 2004 (ok :)
GMT : Sat Feb 7 13:47:25 2004

---
Flags:
category=core
severity=medium
---
Site configuration information for perl v5.8.2:

Configured by Gerrit at Fri Nov 7 12:03:56 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
Platform:
osname=cygwin, osvers=1.5.5(0.9432), archname=cygwin-thread-multi-64int
uname='cygwin_nt-5.0 troubardix 1.5.5(0.9432) 2003-09-20 16:31 i686 unknown unknown cygwin '
config_args='-de -Dmksymlinks -Duse64bitint -Dusethreads -Doptimize=-O2 -Dman3ext=3pm'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=undef uselongdouble=undef
usemymalloc=y, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -fno-strict-aliasing',
optimize='-O2',
cppflags='-DPERL_USE_SAFE_PUTENV -fno-strict-aliasing'
ccversion='', gccversion='3.3.1 (cygming special)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='ld2', ldflags =' -s -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib /lib
libs=-lgdbm -ldb -lcrypt -lgdbm_compat
perllibs=-lcrypt -lgdbm_compat
libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' -s'
cccdlflags=' ', lddlflags=' -s -L/usr/local/lib'

Locally applied patches:

---
@INC for perl v5.8.2:
/usr/lib/perl5/5.8.2/cygwin-thread-multi-64int
/usr/lib/perl5/5.8.2
/usr/lib/perl5/site_perl/5.8.2/cygwin-thread-multi-64int
/usr/lib/perl5/site_perl/5.8.2
/usr/lib/perl5/site_perl
.

---
Environment for perl v5.8.2:
CYGWIN_HOME=D:\home\sagawa
HOME=/home/sagawa
LANG=ja_JP.eucJP
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/sagawa/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/usr/local/tex/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/usr/X11R6/bin
PERLDOC_PAGER=less -R
PERL_BADLANG (unset)
SHELL=/bin/zsh

--
Akihiro SAGAWA <sag...@sohgoh.net>

Yitzchak Scott-Thoennes

unread,
Feb 8, 2004, 1:49:51 PM2/8/04
to perl5-...@perl.org
On Sat, Feb 07, 2004 at 01:49:23PM -0000, "sag...@sohgoh.net (via RT)" <perlbug-...@perl.org> wrote:
> I use cygwin perl package (5.8.2-1) and localtime returns gmtime
> as same as #24582.
> ( http://rt.perl.org/rt3/Ticket/Display.html?id=24582 ).
> I noticed that Cygwin 5.8.2-1 package supports thread,
> but 5.8.0-5 doesn't, and threaded perl calls localtime_r(3)
> instead of localtime(3) as far as my reading.

Thank you so much for tracking this down.



> In cygwin environment (and some other libc),
> localtime(3) calls tzset(3), but localtime_r(3) does not.

I'm not sure if this is a perl bug or cygwin/newlib bug.
I've asked on the cygwin list:

http://cygwin.com/ml/cygwin/2004-02/msg00346.html

As a temporary workaround, a tzset() call during startup might be a
good idea.

0 new messages