为什么touch包含utimensat()系统调用? [英] Why does touch include a utimensat() syscall?

查看:108
本文介绍了为什么touch包含utimensat()系统调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查看文件mtimes的奇数时间顺序时,我注意到(gnu)touch命令在其触摸序列中包括了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:

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

似乎touch命令将文件时间戳的亚秒部分显式归零.其他文件创建方法不一定会这样做, 在透明的V8动态视图中,这会导致make出现有趣的"排序问题.

It appears that the touch command explicitly zeros the subsecond portion of the files' timestamp. Other methods of file creation don't necessarily do this, and in clearcase V8 dynamic views, this is causing "interesting" sequencing issues with make.

为什么使用此utimensat系统调用将文件的亚秒级修改时间设为零?

Why would touch zero the subsecond modification time for the file using this utimensat syscall?

dg99指出,按照strace指示的方式调用的此API可能是尝试将时间设置为当前时间,而不是观察到的清除时间的亚秒部分.为了对此进行重现,我尝试了对utimensat(fd,NULL,NULL,0)的调用,但这会产生EINVAL.事实证明strace在说谎(也许稍有一点:也许同一个内核syscall会同时执行utimensatfutimens API),而touch.c的实际作用是:

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. In an attempt to repro this, I tried a call to utimensat(fd, NULL, NULL, 0), but this produces an 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:

269               result = futimens (fd, ts);
(gdb) s
272               if (0 < result)
(gdb) p fd
$4 = 0
(gdb) p ts
$5 = (struct timespec *) 0x0

使用futimes以这种方式调用一些独立的代码,还具有使用clearcase版本8 MVFS清除亚秒级时间的外观.

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.

推荐答案

从对utimensat手册页的阅读中,上述调用未将任何内容显式设置为零,而是将访问和修改时间戳记均设置为当前时间:

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:

int utimensat(int dirfd, const char *pathname,
              const struct timespec times[2], int flags);

...新文件的时间戳记在数组中指定了times ...如果times为NULL,则两个时间戳记都设置为当前时间.

... the new file timestamps are specified in the array times ... If times is NULL, then both timestamps are set to the current time.

这篇关于为什么touch包含utimensat()系统调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆