Skip to content

Commit

Permalink
Pedantic fixes to clock_nanosleep error handling
Browse files Browse the repository at this point in the history
Surprisingly, clock_nanosleep() returns an errno value directly,
rather than setting errno itself.  This is unlike both
clock_gettime() and nanosleep(), which return -1 and set the
actual errno, like most such functions.

I'm removing the EINTR handling while I'm here, because this was a
vestigial remnant of when I tried to make this work with actual
signal handlers earlier on.  As things stand now (no handlers),
we'll never get an EINTR here anyways, we'll just terminate inside
of the sleep.
  • Loading branch information
blblack committed Feb 15, 2024
1 parent 101ae19 commit d46bb79
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tofurkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ int main(int argc, char* argv[])
log_verbose("Sleeping until next half-interval wakeup at %" PRIi64,
(int64_t)next_ts.tv_sec);
const int cnrv = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next_ts, NULL);
if (cnrv && errno != EINTR)
log_fatal("clock_nanosleep() failed: %s", strerror(errno));
if (cnrv)
log_fatal("clock_nanosleep() failed: %s", strerror(cnrv));
next_wake = set_keys(cfg_p);
}
} else {
Expand Down

0 comments on commit d46bb79

Please sign in to comment.