-reopen:
- if (lstat(TIMESTAMP_DIR, &stl) == -1) {
- if (!(errno == ENOENT && isnew == 0))
- err(1, "lstat: %s", TIMESTAMP_DIR);
- } else if ((stl.st_mode & S_IFMT) != S_IFDIR) {
- errx(1, "%s: not a directory", TIMESTAMP_DIR);
- }
-
- if ((fd = open(TIMESTAMP_DIR, O_RDONLY | O_DIRECTORY)) == -1) {
- if (errno == ENOENT && isnew == 0) {
- if (mkdir(TIMESTAMP_DIR, (S_IRUSR|S_IWUSR|S_IXUSR)) != 0)
- err(1, "mkdir");
- isnew = 1;
- goto reopen;
- } else {
- err(1, "failed to open timestamp directory: %s", TIMESTAMP_DIR);
- }
- }
-
-recheck:
- if (fstat(fd, &st) == -1)
- err(1, "fstatat");
-
- if (stl.st_ino != st.st_ino || stl.st_dev != st.st_dev)
- errx(1, "timestamp directory lstat and fstat are different files");
-
- if ((st.st_mode & (S_IWGRP|S_IRGRP|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH)) != 0)
- errx(1, "timestamp directory has wrong permissions");
-
- if (isnew == 1) {
- if (fchown(fd, 0, 0) == -1)
- err(1, "fchown");
- isnew = 0;
- goto recheck;
- } else {
- if (st.st_uid != 0 || st.st_gid != 0)
- errx(1, "timestamp directory has wrong owner or group");
- }
-
-#if defined(TIMESTAMP_TMPFS) && defined(__linux__)
- struct statfs sf;
- if (fstatfs(fd, &sf) == -1)
- err(1, "statfs");
-
- if (sf.f_type != TMPFS_MAGIC)
- errx(1, "timestamp directory not on tmpfs");
-#endif
-
- return fd;
+ timespecadd(&ts[0], &timeout, &ts[0]);
+ timespecadd(&ts[1], &timeout, &ts[1]);
+ return futimens(fd, ts);