mailing list of musl libc
 help / color / mirror / code / Atom feed
* ctime, timezone?
@ 2014-05-01 20:37 John Mudd
  2014-05-01 20:56 ` Josiah Worcester
  2014-05-01 21:57 ` John Mudd
  0 siblings, 2 replies; 9+ messages in thread
From: John Mudd @ 2014-05-01 20:37 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 405 bytes --]

Am I doing something wrong? I expected roughly the same time when running
the musl version.


$ cat test_ctime.c
#include <stdio.h>
#include <time.h>

int main()
{
    time_t t = time(0);
    printf("%s", ctime(&t));
}
$


$ gcc  test_ctime.c   -o test_ctime
$ test_ctime
Thu May  1 16:33:16 2014
$


$ musl-gcc -fno-stack-protector    test_ctime.c   -o test_ctime
$ test_ctime
Thu May  1 20:33:46 2014
$

[-- Attachment #2: Type: text/html, Size: 769 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ctime, timezone?
  2014-05-01 20:37 ctime, timezone? John Mudd
@ 2014-05-01 20:56 ` Josiah Worcester
  2014-05-01 21:57   ` Josiah Worcester
  2014-05-01 21:57 ` John Mudd
  1 sibling, 1 reply; 9+ messages in thread
From: Josiah Worcester @ 2014-05-01 20:56 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

On Thu, May 1, 2014 at 3:37 PM, John Mudd <johnbmudd@gmail.com> wrote:

> Am I doing something wrong? I expected roughly the same time when running
> the musl version.
>
> $ gcc  test_ctime.c   -o test_ctime
> $ test_ctime
> Thu May  1 16:33:16 2014
> $
>
>
> $ musl-gcc -fno-stack-protector    test_ctime.c   -o test_ctime
> $ test_ctime
> Thu May  1 20:33:46 2014
> $
>

It looks as though glibc and musl have different ideas of what the timezone
is. Could you print out the contents of the $TZ variable, and if
/etc/localtime is a symlink, could you tell us where that points to?

[-- Attachment #2: Type: text/html, Size: 1067 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ctime, timezone?
  2014-05-01 20:56 ` Josiah Worcester
@ 2014-05-01 21:57   ` Josiah Worcester
  0 siblings, 0 replies; 9+ messages in thread
From: Josiah Worcester @ 2014-05-01 21:57 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 580 bytes --]

On Thu, May 1, 2014 at 3:56 PM, Josiah Worcester <josiahw@gmail.com> wrote:

> It looks as though glibc and musl have different ideas of what the
> timezone is. Could you print out the contents of the $TZ variable, and if
> /etc/localtime is a symlink, could you tell us where that points to?
>
>
Ah. Quick look at the musl source makes it clear what's going on. musl does
not look at /etc/localtime for the time zone. If TZ is unset it defaults to
UTC. Try export TZ=your-zoneinfo-timezone.

(relatedly, it is possibly desirable to have the timezone code examine
/etc/localtime)

[-- Attachment #2: Type: text/html, Size: 1020 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ctime, timezone?
  2014-05-01 20:37 ctime, timezone? John Mudd
  2014-05-01 20:56 ` Josiah Worcester
@ 2014-05-01 21:57 ` John Mudd
  2014-05-01 22:00   ` John Mudd
  1 sibling, 1 reply; 9+ messages in thread
From: John Mudd @ 2014-05-01 21:57 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 787 bytes --]

$ echo $TZ

$ set | grep TZ
$
I don't have $TZ set at all.

$ ls -l /etc/localtime
-rw-r--r-- 1 root root 3519 Apr 24 18:13 /etc/localtime
$


Thanks, works as expected now with $TZ set.

$ export TZ='America/New_York'
$ test_ctime
Thu May  1 17:54:29 2014
$




On Thu, May 1, 2014 at 4:37 PM, John Mudd <johnbmudd@gmail.com> wrote:

> Am I doing something wrong? I expected roughly the same time when running
> the musl version.
>
>
> $ cat test_ctime.c
> #include <stdio.h>
> #include <time.h>
>
> int main()
> {
>     time_t t = time(0);
>     printf("%s", ctime(&t));
> }
> $
>
>
> $ gcc  test_ctime.c   -o test_ctime
> $ test_ctime
> Thu May  1 16:33:16 2014
> $
>
>
> $ musl-gcc -fno-stack-protector    test_ctime.c   -o test_ctime
> $ test_ctime
> Thu May  1 20:33:46 2014
> $
>

[-- Attachment #2: Type: text/html, Size: 1672 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ctime, timezone?
  2014-05-01 21:57 ` John Mudd
@ 2014-05-01 22:00   ` John Mudd
  2014-05-01 22:18     ` Josiah Worcester
  2014-05-01 22:47     ` Laurent Bercot
  0 siblings, 2 replies; 9+ messages in thread
From: John Mudd @ 2014-05-01 22:00 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 314 bytes --]

Hmm, I'd like to install my app at 4,000 locations around the country. Can
I avoid explicitly setting $TZ?


On Thu, May 1, 2014 at 5:57 PM, John Mudd <johnbmudd@gmail.com> wrote:

>
>
> Thanks, works as expected now with $TZ set.
>
> $ export TZ='America/New_York'
> $ test_ctime
> Thu May  1 17:54:29 2014
> $
>

[-- Attachment #2: Type: text/html, Size: 740 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: ctime, timezone?
  2014-05-01 22:00   ` John Mudd
@ 2014-05-01 22:18     ` Josiah Worcester
  2014-05-02  5:06       ` Timo Teras
  2014-05-01 22:47     ` Laurent Bercot
  1 sibling, 1 reply; 9+ messages in thread
From: Josiah Worcester @ 2014-05-01 22:18 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 567 bytes --]

On Thu, May 1, 2014 at 5:00 PM, John Mudd <johnbmudd@gmail.com> wrote:

> Hmm, I'd like to install my app at 4,000 locations around the country. Can
> I avoid explicitly setting $TZ?
>
>
With unpatched musl, not really. In the do_tzset function in __tz.c, I
think changing the
"if (!s || !*s) s = __gmt;" to simply "if (!s || !*s) s =
"/etc/localtime";" should do it, though I wouldn't say for sure without
testing.
If you simply don't want to have to deal with manually setting TZ to match
the /etc/localtime definition everywhere, TZ=/etc/localtime should suffice.

[-- Attachment #2: Type: text/html, Size: 1016 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: ctime, timezone?
  2014-05-01 22:00   ` John Mudd
  2014-05-01 22:18     ` Josiah Worcester
@ 2014-05-01 22:47     ` Laurent Bercot
  1 sibling, 0 replies; 9+ messages in thread
From: Laurent Bercot @ 2014-05-01 22:47 UTC (permalink / raw)
  To: musl

> Hmm, I'd like to install my app at 4,000 locations around the country. Can I avoid explicitly setting $TZ?

  Unfortunately you can't, because only TZ is standard. /etc/localtime is a glibc-ism.

-- 
  Laurent



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: ctime, timezone?
  2014-05-01 22:18     ` Josiah Worcester
@ 2014-05-02  5:06       ` Timo Teras
  2014-05-02  5:10         ` Timo Teras
  0 siblings, 1 reply; 9+ messages in thread
From: Timo Teras @ 2014-05-02  5:06 UTC (permalink / raw)
  To: musl; +Cc: josiahw

On Thu, 1 May 2014 17:18:32 -0500
Josiah Worcester <josiahw@gmail.com> wrote:

> On Thu, May 1, 2014 at 5:00 PM, John Mudd <johnbmudd@gmail.com> wrote:
> 
> > Hmm, I'd like to install my app at 4,000 locations around the
> > country. Can I avoid explicitly setting $TZ?
> >
> >
> With unpatched musl, not really. In the do_tzset function in __tz.c, I
> think changing the
> "if (!s || !*s) s = __gmt;" to simply "if (!s || !*s) s =
> "/etc/localtime";" should do it, though I wouldn't say for sure
> without testing.
> If you simply don't want to have to deal with manually setting TZ to
> match the /etc/localtime definition everywhere, TZ=/etc/localtime
> should suffice.

This will not work for setuid programs.

I patched musl with:
http://git.alpinelinux.org/cgit/aports/plain/main/musl/2001-default-to-localtime-timezone-if-TZ-is-undefined.patch

This needs latest musl git head to work.

And we configured Alpine to setup /etc/zoneinfo/localtime as symlink to
the proper place.

With the patch you could also symlink /etc/zoneinfo/localtime
-> /etc/localtime and then it'd just work.

- Timo


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: ctime, timezone?
  2014-05-02  5:06       ` Timo Teras
@ 2014-05-02  5:10         ` Timo Teras
  0 siblings, 0 replies; 9+ messages in thread
From: Timo Teras @ 2014-05-02  5:10 UTC (permalink / raw)
  To: Timo Teras; +Cc: musl, josiahw

On Fri, 2 May 2014 08:06:56 +0300
Timo Teras <timo.teras@iki.fi> wrote:

> On Thu, 1 May 2014 17:18:32 -0500
> Josiah Worcester <josiahw@gmail.com> wrote:
> 
> > On Thu, May 1, 2014 at 5:00 PM, John Mudd <johnbmudd@gmail.com>
> > wrote:
> > 
> > > Hmm, I'd like to install my app at 4,000 locations around the
> > > country. Can I avoid explicitly setting $TZ?
> > >
> > >
> > With unpatched musl, not really. In the do_tzset function in
> > __tz.c, I think changing the
> > "if (!s || !*s) s = __gmt;" to simply "if (!s || !*s) s =
> > "/etc/localtime";" should do it, though I wouldn't say for sure
> > without testing.
> > If you simply don't want to have to deal with manually setting TZ to
> > match the /etc/localtime definition everywhere, TZ=/etc/localtime
> > should suffice.
> 
> This will not work for setuid programs.
> 
> I patched musl with:
> http://git.alpinelinux.org/cgit/aports/plain/main/musl/2001-default-to-localtime-timezone-if-TZ-is-undefined.patch
> 
> This needs latest musl git head to work.
> 
> And we configured Alpine to setup /etc/zoneinfo/localtime as symlink
> to the proper place.
> 
> With the patch you could also symlink /etc/zoneinfo/localtime
> -> /etc/localtime and then it'd just work.

Or ship /usr/share/zoneinfo/localtime -> /etc/localtime symlink with
your libc package. I think this is how it's often done with glibc.

The TZ=":name" files are searched from:
  /usr/share/zoneinfo/
  /share/zoneinfo/
  /etc/zoneinfo/

- Timo


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-05-02  5:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-01 20:37 ctime, timezone? John Mudd
2014-05-01 20:56 ` Josiah Worcester
2014-05-01 21:57   ` Josiah Worcester
2014-05-01 21:57 ` John Mudd
2014-05-01 22:00   ` John Mudd
2014-05-01 22:18     ` Josiah Worcester
2014-05-02  5:06       ` Timo Teras
2014-05-02  5:10         ` Timo Teras
2014-05-01 22:47     ` Laurent Bercot

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).