nginx 中ngx_timezone_update()函数在LInux系统上的工作原理

最近在看Nginx源码,ngx_init_cycle()函数的第一项任务是ngx_timezone_update(),定义在src/os/unix/ngx_time.c中。其主要功能是更新时区,此函数的定义如下(只截取出

Linux部分,因为这是个包含条件编译的函数),经gdb调试,确实是运行的这一部分代码:

void
ngx_timezone_update(void)
{
time_t s;
struct tm *t;
char buf[4];

s = time(0);
t = localtime(&s);
strftime(buf, 4, "%H", t);

}

表面上看获取了一下本地时间,以及将小时输出到局部变量buf中,根本看不出和时区有任何联系。

该函数相关注释如下:

Linux does not test /etc/localtime change in localtime(), but may stat("/etc/localtime") several times in every strftime(),
therefore we use it to update timezone.

Linux在localtime()函数中并不检测/etc/localtime的变化,但是在每次调用strftime()时会stat("/etc/localtime")几次,所以我们使用它来更新时区。

我是一脸懵b,有木有?stat()只是获取文件状态,怎么就可以更新时区了?

查了半天没查到相关资料,请教大神,望不吝赐教!

http://blog.csdn.net/hyhnoproblem/article/details/42685913