+static void update_stampfile(Timer *t, usec_t timestamp) {
+ _cleanup_close_ int fd = -1;
+
+ mkdir_parents_label(t->stamp_path, 0755);
+
+ /* Update the file atime + mtime, if we can */
+ fd = open(t->stamp_path, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644);
+ if (fd >= 0) {
+ struct timespec ts[2];
+
+ timespec_store(&ts[0], timestamp);
+ ts[1] = ts[0];
+
+ futimens(fd, ts);
+ }
+}
+
+static int timer_setup_persistent(Timer *t) {
+ int r;
+
+ assert(t);
+
+ if (!t->persistent)
+ return 0;
+
+ if (UNIT(t)->manager->running_as == SYSTEMD_SYSTEM) {
+
+ r = unit_require_mounts_for(UNIT(t), "/var/lib/systemd/timers");
+ if (r < 0)
+ return r;
+
+ t->stamp_path = strappend("/var/lib/systemd/timers/stamp-", UNIT(t)->id);
+ } else {
+ const char *e;
+
+ e = getenv("XDG_DATA_HOME");
+ if (e)
+ t->stamp_path = strjoin(e, "/systemd/timers/", UNIT(t)->id, NULL);
+ else {
+
+ _cleanup_free_ char *h = NULL;
+
+ r = get_home_dir(&h);
+ if (r < 0) {
+ log_error("Failed to determine home directory: %s", strerror(-r));
+ return r;
+ }
+
+ t->stamp_path = strjoin(h, "/.local/share/systemd/timers/stamp-", UNIT(t)->id, NULL);
+ }
+ }
+
+ if (!t->stamp_path)
+ return log_oom();
+
+ return 0;
+}
+