X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Ftimer.c;h=b0a9023bb00debc4fc5e5e827ba6e423aa759ed8;hb=472fc28fdade525e700ebf4b25d026a8c907796d;hp=62baf5785d3eef2ea786ad822b0f7f47603fa87b;hpb=dedabea4b3d61a87cedb5c8d7ccce5b86ea84afe;p=elogind.git diff --git a/src/core/timer.c b/src/core/timer.c index 62baf5785..b0a9023bb 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -48,7 +48,7 @@ static void timer_init(Unit *u) { t->next_elapse_monotonic_or_boottime = (usec_t) -1; t->next_elapse_realtime = (usec_t) -1; - t->accuracy_usec = USEC_PER_MINUTE; + t->accuracy_usec = u->manager->default_timer_accuracy_usec; } void timer_free_values(Timer *t) { @@ -111,6 +111,23 @@ static int timer_add_default_dependencies(Timer *t) { return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true); } +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; @@ -496,22 +513,8 @@ static void timer_enter_running(Timer *t) { dual_timestamp_get(&t->last_trigger); - if (t->stamp_path) { - _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], t->last_trigger.realtime); - ts[1] = ts[0]; - - futimens(fd, ts); - } - } + if (t->stamp_path) + update_stampfile(t, t->last_trigger.realtime); timer_set_state(t, TIMER_RUNNING); return; @@ -539,6 +542,11 @@ static int timer_start(Unit *u) { if (stat(t->stamp_path, &st) >= 0) t->last_trigger.realtime = timespec_load(&st.st_atim); + else if (errno == ENOENT) + /* The timer has never run before, + * make sure a stamp file exists. + */ + update_stampfile(t, now(CLOCK_REALTIME)); } t->result = TIMER_SUCCESS;