summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2019-06-08 00:03:07 +1000
committerDarren Tucker <dtucker@dtucker.net>2019-06-08 00:03:07 +1000
commit2b3402dc9f1d9b0df70291b424f36e436cdfa7e0 (patch)
tree81d402d19a1764a5ad10c70aa4a09ffe83f36fd5 /openbsd-compat
parent182898192d4b720e4faeafd5b39c2cfb3b92aa21 (diff)
Always clean up before and after utimensat test.
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/regress/utimensattest.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/openbsd-compat/regress/utimensattest.c b/openbsd-compat/regress/utimensattest.c
index b29cef2f1..24312e5d8 100644
--- a/openbsd-compat/regress/utimensattest.c
+++ b/openbsd-compat/regress/utimensattest.c
@@ -33,7 +33,14 @@
33 33
34int utimensat(int, const char *, const struct timespec[2], int); 34int utimensat(int, const char *, const struct timespec[2], int);
35 35
36void 36static void
37cleanup(void)
38{
39 (void)unlink(TMPFILE);
40 (void)unlink(TMPFILE2);
41}
42
43static void
37fail(char *msg, long expect, long got) 44fail(char *msg, long expect, long got)
38{ 45{
39 int saved_errno = errno; 46 int saved_errno = errno;
@@ -44,6 +51,7 @@ fail(char *msg, long expect, long got)
44 else 51 else
45 fprintf(stderr, "utimensat: %s: expected %ld got %ld\n", 52 fprintf(stderr, "utimensat: %s: expected %ld got %ld\n",
46 msg, expect, got); 53 msg, expect, got);
54 cleanup();
47 exit(1); 55 exit(1);
48} 56}
49 57
@@ -54,6 +62,7 @@ main(void)
54 struct stat sb; 62 struct stat sb;
55 struct timespec ts[2]; 63 struct timespec ts[2];
56 64
65 cleanup();
57 if ((fd = open(TMPFILE, O_CREAT, 0600)) == -1) 66 if ((fd = open(TMPFILE, O_CREAT, 0600)) == -1)
58 fail("open", 0, 0); 67 fail("open", 0, 0);
59 close(fd); 68 close(fd);
@@ -87,8 +96,8 @@ main(void)
87 * POSIX specifies that when given a symlink, AT_SYMLINK_NOFOLLOW 96 * POSIX specifies that when given a symlink, AT_SYMLINK_NOFOLLOW
88 * should update the symlink and not the destination. The compat 97 * 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 98 * 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 99 * with instead of following a symlink when explicitly asked not to.
91 * not to. Here we just test that it does not update the destination. 100 * Here we just test that it does not update the destination.
92 */ 101 */
93 if (rename(TMPFILE, TMPFILE2) == -1) 102 if (rename(TMPFILE, TMPFILE2) == -1)
94 fail("rename", 0, 0); 103 fail("rename", 0, 0);
@@ -104,8 +113,6 @@ main(void)
104 if (sb.st_mtime == 55667788) 113 if (sb.st_mtime == 55667788)
105 fail("utimensat symlink st_mtime", 0, 0 ); 114 fail("utimensat symlink st_mtime", 0, 0 );
106 115
107 /* Clean up */ 116 cleanup();
108 if (!(unlink(TMPFILE) == 0 && unlink(TMPFILE2) == 0))
109 fail("unlink", 0, 0);
110 exit(0); 117 exit(0);
111} 118}