[英]Why does touch include a utimensat() syscall?
Looking into an odd time sequencing of file mtimes, I noticed that the (gnu) touch
command includes an utimensat
syscall as part of its touch sequence: 在查看文件mtimes的奇数时间顺序时,我注意到(gnu)
touch
命令包括utimensat
syscall作为其触摸序列的一部分:
open("touchedLater", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
dup2(3, 0) = 0
close(3) = 0
dup2(0, 0) = 0
utimensat(0, NULL, NULL, 0) = 0
close(0) = 0
It appears that the touch command explicitly zeros the subsecond portion of the files' timestamp. 似乎touch命令将文件时间戳的亚秒部分显式归零。 Other methods of file creation don't necessarily do this, and in clearcase V8 dynamic views, this is causing "interesting" sequencing issues with make.
文件创建的其他方法不一定要这样做,在清晰的V8动态视图中,这会导致make产生“有趣的”排序问题。
Why would touch zero the subsecond modification time for the file using this utimensat
syscall? 为什么使用此
utimensat
syscall将文件的亚秒级修改时间utimensat
?
EDIT: dg99 points out that this API, as called in the way that strace indicates may be an attempt to set the time to the current time, not clear the subsecond portion of the time, as observed. 编辑:dg99指出,按照strace指示的方式调用的此API可能是尝试将时间设置为当前时间,而不是观察到的清除时间的亚秒部分。 In an attempt to repro this, I tried a call to
utimensat
(fd, NULL, NULL, 0), but this produces an EINVAL. 为了对此进行重现,我尝试了对
utimensat
的调用(fd,NULL,NULL,0),但这会产生EINVAL。 It turns out that strace is lying (perhaps slightly: maybe the same kernel syscall does both utimensat
and futimens
APIs), and what touch.c is actually doing is: 事实证明strace在说谎(也许稍微:也许同一个内核syscall既执行
utimensat
也执行futimens
API),而touch.c实际在做什么:
269 result = futimens (fd, ts);
(gdb) s
272 if (0 < result)
(gdb) p fd
$4 = 0
(gdb) p ts
$5 = (struct timespec *) 0x0
Calling some standalone code in this fashion, using futimes
also has the appearance of clearing the subsecond portion of the time using using clearcase version 8 MVFS. 以这种方式调用某些独立代码,使用
futimes
的外观,也使用clearcase版本8 MVFS清除了时间的亚秒部分。
From my reading of the utimensat
man page, the above call is not explicitly setting anything to zero, but rather is setting both access and modification timestamps to the current time: 根据我对
utimensat
手册页的阅读,上述调用不是将任何内容显式设置为零,而是将访问和修改时间戳记都设置为当前时间:
int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);
... the new file timestamps are specified in the array times ... If times is NULL, then both timestamps are set to the current time.
...新的文件时间戳记在数组times中指定。如果times为NULL,则两个时间戳记均设置为当前时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.