Call tzset() before chroot()

在看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()之前先初始化一些

与时区有关的变量。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值