summaryrefslogtreecommitdiff
path: root/lib/fdutimensat.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2010-09-17 08:29:16 -0600
committerEric Blake <eblake@redhat.com>2010-09-17 08:34:59 -0600
commit18aae5b74420237d8c827e7c68312c5b71d659dc (patch)
treeca6a30f1b82667210506cebb66fbb179e0e58241 /lib/fdutimensat.c
parentad739a2be8c9eccadb7932665420a7c835fb8bd2 (diff)
downloadgnulib-18aae5b74420237d8c827e7c68312c5b71d659dc.tar.gz
fdutimensat: drop atflag validation
* lib/fdutimensat.c (fdutimensat): Allow AT_SYMLINK_NOFOLLOW even with valid fd, to close a race scenario where futimens is unsupported and FILE was replaced by a symlink. * tests/test-fdutimensat.c (do_fdutimens, main): Adjust test accordingly. Suggested by Paul Eggert. Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'lib/fdutimensat.c')
-rw-r--r--lib/fdutimensat.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/lib/fdutimensat.c b/lib/fdutimensat.c
index 77f893bb3b..0219a78326 100644
--- a/lib/fdutimensat.c
+++ b/lib/fdutimensat.c
@@ -35,8 +35,8 @@
use just futimes (or equivalent) instead of utimes (or equivalent),
and fail if on an old system without futimes (or equivalent).
If TIMESPEC is null, set the time stamps to the current time.
- ATFLAG must be 0 if FD is non-negative; otherwise it may be
- AT_SYMLINK_NOFOLLOW to operate on FILE as a symlink.
+ ATFLAG is passed to utimensat if FD is negative or futimens was
+ unsupported, which can allow operation on FILE as a symlink.
Return 0 on success, -1 (setting errno) on failure. */
int
@@ -44,20 +44,8 @@ fdutimensat (int dir, char const *file, int fd, struct timespec const ts[2],
int atflag)
{
int result = 1;
- if (atflag & ~AT_SYMLINK_NOFOLLOW)
- {
- errno = EINVAL;
- return -1;
- }
if (0 <= fd)
- {
- if (atflag)
- {
- errno = EINVAL;
- return -1;
- }
- result = futimens (fd, ts);
- }
+ result = futimens (fd, ts);
if (file && (fd < 0 || (result == -1 && errno == ENOSYS)))
result = utimensat (dir, file, ts, atflag);
if (result == 1)