summaryrefslogtreecommitdiff
path: root/openbsd-compat/regress/utimensattest.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2019-06-07 23:47:37 +1000
committerColin Watson <cjwatson@debian.org>2019-06-09 22:09:25 +0100
commitbbc5ff0a295797174b4ef3928f58969e43f5adfe (patch)
treedec20ce22874481f46de4ccc26afe2948b44821e /openbsd-compat/regress/utimensattest.c
parent7d50f9e5be88179325983a1f58c9d51bb58f025a (diff)
Update utimensat test.
POSIX specifies that when given a symlink, AT_SYMLINK_NOFOLLOW should update the symlink and not the destination. The compat code doesn't have a way to do this, so where possible it fails instead of following a symlink when explicitly asked not to. Instead of checking for an explicit failure, check that it does not update the destination, which both the real and compat implementations should honour. Inspired by github pull req #125 from chutzpah at gentoo.org. Origin: upstream, https://anongit.mindrot.org/openssh.git/commit/?id=182898192d4b720e4faeafd5b39c2cfb3b92aa21 Last-Update: 2019-06-09 Patch-Name: fix-utimensat-test.patch
Diffstat (limited to 'openbsd-compat/regress/utimensattest.c')
-rw-r--r--openbsd-compat/regress/utimensattest.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/openbsd-compat/regress/utimensattest.c b/openbsd-compat/regress/utimensattest.c
index a7bc7634b..b29cef2f1 100644
--- a/openbsd-compat/regress/utimensattest.c
+++ b/openbsd-compat/regress/utimensattest.c
@@ -83,14 +83,28 @@ main(void)
83 fail("mtim.tv_nsec", 45678000, sb.st_mtim.tv_nsec); 83 fail("mtim.tv_nsec", 45678000, sb.st_mtim.tv_nsec);
84#endif 84#endif
85 85
86 /*
87 * POSIX specifies that when given a symlink, AT_SYMLINK_NOFOLLOW
88 * should update the symlink and not the destination. The compat
89 * code doesn't have a way to do this, so where possible it fails
90 * with ENOSYS instead of following a symlink when explicitly asked
91 * not to. Here we just test that it does not update the destination.
92 */
86 if (rename(TMPFILE, TMPFILE2) == -1) 93 if (rename(TMPFILE, TMPFILE2) == -1)
87 fail("rename", 0, 0); 94 fail("rename", 0, 0);
88 if (symlink(TMPFILE2, TMPFILE) == -1) 95 if (symlink(TMPFILE2, TMPFILE) == -1)
89 fail("symlink", 0, 0); 96 fail("symlink", 0, 0);
97 ts[0].tv_sec = 11223344;
98 ts[1].tv_sec = 55667788;
99 (void)utimensat(AT_FDCWD, TMPFILE, ts, AT_SYMLINK_NOFOLLOW);
100 if (stat(TMPFILE2, &sb) == -1)
101 fail("stat", 0, 0 );
102 if (sb.st_atime == 11223344)
103 fail("utimensat symlink st_atime", 0, 0 );
104 if (sb.st_mtime == 55667788)
105 fail("utimensat symlink st_mtime", 0, 0 );
90 106
91 if (utimensat(AT_FDCWD, TMPFILE, ts, AT_SYMLINK_NOFOLLOW) != -1) 107 /* Clean up */
92 fail("utimensat followed symlink", 0, 0);
93
94 if (!(unlink(TMPFILE) == 0 && unlink(TMPFILE2) == 0)) 108 if (!(unlink(TMPFILE) == 0 && unlink(TMPFILE2) == 0))
95 fail("unlink", 0, 0); 109 fail("unlink", 0, 0);
96 exit(0); 110 exit(0);