X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=persist_timestamp.c;h=d4ffdd3ac8f38336b06467b993e07d486a769d72;hb=7c364fd80021864ff69cf01e130eebeb734ea6f5;hp=d69e7dab3773cc20089b049ee60c9869370c415f;hpb=ec70ae5c5eb35b66b4ab0d9676de02bcfce93bf6;p=opendoas.git diff --git a/persist_timestamp.c b/persist_timestamp.c index d69e7da..d4ffdd3 100644 --- a/persist_timestamp.c +++ b/persist_timestamp.c @@ -160,33 +160,24 @@ check: return 0; } -static int -timestamp_read(int fd, struct timespec *mono, struct timespec *real) -{ - if (read(fd, (void *)mono, sizeof *mono) != sizeof *mono || - read(fd, (void *)real, sizeof *real) != sizeof *mono) - err(1, "read"); - if (!timespecisset(mono) || !timespecisset(real)) - errx(1, "timespecisset"); - return 0; -} - int persist_check(int fd, int secs) { struct timespec mono, real, ts_mono, ts_real, timeout; - if (timestamp_read(fd, &ts_mono, &ts_real) != 0) - return 1; + if (read(fd, &ts_mono, sizeof ts_mono) != sizeof ts_mono || + read(fd, &ts_real, sizeof ts_real) != sizeof ts_mono) + err(1, "read"); + if (!timespecisset(&ts_mono) || !timespecisset(&ts_real)) + errx(1, "timespecisset"); - if (clock_gettime(CLOCK_MONOTONIC, &mono) != 0 || !timespecisset(&mono)) - err(1, "clock_gettime(CLOCK_MONOTONIC, ?)"); - if (clock_gettime(CLOCK_REALTIME, &real) != 0 || !timespecisset(&real)) - err(1, "clock_gettime(CLOCK_REALTIME, ?)"); + if (clock_gettime(CLOCK_MONOTONIC, &mono) == -1 || + clock_gettime(CLOCK_REALTIME, &real) == -1) + err(1, "clock_gettime"); if (timespeccmp(&mono, &ts_mono, >) || timespeccmp(&real, &ts_real, >)) - return 1; + return -1; memset(&timeout, 0, sizeof timeout); timeout.tv_sec = secs; @@ -205,10 +196,9 @@ persist_set(int fd, int secs) { struct timespec mono, real, ts_mono, ts_real, timeout; - if (clock_gettime(CLOCK_MONOTONIC, &mono) != 0 || !timespecisset(&mono)) - err(1, "clock_gettime(XLOCK_MONOTONIC, ?)"); - if (clock_gettime(CLOCK_REALTIME, &real) != 0 || !timespecisset(&real)) - err(1, "clock_gettime(CLOCK_REALTIME, ?)"); + if (clock_gettime(CLOCK_MONOTONIC, &mono) == -1 || + clock_gettime(CLOCK_REALTIME, &real) == -1) + err(1, "clock_gettime"); memset(&timeout, 0, sizeof timeout); timeout.tv_sec = secs;