system-config-date的实现机制

system-config-date解析
本文解析了system-config-date的实现机制,包括如何通过date命令和hwclock命令让时间生效,以及如何通过复制时区文件和更新配置文件来设置时区。同时讨论了时区列表数据的来源,并提出了针对移动设备的时区选择优化方案。

system-config-date的实现机制

转载时请注明出处和作者联系方式:http://blog.youkuaiyun.com/absurd

作者联系方式:Li XianJing <xianjimli at hotmail dot com>

更新时间:2006-12-19

前几天我们要开发一个时间(时区)设置的应用程序,所以花了一点时间去看config-date的实现,这里简单说一下config-date的工作机制和我们面临的一些问题。

1. 让时间生效分为两步,这是在dateBackend.py里实现的。首先调用date命令设置系统时间,然后调用hwclock命令把时间写到BIOS中。

2. 设置时区也分为两步,这是在timezoneBackend.py里实现的。首先把时区数据文件(/usr/share/zoneinfo/时区)拷贝到文件/etc/localtime,然后把时区信息写入到文件/etc/sysconfig/clock。中间还有一步是把时区数据文件拷贝到文件/var/spool/postfix/etc/localtime,这一步是可选的,取决于该文件是否存在,一般系统上/var/spool/postfix/etc/localtime都不存在,具体用途不清楚。

3. 时区列表数据是从文件/usr/share/zoneinfo/zone.tab中读取的。该文件记录了主要城市的时区信息,每一行描述一个城市:城市所在的国家、经/纬度和对应的时区数据文件等等。

4. glibc的代码来看,localtimetzset两个函数只使用了/etc/localtime文件,该文件是一个二进制文件,结构有点复杂,没看得太明白。

我们遇到两个问题:

1. /usr/share/zoneinfo/zone.tab文件太大,有400多行,手机上屏幕比较小,用户很难找到想要的时区。解决办法:对它进行裁减,主要保留主要城市。

2. /usr/share/zoneinfo/zone.tab里记录的是城市精确的经/纬度,通过该经/纬度计算出来的偏移时间是小数,这倒不是大问题,取整就行了。问题是像上海和重庆这两个城市,我们希望得到同样8小时的时间偏移,这不可能根据经/纬度计算。时区数据文件中是有相关信息的,因为localtime这样的函数都可以正常工作。但是该文件的结构有点复杂,没搞明白。解决办法:自己定义了一张表记录这些信息,或者在选择时区时,时间不做同步更新。

不知大家遇到过同样的问题没有,是否有更好的办法呢?

~~end~~

As an AI language model, I cannot provide the exact solution to this error as it depends on the context of the code and the system configuration. However, here are some possible solutions that you can try: 1. Install pkg-config: Make sure that pkg-config is installed on your system. If not, install it using the package manager of your operating system. 2. Check the PATH environment variable: Ensure that the PATH environment variable includes the path to pkg-config. You can check it by running the command "echo $PATH" in your terminal. 3. Check pkg-config configuration: Check if pkg-config is configured correctly. You can do this by running the command "pkg-config --version" in your terminal. If it returns a version number, then the configuration is correct. 4. Check autoconf installation: Ensure that autoconf is installed on your system. If not, install it using the package manager of your operating system. 5. Check configure.ac file: Check the configure.ac file and make sure that it is correctly configured. You can also try to regenerate the configure script by running the command "autoreconf -ivf". 6. Update dependencies: Check if all the dependencies required by your project are installed and up-to-date. Update them if necessary. 7. Check for typos: Check if there are any typos in the configure.ac file, especially in the name of the package or library that you are trying to configure. If these solutions do not work, you might need to provide more information about your system configuration and the context of the code to get a more specific solution.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值