adjtime之类的系统调用的实现代码从哪里找?

最大的社区版本,Ubuntu的发源地
回复
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

adjtime之类的系统调用的实现代码从哪里找?

#1

帖子 科学之子 » 2016-08-18 21:54

adjtime之类的系统调用的实现代码从哪里找?
man adjtime:

代码: 全选

 EINVAL The adjustment in delta is outside the permitted range.
主要是想知道"range"是什么
不知道去找系统调用实现代码是否是个合适的方法
或者有其它文档描述了这个"range"?
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: adjtime之类的系统调用的实现代码从哪里找?

#2

帖子 vickycq » 2016-08-18 23:10

科学之子 写了:主要是想知道"range"是什么
见 man adjtime "NOTES" 一节末尾
man adjtime 写了:NOTES
The adjustment that adjtime() makes to the clock is carried out in such a manner that the clock is always monotonically increasing. Using adjtime() to adjust the time prevents the problems that can be caused for certain applications (e.g., make(1)) by abrupt positive or negative jumps in the system time.

adjtime() is intended to be used to make small adjustments to the system time. Most systems impose a limit on the adjustment that can be specified in delta. In the glibc implementation, delta must be less than or equal to (INT_MAX / 1000000 - 2) and greater than or equal to (INT_MIN / 1000000 + 2) (respectively 2145 and -2145 seconds on i386).
网搜可得印证
http://lists.ntp.org/pipermail/question ... 08671.html
https://bugs.debian.org/cgi-bin/bugrepo ... bug=697643
科学之子 写了:adjtime之类的系统调用的实现代码从哪里找?不知道去找系统调用实现代码是否是个合适的方法
对于 glibc,见 https://www.gnu.org/software/libc/download.html

sysdeps/unix/sysv/linux/adjtime.c

代码: 全选

#define MAX_SEC	(INT_MAX / 1000000L - 2)
#define MIN_SEC	(INT_MIN / 1000000L + 2)
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

Re: adjtime之类的系统调用的实现代码从哪里找?

#3

帖子 科学之子 » 2016-08-19 1:19

vickycq 写了:
科学之子 写了:主要是想知道"range"是什么
见 man adjtime "NOTES" 一节末尾
man adjtime 写了:NOTES
The adjustment that adjtime() makes to the clock is carried out in such a manner that the clock is always monotonically increasing. Using adjtime() to adjust the time prevents the problems that can be caused for certain applications (e.g., make(1)) by abrupt positive or negative jumps in the system time.

adjtime() is intended to be used to make small adjustments to the system time. Most systems impose a limit on the adjustment that can be specified in delta. In the glibc implementation, delta must be less than or equal to (INT_MAX / 1000000 - 2) and greater than or equal to (INT_MIN / 1000000 + 2) (respectively 2145 and -2145 seconds on i386).
网搜可得印证
http://lists.ntp.org/pipermail/question ... 08671.html
https://bugs.debian.org/cgi-bin/bugrepo ... bug=697643
科学之子 写了:adjtime之类的系统调用的实现代码从哪里找?不知道去找系统调用实现代码是否是个合适的方法
对于 glibc,见 https://www.gnu.org/software/libc/download.html

sysdeps/unix/sysv/linux/adjtime.c

代码: 全选

#define MAX_SEC	(INT_MAX / 1000000L - 2)
#define MIN_SEC	(INT_MIN / 1000000L + 2)
:Adore
那段宏定义是如何找出来的?
我想到的是这样:
grep -r adjtime
找到可疑文件名:adjtime.c
然后"find -name adjtime\.c"

代码: 全选

./ports/sysdeps/unix/sysv/linux/alpha/adjtime.c
./sysdeps/mach/adjtime.c
./sysdeps/mach/hurd/adjtime.c
./sysdeps/unix/sysv/linux/adjtime.c
./time/adjtime.c
根据那个"linux"字样,猜测应该是Linux平台用的
然后人工打开"./sysdeps/unix/sysv/linux/adjtime.c"确认?
不过要是这个文件是那种几千行代码的,估计我找不了...
有无更好方法?
Fri Aug 19 03:13:28 CST 2016补充:
又马后炮了哈,仅供各位参考:
用apt-file搜出那个头文件所在的包
apt-get source 所在包包名
然后在源码目录里:

代码: 全选

$ grep INT_MAX $(grep -l 1000000 $(grep -l -r adjtime) |grep \\\.c$)
sysdeps/unix/sysv/linux/adjtime.c:#define MAX_SEC	(INT_MAX / 1000000L - 2)
跑题:
貌似根本原因还是英文水平不足,man没看仔细
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: adjtime之类的系统调用的实现代码从哪里找?

#4

帖子 vickycq » 2016-08-19 8:56

科学之子 写了:$ grep INT_MAX $(grep -l 1000000 $(grep -l -r adjtime) |grep \\\.c$)
sysdeps/unix/sysv/linux/adjtime.c:#define MAX_SEC (INT_MAX / 1000000L - 2)
这样搜不是事后诸葛亮么,一开始咱是不知道这些关键词的
下载源代码后:
grep -Ri 'einval' ./
发现很多,
grep -Ri 'einval' ./ | grep adjtime
./sysdeps/unix/sysv/linux/adjtime.c: return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
打开 ./sysdeps/unix/sysv/linux/adjtime.c,在 EINVAL 的前一行发现 MIN_SEC, MAX_SEC
再找 MIN_SEC, MAX_SEC 定义即可(实际上不需要,打开文件第一眼就看到了)

搜索时使用 viewtopic.php?f=165&t=480008 是更好的办法
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

Re: adjtime之类的系统调用的实现代码从哪里找?

#5

帖子 科学之子 » 2016-08-19 11:58

vickycq 写了:
科学之子 写了:$ grep INT_MAX $(grep -l 1000000 $(grep -l -r adjtime) |grep \\\.c$)
sysdeps/unix/sysv/linux/adjtime.c:#define MAX_SEC (INT_MAX / 1000000L - 2)
这样搜不是事后诸葛亮么,一开始咱是不知道这些关键词的
下载源代码后:
grep -Ri 'einval' ./
发现很多,
grep -Ri 'einval' ./ | grep adjtime
./sysdeps/unix/sysv/linux/adjtime.c: return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
打开 ./sysdeps/unix/sysv/linux/adjtime.c,在 EINVAL 的前一行发现 MIN_SEC, MAX_SEC
再找 MIN_SEC, MAX_SEC 定义即可(实际上不需要,打开文件第一眼就看到了)

搜索时使用 viewtopic.php?f=165&t=480008 是更好的办法

代码: 全选

grep -Ri 'einval' ./ | grep adjtime
./sysdeps/unix/sysv/linux/adjtime.c:    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
奇怪,我这里的执行结果是:

代码: 全选

$ grep -Ri 'einval' ./ | grep adjtime
./sysdeps/unix/sysv/linux/adjtime.c:	  __set_errno (EINVAL);
./sysdeps/unix/sysv/linux/adjtime.c:      if (itv && errno == EINVAL && tntx.modes == ADJ_OFFSET_SS_READ)
受教了,当时完全忽略了"EINVAL"是个系统定义的宏
这样搜不是事后诸葛亮么,一开始咱是不知道这些关键词的
感觉不完全是事后诸葛亮,man中可以观察到"1000000",INT_MAX,同时猜测实现中应该还包含"adjtime"
只是当时搜索经验不足,加上英文水平也不够,没能敏锐发现这些细节
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: adjtime之类的系统调用的实现代码从哪里找?

#6

帖子 vickycq » 2016-08-19 15:31

科学之子 写了: 奇怪,我这里的执行结果是:
./sysdeps/unix/sysv/linux/adjtime.c: __set_errno (EINVAL);
./sysdeps/unix/sysv/linux/adjtime.c: if (itv && errno == EINVAL && tntx.modes == ADJ_OFFSET_SS_READ)
可能原因 您下载的是 jessie 自带的 glibc 2.19,我是从官网下载的 glibc 2.24。
下载了 glibc 2.19,确实同您的结果一样.
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
回复