This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc 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]

[Bug libc/5184] New: strftime stats /etc/localtime too much


Running "2.3.6.ds1-8" from Debian unstable on x86_64, the following is observed
using strace:

...
open("/etc/localtime", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x2b47ac40b000
read(3, "TZif\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\0\4\0"..., 4096) = 1017
close(3)                                = 0
munmap(0x2b47ac40b000, 4096)            = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
time(NULL)                              = 1192500153
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1017, ...}) = 0
exit_group(0)                           = ?
Process 9465 detached
adi@xxxxx:~/tmp$ cat strftime-stats.c
#include <time.h>

int main(void)
{
    char buf[40];
    time_t now;
    
    now = time(0);
    strftime(buf, sizeof(buf), "%F %T", localtime(&now));
    now = time(0);
    strftime(buf, sizeof(buf), "%F %T", localtime(&now));
    return 0;
}

It appears that strftime is stat(2)ing /etc/localtime for every date component.
This could result in an inconsistent date representation being generated if it
races with an update to /etc/localtime.  If /etc/localtime is updated atomically
using rename(2), strftime should generate a date entirely using the old data or
entirely using the new, not a partial mix.  Even ignoring modifications to
/etc/localtime, this is certainly a performance bug (6 stats instead of one).

-- 
           Summary: strftime stats /etc/localtime too much
           Product: glibc
           Version: 2.3.6
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: adi at hexapodia dot org
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=5184

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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