From f39d916e3a35527eb0d886506ac6fc70fa639070 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 15 Aug 2020 09:53:03 -0400 Subject: Just use CLOCK_MONOTONIC and clean up includes CLOCK_MONOTONIC exists everywhere. --- daemon.c | 19 ++++++++++--------- daemon.h | 2 +- service.c | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/daemon.c b/daemon.c index cd12f92..9eb8bb4 100644 --- a/daemon.c +++ b/daemon.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -266,7 +265,7 @@ int main(int argc, char *argv[]) { struct timespec now = {0}; struct timespec timeout = {0}; if (timespecisset(&deadline)) { - clock_gettime(CLOCK_MONOTONIC_FAST, &now); + clock_gettime(CLOCK_MONOTONIC, &now); timespecsub(&deadline, &now, &timeout); } if (timeout.tv_sec < 0 || timeout.tv_nsec < 0) { @@ -281,13 +280,15 @@ int main(int argc, char *argv[]) { // TODO: Handle FIFO and pipes. - clock_gettime(CLOCK_MONOTONIC_FAST, &now); - for (size_t i = 0; i < services.len; ++i) { - struct Service *service = &services.ptr[i]; - if (service->intent != Start) continue; - if (service->state == Start) continue; - if (timespeccmp(&service->restartDeadline, &now, <=)) { - serviceStart(service); + if (timespecisset(&deadline)) { + clock_gettime(CLOCK_MONOTONIC, &now); + for (size_t i = 0; i < services.len; ++i) { + struct Service *service = &services.ptr[i]; + if (service->intent != Start) continue; + if (service->state == Start) continue; + if (timespeccmp(&service->restartDeadline, &now, <=)) { + serviceStart(service); + } } } diff --git a/daemon.h b/daemon.h index 4a9f4d8..db82ee2 100644 --- a/daemon.h +++ b/daemon.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include typedef unsigned char byte; diff --git a/service.c b/service.c index 35d15f3..12f465f 100644 --- a/service.c +++ b/service.c @@ -111,7 +111,7 @@ err: } static void setDeadline(struct Service *service) { - clock_gettime(CLOCK_MONOTONIC_FAST, &service->restartDeadline); + clock_gettime(CLOCK_MONOTONIC, &service->restartDeadline); timespecadd( &service->restartDeadline, &service->restartInterval, &service->restartDeadline -- cgit 1.4.1