Just use CLOCK_MONOTONIC and clean up includes
CLOCK_MONOTONIC exists everywhere.
This commit is contained in:
parent
ba2175979c
commit
f39d916e3a
7
daemon.c
7
daemon.c
@ -29,7 +29,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/timespec.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
@ -266,7 +265,7 @@ int main(int argc, char *argv[]) {
|
|||||||
struct timespec now = {0};
|
struct timespec now = {0};
|
||||||
struct timespec timeout = {0};
|
struct timespec timeout = {0};
|
||||||
if (timespecisset(&deadline)) {
|
if (timespecisset(&deadline)) {
|
||||||
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
timespecsub(&deadline, &now, &timeout);
|
timespecsub(&deadline, &now, &timeout);
|
||||||
}
|
}
|
||||||
if (timeout.tv_sec < 0 || timeout.tv_nsec < 0) {
|
if (timeout.tv_sec < 0 || timeout.tv_nsec < 0) {
|
||||||
@ -281,7 +280,8 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// TODO: Handle FIFO and pipes.
|
// TODO: Handle FIFO and pipes.
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
if (timespecisset(&deadline)) {
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
for (size_t i = 0; i < services.len; ++i) {
|
for (size_t i = 0; i < services.len; ++i) {
|
||||||
struct Service *service = &services.ptr[i];
|
struct Service *service = &services.ptr[i];
|
||||||
if (service->intent != Start) continue;
|
if (service->intent != Start) continue;
|
||||||
@ -290,6 +290,7 @@ int main(int argc, char *argv[]) {
|
|||||||
serviceStart(service);
|
serviceStart(service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (signals[SIGCHLD]) {
|
if (signals[SIGCHLD]) {
|
||||||
int status;
|
int status;
|
||||||
|
2
daemon.h
2
daemon.h
@ -19,7 +19,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/timespec.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
|
@ -111,7 +111,7 @@ err:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void setDeadline(struct Service *service) {
|
static void setDeadline(struct Service *service) {
|
||||||
clock_gettime(CLOCK_MONOTONIC_FAST, &service->restartDeadline);
|
clock_gettime(CLOCK_MONOTONIC, &service->restartDeadline);
|
||||||
timespecadd(
|
timespecadd(
|
||||||
&service->restartDeadline, &service->restartInterval,
|
&service->restartDeadline, &service->restartInterval,
|
||||||
&service->restartDeadline
|
&service->restartDeadline
|
||||||
|
Loading…
Reference in New Issue
Block a user