在看lighttpd源码的时候,发现在chroot()之前调用了tzset()。由于之前都没怎么
考虑过时区的问题,所以觉得比较莫名奇妙,时区和chroot()有什么关系呢?
man tzset发现了问题所在:
If the TZ variable does not appear in the environment, the tzname vari‐
able is initialized with the best approximation of local wall clock
time, as specified by the tzfile(5)-format file localtime found in the
system timezone directory (see below). (One also often sees
/etc/localtime used here, a symlink to the right file in the system
timezone directory.
如果没有设置TZ这个环境变量的话,tzset就会根据/etc/localtime这个文件来设置,
如果chroot()之后,我们就找不到这个文件了。所以要在chroot()之前先初始化一些
与时区有关的变量。