mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 23:21:38 +01:00
Merge branch 'maint-0.2.9'
This commit is contained in:
commit
a6eaa121e4
1 changed files with 30 additions and 2 deletions
|
@ -324,10 +324,27 @@ monotime_diff_nsec(const monotime_t *start,
|
||||||
/* end of "__APPLE__" */
|
/* end of "__APPLE__" */
|
||||||
#elif defined(HAVE_CLOCK_GETTIME)
|
#elif defined(HAVE_CLOCK_GETTIME)
|
||||||
|
|
||||||
|
#ifdef CLOCK_MONOTONIC_COARSE
|
||||||
|
/**
|
||||||
|
* Which clock should we use for coarse-grained monotonic time? By default
|
||||||
|
* this is CLOCK_MONOTONIC_COARSE, but it might not work -- for example,
|
||||||
|
* if we're compiled with newer Linux headers and then we try to run on
|
||||||
|
* an old Linux kernel. In that case, we will fall back to CLOCK_MONOTONIC.
|
||||||
|
*/
|
||||||
|
static int clock_monotonic_coarse = CLOCK_MONOTONIC_COARSE;
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
monotime_init_internal(void)
|
monotime_init_internal(void)
|
||||||
{
|
{
|
||||||
/* no action needed. */
|
#ifdef CLOCK_MONOTONIC_COARSE
|
||||||
|
struct timespec ts;
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC_COARSE, &ts) < 0) {
|
||||||
|
log_info(LD_GENERAL, "CLOCK_MONOTONIC_COARSE isn't working (%s); "
|
||||||
|
"falling back to CLOCK_MONOTONIC.", strerror(errno));
|
||||||
|
clock_monotonic_coarse = CLOCK_MONOTONIC;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -355,7 +372,18 @@ monotime_coarse_get(monotime_coarse_t *out)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
int r = clock_gettime(CLOCK_MONOTONIC_COARSE, &out->ts_);
|
int r = clock_gettime(clock_monotonic_coarse, &out->ts_);
|
||||||
|
if (PREDICT_UNLIKELY(r < 0) &&
|
||||||
|
errno == EINVAL &&
|
||||||
|
clock_monotonic_coarse == CLOCK_MONOTONIC_COARSE) {
|
||||||
|
/* We should have caught this at startup in monotime_init_internal!
|
||||||
|
*/
|
||||||
|
log_warn(LD_BUG, "Falling back to non-coarse monotonic time %s initial "
|
||||||
|
"system start?", monotime_initialized?"after":"without");
|
||||||
|
clock_monotonic_coarse = CLOCK_MONOTONIC;
|
||||||
|
r = clock_gettime(clock_monotonic_coarse, &out->ts_);
|
||||||
|
}
|
||||||
|
|
||||||
tor_assert(r == 0);
|
tor_assert(r == 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue