diff --git a/server/include/timing.h b/server/include/timing.h index 88711a3b3..6aafda65e 100644 --- a/server/include/timing.h +++ b/server/include/timing.h @@ -39,6 +39,9 @@ struct timespec time_diff(struct timespec *start, struct timespec *end); /** Get sum of two timespec structs */ struct timespec time_add(struct timespec *start, struct timespec *end); +/** Return current time as a struct timespec. */ +struct timespec time_now(); + /** Return the diffrence off two timestamps as double value in seconds. */ double time_delta(struct timespec *start, struct timespec *end); diff --git a/server/src/file.c b/server/src/file.c index 299793633..f3b626320 100644 --- a/server/src/file.c +++ b/server/src/file.c @@ -65,8 +65,7 @@ char * file_print(struct node *n) if ((f->first.tv_sec || f->first.tv_nsec) && (f->offset.tv_sec || f->offset.tv_nsec)) { - struct timespec eta, now; - clock_gettime(CLOCK_REALTIME, &now); + struct timespec eta, now = time_now(); eta = time_add(&f->first, &f->offset); eta = time_diff(&now, &eta); @@ -145,8 +144,7 @@ int file_open(struct node *n) serror("Failed to create timer"); /* Get current time */ - struct timespec now, eta; - clock_gettime(CLOCK_REALTIME, &now); + struct timespec now = time_now(); /* Get timestamp of first line */ struct msg m; diff --git a/server/src/timing.c b/server/src/timing.c index b0ae18a93..095ddf446 100644 --- a/server/src/timing.c +++ b/server/src/timing.c @@ -31,6 +31,15 @@ uint64_t timerfd_wait_until(int fd, struct timespec *until) return timerfd_wait(fd); } +struct timespec time_now() +{ + struct timespec ts; + + clock_gettime(CLOCK_REALTIME, &ts); + + return ts; +} + struct timespec time_add(struct timespec *start, struct timespec *end) { struct timespec sum = {